解决升级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写过微信公众号,主要是消息的基础接口. 由于当时不知道微信公众号可以申请测试公众号,微信测试公众号基本上没有任何限制,对于开发来说是一个不错 ...
随机推荐
- linux下mnt目录作用
linux下mnt目录作用 一.mount 英文解释 登上; 爬上; 攀登; 骑上; 乘上; 跨上 可直接理解为“挂载” 挂接光驱.USB设备的目录,加载后,会在mnt里多出相应设备的目录.mnt是m ...
- mybatis-generator运行命令
java -jar mybatis-generator-core-x.x.x.jar -configfile generatorConfig.xml -overwrite
- Spring MVC学习笔记——文件上传
1.实现文件上传首先需要导入Apache的包,commons-fileupload-1.2.2.jar和commons-io-2.1.jar 实现上传就在add.jsp文件中修改表单 enctype= ...
- Java多线程 3 线程同步
在之前,已经学习到了线程的创建和状态控制,但是每个线程之间几乎都没有什么太大的联系.可是有的时候,可能存在多个线程多同一个数据进行操作,这样,可能就会引用各种奇怪的问题.现在就来学习多线程对数据访问的 ...
- Standard C 语言标准函数库介绍
全面巩固所知所学,往精通方向迈进! Standard C 语言标准函数库速查 (Cheat Sheet) from:http://ganquan.info/standard-c/function/ C ...
- Android之列表索引
其实这个功能是仿苹果的,但是现在大多数Android设备都已经有了这个功能,尤其是在通讯录中最为常见.先来看看今天这个DEMO的效果图(如下图):从图中我们可以看到,屏幕中的主体是一个ListView ...
- c++语言友元函数和成员函数对运算符重载
#include<iostream> using namespace std; /******************************************/ /*use mem ...
- mysqldump数据库同步遇到的问题
1.同步数据是遇到 没有 lock database权限,报 " mysqldump: Got error: 1044: Access denied for user 'spider_dat ...
- VBA中使用计时器的两种方法
'================================ ' VBA采用Application.OnTime实现计时器 ' ' http://www.cnhup.com '========= ...
- C++11中自定义range
python中的range功能非常好用 for i in range(100): print(i) 现在利用C++11的基于范围的for循环特性实现C++中的range功能 class range { ...