解决升级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写过微信公众号,主要是消息的基础接口. 由于当时不知道微信公众号可以申请测试公众号,微信测试公众号基本上没有任何限制,对于开发来说是一个不错 ...
随机推荐
- app xml报错
如下图所示红色区域,xml中第7行提示以下错误,检查了好久,没发现什么异常,请高人指点下,谢谢! error parsing xml:not well-formed (invalid token)
- android 一些常用开源框架
网络请求compile 'com.squareup.okhttp:okhttp:2.6.0'okhttp依赖compile 'com.squareup.okio:okio:1.6.0'json解析co ...
- 初识cache
1.cache是什么 cache这个名字用来称呼两种物理世界中存在的概念,硬体cache和cache机制.下面来分别介绍. 硬体cache:硬体cache是一种用肉眼可以看得见用皮肤可以摸得着的物品, ...
- 浅谈ScrollView嵌套ListView及ListView嵌套的高度计算
引言 在Android开发中,我们有时会需要使用ScrollView中嵌套ListView的需求.例如:在展示信息的ListView上还有一部分信息展示区域,并且要求这部分信息展示区域在ListVie ...
- 代码质量管理工具——SonarQube
写在前面 SonarQube(简称Sonar)是管理代码质量的开放平台,它可以快速地对代码质量进行分析,并给出合理的解决方案,提高管理效率,保证代码质量. SonarQube的流行,在于以下几点: 开 ...
- 海拔高度图*.dem文件的读取—vtkDEMReader
vtkDEMReader reads digital elevation files and creates image data. Digital elevation files are produ ...
- Swift与OC区别
一.Swift与OC区别: 1.swift程序的入口是UIApplicationMain; 2.OC的类是以.h和.m组成的;swift是一.swift结尾的; 3.OC的类是以@interface和 ...
- AngularJS2.0 教程系列(一)
http://my.oschina.net/u/2275217/blog/482178
- Block formatting context(块级格式化上下文)
今天看到豆瓣面试官的一篇文章,讲到关于CSS中的一个知识点:Block formatting context ,感觉这个确实挺有用,同时我也挺赞同作者的一些观点的,这里就不展开谈我的感受了, 此文只 ...
- Java课程设计--山寨版QQ
Java课设要求做一个聊天通讯窗口,索性直接照着QQ撸了一个Demo出来 界面高仿qq,初学JAVA,技术比较渣,不喜勿喷 线程开的比较多性能不是太好,一般电脑开两个客户端聊天就卡卡的 先上图 使用方 ...