解决升级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写过微信公众号,主要是消息的基础接口. 由于当时不知道微信公众号可以申请测试公众号,微信测试公众号基本上没有任何限制,对于开发来说是一个不错 ...
随机推荐
- prefix pct文件配置Xcode
1.查看项目的各个文件夹下的文件名称: 2.配置如下图:需要添加$(SRCROOT)/项目的名称/pch所在文件夹路径 .易于理解方便那些初学者,下载别人的demO运行时遇到这样的类似的问题噢.< ...
- JestClient
JestService.java [html] view plain copy 在CODE上查看代码片派生到我的代码片 public class JestService { /** * 获取JestC ...
- javascript的正则表达式学习
关于反向引用 复制代码 代码如下: // 测试函数 function matchReg(reg, str) { var result = str.match(reg); if(result) { co ...
- coreseek操作
开启服务$ /usr/local/coreseek/bin/searchd -c /usr/local/coreseek/etc/csft.conf 重新索引: /usr/local/coresee ...
- Java数据结构——树的三种存储结构
(转自http://blog.csdn.net/x1247600186/article/details/24670775) 说到存储结构,我们就会想到常用的两种存储方式:顺序存储和链式存储两种. 先来 ...
- 常用HTTP状态码和CURL 000问题
最近在测试CDN服务质量问题,测试过程中返回了一些不同的状态码,当然有一些常用的,也有一些不常用的.最奇葩的是在使用curl命令的时候出现000状态码,问了很多同事,对这个000的反应跟新事物是的 ...
- C#通过WebClient/HttpWebRequest实现http的post/get方法
C#通过WebClient/HttpWebRequest实现http的post/get方法 http://www.cnblogs.com/shadowtale/p/3372735.html
- MongoDB【第一篇】MongodDB初识
NoSQL介绍 一.NoSQL简介 NoSQL,全称是”Not Only Sql”,指的是非关系型的数据库. 非关系型数据库主要有这些特点:非关系型的.分布式的.开源的.水平可扩展的. 原始的目的是为 ...
- nginx配置ssl证书的方法
Nginx (读音"engine x") 是一个高性能的HTTP和反向代理服务器,比Apache占用更少的内存,同时也像Apache一样支持HTTPS方式访问(SSL加密).本教程 ...
- Android:TextView文字跑马灯的效果实现
解决TextView文字显示不全的问题. 简单设置跑马灯的效果: <TextView android:id="@+id/textView" android:layout_wi ...