博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PHP 操控微信公众号
阅读量:4963 次
发布时间:2019-06-12

本文共 5048 字,大约阅读时间需要 16 分钟。

response_msg(); } } private function response_msg() { $postArr = $GLOBALS['HTTP_RAW_POST_DATA']; $postObj = simplexml_load_string($postArr); if (strtolower($postObj->MsgType) == 'event') { //回复用户消息 $toUser = $postObj->FromUserName; $fromUser = $postObj->ToUserName; //如果是关注事件(subscribe) if (strtolower($postObj->Event == 'subscribe')) { // 是否有推荐人 $referrer = $postObj->EventKey; // 关注人openid $openid = $toUser->__toString(); $referrer_str = $referrer->__toString(); if ($referrer_str) { $referrer_openid = explode('_',$referrer_str)[1]; // 判断关注人是否已关注别人 $wx_recommend = M('wx_recommend'); $exist = $wx_recommend->where(['new_openid'=>$openid])->find(); if (!$exist) { // 有效的用户 // 添加记录 $data = [ 'openid' => $referrer_openid, 'new_openid' => $openid, 'add_time'=> time(), ]; $wx_recommend->add($data); } } $arr = array( array( 'title' => '标题', 'description' => "描述", 'picUrl' => 'xxx.jpg', 'url' => 'xxx.html', ), ); $this->_send_news($arr,$toUser,$fromUser); } elseif ($postObj->Event == 'CLICK') { //------------------- 点击事件 start ------------------------ $event_key = $postObj->EventKey; // 获取key if($event_key=='V1001_PRESENT'){ $arr = array( array( 'title' => '标题', 'description' => "描述", 'picUrl' => 'xxx.jpg', 'url' => 'xxx.html', ), ); $this->_send_news($arr,$toUser,$fromUser); } //------------------- 点击事件 end ------------------------ } } //回复纯文本或单图文消息 if (($postObj->MsgType) == 'text' && (trim($postObj->Content) == '我要帽子' || trim($postObj->Content) == '帽子')) { $toUser = $postObj->FromUserName; $fromUser = $postObj->ToUserName; $arr = array( array( 'title' => '标题', 'description' => "描述", 'picUrl' => 'xxx.jpg', 'url' => 'xxx.html', ), ); $this->_send_news($arr,$toUser,$fromUser); } else if(($postObj->MsgType) == 'text' && (trim($postObj->Content) == '数量' || trim($postObj->Content) == '6')) { $fromUser = $postObj->ToUserName;//消息从哪里来 $toUser = $postObj->FromUserName;//发送给谁 // 用户openid $openid = $toUser->__toString(); // 获取推荐数量 $wx_recommend = M('wx_recommend'); $count = $wx_recommend->where(['openid'=>$openid])->count(); $content = "您当前已推荐关注人数为:".$count; $this->_send_text($content,$toUser,$fromUser); } else { $fromUser = $postObj->ToUserName;//消息从哪里来 $toUser = $postObj->FromUserName;//发送给谁 $content = "内容"; $this->_send_text($content,$toUser,$fromUser); } } private function _send_text($content,$toUser,$fromUser) { $template = "
%s
"; $time = time(); $msgType = 'text'; echo sprintf($template, $toUser, $fromUser, $time, $msgType, $content); } private function _send_news($arr,$toUser,$fromUser) { $template = "
%s
" . count($arr) . "
"; foreach ($arr as $k => $v) { $template .= "
<![CDATA[" . $v['title'] . "]]>
"; } $template .= "
"; $time = time(); $msgType = "news"; echo sprintf($template, $toUser, $fromUser, $time, $msgType); }}

转载于:https://www.cnblogs.com/jiqing9006/p/10007043.html

你可能感兴趣的文章
Python模块调用
查看>>
委托的调用
查看>>
c#中从string数组转换到int数组
查看>>
数据模型(LP32 ILP32 LP64 LLP64 ILP64 )
查看>>
java小技巧
查看>>
POJ 3204 Ikki's Story I - Road Reconstruction
查看>>
【BZOJ】2959: 长跑(lct+缩点)(暂时弃坑)
查看>>
iOS 加载图片选择imageNamed 方法还是 imageWithContentsOfFile?
查看>>
toad for oracle中文显示乱码
查看>>
SQL中Group By的使用
查看>>
错误org/aopalliance/intercept/MethodInterceptor解决方法
查看>>
Pylint在项目中的使用
查看>>
使用nginx做反向代理和负载均衡效果图
查看>>
access remote libvirtd
查看>>
(4) Orchard 开发之 Page 的信息存在哪?
查看>>
ASP.NET中 GridView(网格视图)的使用前台绑定
查看>>
深入了解Oracle ASM(二):ASM File number 1 文件目录
查看>>
Boosting(提升方法)之AdaBoost
查看>>
Binding object to winForm controller through VS2010 Designer(通过VS2010设计器将对象绑定到winForm控件上)...
查看>>
Spring Boot实战笔记(二)-- Spring常用配置(Scope、Spring EL和资源调用)
查看>>