说明:有正式版和测试版本 ,正式版需要企业微信认证资质300r ,测试版不需要。
仅演示测试版本 ,认证版自行搜。
接入文档:https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
大致流程:
获取token,用token进行推送 推送的时候需要指定openid和模板消息 。
如上校验地址可配可不配(只做推送不需要),该地址后期可用来接收【用户给公众号】发的消息,然后post到这个地址自己接收做额外diy开发
微信公众号开发(服务号)消息推送-测试账号版
一、进入【微信公众账号测试号申请系统】
https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=sandbox/login
二、获取 Access token
https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html
curl --request GET \
--url 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx59855554adf27f8ce8b&secret=fb812967555492e3a9a429c6a85d38ddf54' \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Connection: keep-alive' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0'
- curl如上,贴上自己的appid和secret即可
三、推送msg
https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html#%E5%8F%91%E9%80%81%E6%A8%A1%E6%9D%BF%E6%B6%88%E6%81%AF
curl --request POST \
--url 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=90_UMBjdcK5mbogthDdTImx7KdgoDHloQud-7zQbGp6AKrMHCQ-iTi7dT-z6muiQp60ALP2WXrTT9SvliGMT4P6BY5z68i469OZDzm5FkFbNKL8eKhbUoEHW17hmHsLZMjADAESF' \
--header 'Accept: */*' \
--header 'Accept-Encoding: gzip, deflate, br' \
--header 'Connection: keep-alive' \
--header 'Content-Type: application/json' \
--header 'User-Agent: PostmanRuntime-ApipostRuntime/1.1.0' \
--data ' {
"touser":"ozRaZ6hB7ZhCtZNekIKyQl-y_8nQ",
"template_id":"ckOUhUDYllkzPfjLclhQ73xwTvMoaC__Of3yTNwCNXs",
"url":"http://weixin.qq.com/download",
"client_msg_id":"MSG_000001",
"data":{
"keyword1":{
"value":"巧克力"
},
"keyword2": {
"value":"39.8元"
},
"keyword3": {
"value":"2014年9月22日"
}
}
}'
- curl如上,贴上自己的token、openid、tempid
踩坑指南:
是基础消息下的【模板消息接口】===>发送模板消息 ,而不是订阅通知下的【订阅通知接口!!】
获取用户发送的消息接口文档
https://developers.weixin.qq.com/doc/service/guide/product/message/Receiving_standard_messages.html