微信消息通知

【微信小程序消息通知方案】

1.统一服务消息:

要求:用户需要对小程序中的某个组件(如某个按钮) 进行点击,获得消息通知机会(formld) 。

缺点:点击一次,只能获得一次消息通知机会。

2.订阅消息(一次性订阅消息)

要求:脱打开小程序时贵同意授权小程序发送一次性订阅消息给用户。

缺点:授权一次。只熊获得一次消息通知机会。

3.订阅消息(长期性订阅消息)

要求:用户打开小程序时,需同意授权小程序发送长期订阅消息给用户。可多次发送消息给用户。

缺点:目前长期性订阅消息仅向政务民生、医疗、交通、金融、教育等线下公共服务开放,后期将逐步支持到其他线下公共服务业务。

4.通过公众号发送模板消息

要求:

1、公众号授权给第三方平台;

2、用户关注公众号后,需要有个H5页面,让其授权,获取openID、 unionID;

3、通过公众号用户的unionID,关联小程序用户;

【参考文章】

小程序进阶-用户消息通知

https://blog.csdn.net/weixin_43166227/article/details/123445134

uniapp微信小程序订阅消息发送服务通知

https://blog.csdn.net/qq_44718932/article/details/126130702

微信接口调用返回码一览表

https://blog.csdn.net/fqf_520/article/details/52675513

微信接口调用返回码一览表

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用PHP发送微信消息通知,可以使用微信提供的公众号接口或者企业微信接口。 1. 使用公众号接口: 首先需要获取到公众号的access_token,可以通过调用微信提供的API获取。然后使用该access_token来发送消息通知。 示例代码如下: ```php <?php // 获取access_token $appid = 'your_appid'; $secret = 'your_secret'; $apiUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$secret}"; $result = json_decode(file_get_contents($apiUrl), true); $access_token = $result["access_token"]; // 发送消息 $msg = "Hello, World!"; $openid = 'your_openid'; $apiUrl = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}"; $data = array( 'touser' => $openid, 'msgtype' => 'text', 'text' => array( 'content' => $msg ) ); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => json_encode($data) ) ); $context = stream_context_create($options); $result = file_get_contents($apiUrl, false, $context); ``` 以上代码中的`your_appid`、`your_secret`、`your_openid`分别替换成你的公众号的AppID、AppSecret和要发送的用户的openid。 2. 使用企业微信接口: 首先需要在企业微信后台创建一个应用,并获取到应用的access_token。然后使用该access_token来发送消息通知。 示例代码如下: ```php <?php // 获取access_token $corpid = 'your_corpid'; $corpsecret = 'your_corpsecret'; $apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid={$corpid}&corpsecret={$corpsecret}"; $result = json_decode(file_get_contents($apiUrl), true); $access_token = $result["access_token"]; // 发送消息 $msg = "Hello, World!"; $userid = 'your_userid'; $apiUrl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$access_token}"; $data = array( 'touser' => $userid, 'msgtype' => 'text', 'text' => array( 'content' => $msg ) ); $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => json_encode($data) ) ); $context = stream_context_create($options); $result = file_get_contents($apiUrl, false, $context); ``` 以上代码中的`your_corpid`、`your_corpsecret`、`your_userid`分别替换成你的企业微信的corpid、corpsecret和要发送的用户的userid。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值