调用微信公众号API,实现主动给粉丝发送消息
Sen
• 发表于:2021年10月08日 14:23 • 更新于:2021年10月08日 14:23
4733
目标:
通过微信公众号向关注用户发送消息。
开发环境:
node.js
准备工作:
1、在微信公众号后台的 开发 > 基本配置 获取appid和appsecret
2、关注用户在此公众号的openid
实现步骤:
1、创建云函数,填写配置参数,并设置输入参数接收openid
2、编写API,调用发送客服消息接口:weixinApi.sendText
async function run($input, $output, $modules = modules) {
const weixinApi = $modules.weixinApi;
let result = await weixinApi.sendText(
$input.openid,//传入的openid
'<a href="https://www.baidu.com">点此进入系统~</a>'//文本消息内容
);
$output.result = result;//输出结果
}
注:发送文本消息支持<a>标签。
测试结果:
在API下方调试,输入openid,返回”errmsg”:”OK”说明发送成功
微信公众号更多API可参考扩展库:https://github.com/node-webot/co-wechat-api
也可参考官方开发文档:
https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Service_Center_messages.html
联系我们
返回顶部