解决升级PHP7后 微信公众号收不到消息
服务器配置Linux+Nginx+PHP5.5+mysql
index方法配置微信的关注回复、菜单事件、多客服、自动回复等
public function actionIndex() {
if (isset($_GET["echostr"]) && !empty($_GET["echostr"])) {
$this->valid();
} else {
$postStr = isset($GLOBALS["HTTP_RAW_POST_DATA"]) ? $GLOBALS["HTTP_RAW_POST_DATA"] : '';
if (empty($postStr)) {
exit('.');
}
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach ($postObj as $key => $value) {
$this->data[$key] = strval($value);
}
/**
* 关注时回复
*/
$arr_data = $this->data;
if ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'subscribe') { // 关注时回复
/**
* 场景二维码
*/
$qr = explode('_', $arr_data['EventKey']);
if ($arr_data['EventKey'] && isset($qr[1])) {
/**
* 场景二维码,首次关注
*/
$this->sceneQrSubscribe($qr[1], $arr_data['FromUserName']);
$this->sceneQr($qr[1], $arr_data['FromUserName']);
}
$WxSubscribeText = \common\models\WxSubscribeText::find()->one();
$SubscribeText = 'msg';
if (!empty($WxSubscribeText)) {
$SubscribeText = $WxSubscribeText->text;
}
$this->response($SubscribeText);
} else if ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'LOCATION') { //地理位置消息
} elseif ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'CLICK') { // 事件, 点击自定义菜单
$this->event($arr_data);
} else if ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'SCAN') { // 再次关注
if (isset($arr_data['EventKey']) && $arr_data['EventKey']) {
$this->sceneQr($arr_data['EventKey'], $arr_data['FromUserName']);
}
$this->response('您已经关注我们了!'); //"扫描 ".$arr_data['EventKey'];
} else if ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'unsubscribe') { // 取消关注事件
$this->unsubscribe($arr_data['FromUserName']);
// 取消关注事件
} else { // 文本输入 检查 发送图片
/**
* 多客服
*/
$this->response('没有找到您要的内容!', 'text_kefu');
}
}
}
今天升级系统PHP版本为PHP7后,其他页面访问,后台、前台页面都没有问题,唯有访问微信公众号API接口提示“该公众号无法提供服务,请稍后重试”
后来在网上搜索,在OpenStack社区找到了回答,PHP7抛弃了HTTP_RAW_POST_DATA,要获取post数据可以用
php://input代替
修改代码为:
public function actionIndex() {
if (isset($_GET["echostr"]) && !empty($_GET["echostr"])) {
$this->valid();
} else {
$postStr =file_get_contents("php://input");
if (empty($postStr)) {
exit('.');
}
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
foreach ($postObj as $key => $value) {
$this->data[$key] = strval($value);
}
/**
* 关注时回复
*/
$arr_data = $this->data;
if ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'subscribe') { // 关注时回复
/**
* 场景二维码
*/
$qr = explode('_', $arr_data['EventKey']);
if ($arr_data['EventKey'] && isset($qr[1])) {
/**
* 场景二维码,首次关注
*/
$this->sceneQrSubscribe($qr[1], $arr_data['FromUserName']);
$this->sceneQr($qr[1], $arr_data['FromUserName']);
}
$WxSubscribeText = \common\models\WxSubscribeText::find()->one();
$SubscribeText = 'msg';
if (!empty($WxSubscribeText)) {
$SubscribeText = $WxSubscribeText->text;
}
$this->response($SubscribeText);
} else if ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'LOCATION') { //地理位置消息
} elseif ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'CLICK') { // 事件, 点击自定义菜单
$this->event($arr_data);
} else if ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'SCAN') { // 再次关注
if (isset($arr_data['EventKey']) && $arr_data['EventKey']) {
$this->sceneQr($arr_data['EventKey'], $arr_data['FromUserName']);
}
$this->response('您已经关注我们了!'); //"扫描 ".$arr_data['EventKey'];
} else if ($arr_data['MsgType'] == 'event' && $arr_data['Event'] == 'unsubscribe') { // 取消关注事件
$this->unsubscribe($arr_data['FromUserName']);
// 取消关注事件
} else { // 文本输入 检查 发送图片
/**
* 多客服
*/
$this->response('没有找到您要的内容!', 'text_kefu');
}
}
}
一切OK了!
解决升级PHP7后 微信公众号收不到消息的更多相关文章
- 微信公众号发送客服消息提示errcode":45015,"errmsg":"response out of time limit or subscription is canceled hint:解决办法【已解决】
微信公众号发送客服消息提示errcode":45015,"errmsg":"response out of time limit or subscription ...
- PHP开发微信公众号(二)消息接受与推送
上一篇文章我们知道怎么获取二维码,这样别人就可以扫描二维码来关注我们,但是别人关注后,发送消息,我们怎么进行相关处理? 这里我们就来学习下怎么处理处理这些消息,以及推送消息. 学习之前首先你需要有一个 ...
- Java微信公众号开发----关键字自动回复消息
在配置好开发者配置后,本人第一个想要实现的是自动回复消息的功能,说明以下几点: 1. url 仍然不变,还是开发配置里的url 2. 微信采用 xml 格式传输数据 3.微信服务器传给我们的参数主要有 ...
- tp6微信公众号开发者模式基础消息
官方文档 https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_standard_messages ...
- php简陋版实现微信公众号主动推送消息
推荐一个网站www.itziy.com csdn免积分下载器.pudn免积分下载器.51cto免积分下载器www.verypan.com 百度网盘搜索引擎www.94cto.com 编程相关视频教程. ...
- 使用 nodeJs 开发微信公众号(设置自动回复消息)
微信向第三方服务器发送请求时会降 signature .timestamp. nonce . openid(用户标识),发送内容会以 xml 的形式附加在请求中 回复消息前提我们得拿到用户id , 用 ...
- 微信公众号开发之文本消息自动回复,以及系统关注自动回复,php代码
以tshop为例 直接上代码: 企业 cc_wx_sys表为自建,存储系统消息的配置的 字段: id type key status <?php /** * tpshop * ========= ...
- 微信公众号开发之VS远程调试
目录 (一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 前言 微信公众平台消息接口的工作原理大概可以这样理解:从用户端到公众号端一个流 ...
- 基于NodeJS微信公众号
最近重新研究了微信公众号的高级接口,原来也利用C#或JAVA写过微信公众号,主要是消息的基础接口. 由于当时不知道微信公众号可以申请测试公众号,微信测试公众号基本上没有任何限制,对于开发来说是一个不错 ...
随机推荐
- mysql定时任务
查看event是否开启: show variables like '%sche%'; 将事件计划开启: set global event_scheduler=1; 关闭事件任务: alter even ...
- redis消息队列简单应用
消息队列出现的原因 随着互联网的高速发展,门户网站.视频直播.电商领域等web应用中,高并发.大数据已经成为基本的标识.淘宝双11.京东618.各种抢购.秒杀活动.以及12306的春运抢票等,他们这些 ...
- api签名
当你提交以上信息时,办公逸将发送GET请求到填写的URL,GET请求将携带四个参数, 参数 描述 是否必带 signature 办公逸签名,signature结合了企业填写的token,请求中的tim ...
- redis中的跳跃表
参考:http://www.leoox.com/?p=347
- 子div设置float后导致父div无法自动撑开的问题
子div设置float后会导致父div无法自动撑开 原因:内部的DIV因为float:left之后,就丢失了clear:both和display:block的样式,所以外部的DIV不会被撑开. 以下是 ...
- rcu机制
转载自:再谈Linux内核中的RCU机制-MagicBoy2010-ChinaUnix博客 http://blog.chinaunix.net/uid-23769728-id-3080134.html ...
- Eclipse 中文的设置
步骤如下:一.下载:在Eclipse官网下载相应版本的中文包. 二.中文包安装:1.解压中文语言包中的两个文件夹至Eclipse文件夹的dropins文件夹中.(目录不要放错)2.安装:方法一:使用命 ...
- 解决Android studio导入项目卡死
在使用Android studio的时候常常遇到这样的问题,从github或是其他地方导入项目,Android studio呈现卡死的现象!当遇到这种情况时,可以看看是下面那种情况,在按照方法来解决! ...
- 云服务器 Centos7.0 部署
CentOS安装jdk的三种方法 http://www.mamicode.com/info-detail-613410.html centos Linux下安装Tomcat和发布Java的web程序 ...
- github with msysgit:配置SSH Key
Step 1: Check for SSH keys First, we need to check for existing ssh keys on your computer. Open up G ...