微信公众号推送测试

1.打开公众号页面

https://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

2.创建测试公众号

用微信扫码创建,得到appidsecret

3.(首次)关注测试公众号

拉到下面有该测试公众号的二维码,用微信扫描关注测试公众号,稍等一下关注的用户就会出现在关注用户列表里面,后面有用户的微信号(即下面用到的touser)

4.获取token

请求如下地址,可得到token(貌似有有效期的)

https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=xxxxx&secret=xxxxx

5.推送消息到用户

用POST的方式请求url与body内容如下:

https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=XX_XXX_XX_XX
{
    "touser": "xxxxxx",
    "msgtype": "text",
    "text": {
        "content": "hello wx user"
    }
}

评论

暂无

添加新评论