服务器配置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后 微信公众号收不到消息的更多相关文章

  1. 微信公众号发送客服消息提示errcode":45015,"errmsg":"response out of time limit or subscription is canceled hint:解决办法【已解决】

    微信公众号发送客服消息提示errcode":45015,"errmsg":"response out of time limit or subscription ...

  2. PHP开发微信公众号(二)消息接受与推送

    上一篇文章我们知道怎么获取二维码,这样别人就可以扫描二维码来关注我们,但是别人关注后,发送消息,我们怎么进行相关处理? 这里我们就来学习下怎么处理处理这些消息,以及推送消息. 学习之前首先你需要有一个 ...

  3. Java微信公众号开发----关键字自动回复消息

    在配置好开发者配置后,本人第一个想要实现的是自动回复消息的功能,说明以下几点: 1. url 仍然不变,还是开发配置里的url 2. 微信采用 xml 格式传输数据 3.微信服务器传给我们的参数主要有 ...

  4. tp6微信公众号开发者模式基础消息

    官方文档 https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Receiving_standard_messages ...

  5. php简陋版实现微信公众号主动推送消息

    推荐一个网站www.itziy.com csdn免积分下载器.pudn免积分下载器.51cto免积分下载器www.verypan.com 百度网盘搜索引擎www.94cto.com 编程相关视频教程. ...

  6. 使用 nodeJs 开发微信公众号(设置自动回复消息)

    微信向第三方服务器发送请求时会降 signature .timestamp. nonce . openid(用户标识),发送内容会以 xml 的形式附加在请求中 回复消息前提我们得拿到用户id , 用 ...

  7. 微信公众号开发之文本消息自动回复,以及系统关注自动回复,php代码

    以tshop为例 直接上代码: 企业 cc_wx_sys表为自建,存储系统消息的配置的 字段: id type key status <?php /** * tpshop * ========= ...

  8. 微信公众号开发之VS远程调试

    目录 (一)微信公众号开发之VS远程调试 (二)微信公众号开发之基础梳理 (三)微信公众号开发之自动消息回复和自定义菜单 前言 微信公众平台消息接口的工作原理大概可以这样理解:从用户端到公众号端一个流 ...

  9. 基于NodeJS微信公众号

    最近重新研究了微信公众号的高级接口,原来也利用C#或JAVA写过微信公众号,主要是消息的基础接口. 由于当时不知道微信公众号可以申请测试公众号,微信测试公众号基本上没有任何限制,对于开发来说是一个不错 ...

随机推荐

  1. supermpa配置遇到的问题

    环境 vs2010  supermap idesktop7.1.2  iobject7.1.2.net windowform 问题 在安装iobject7.1.2 64位时 在vs中的工具箱是不显示s ...

  2. Sed、Awk单行脚本快速参考

    文本间隔: # 在每一行后面增加一空行 sed G awk '{printf("%s\n\n",$0)}' # 将原来的所有空行删除并在每一行后面增加一空行. # 这样在输出的文本 ...

  3. thinkphp3.22 多项目配置

    1.index.php if(version_compare(PHP_VERSION,'5.3.0','<')) die('require PHP > 5.3.0 !'); // 开启调试 ...

  4. Python题目

    https://github.com/taizilongxu/interview_python 1 Python的函数参数传递 strings, tuples, 和numbers是不可更改的对象,而l ...

  5. SQL 删除索引错误

    SQL Server 数据库执行 ”DROP INDEX 索引名 ON 表名“ 时出现“不允许对索引 '索引名' 显式地使用 DROP INDEX.该索引正用于 PRIMARY KEY 约束的强制执行 ...

  6. Excel——MATCH函数

    使用 MATCH 函数在范围单元格中搜索特定的项,然后返回该项在此区域中的相对位置. 1.参数说明: MATCH(lookup_value, lookup_array, [match_type]) l ...

  7. file xxx from install of xxx conflicts with file from xxx

    执行安装 rpm -ivh lib64stdc++6-4.6.1-2-mdv2011.0.x86_64.rpm 时提示以下错误: warning: lib64stdc++6-4.6.1-2-mdv20 ...

  8. Autoit中用PrintWindow替代ScreenCapture函数实现截图

    想截取躲在后面的窗体或控件,找到了PrintWindow函数,幸运的是Autoit3也对此进行了封装以方便使用. 于是乎,将帮助文件里的_WinAPI_PrintWindow()实例改写了一下,以替代 ...

  9. 一些js

    //fixed块随滚动条滚动 window.onscroll=function(){ var scroll_left = $(window).scrollLeft(); $('#table_fixed ...

  10. SLF4J: Class path contains multiple SLF4J bindings.

    库冲突导致的异常,由于多次引入SLF4j包导致. It seems you have several implementation of SLF4J; you should exclude all t ...