由网络副手--寻路人于2016.06.21 17:12:00发布在编程语言,PHP代码 借助WeChart微信包开发订阅号以及微信服务号 阅读3559 评论0 喜欢0 一、接收服务器配置信息并解析POSTXML 微信开发者信息配置: http://www.text.com/WeinxNotice/getNotice (接收服务器信息接口) * @Date : 2016/6/209:56 */ class WeinxNoticeController { const WXMSG_IMG = '网罗天下美图,快来看看吧'; const WXMSG_VIDEO = '更全更受欢迎的影视网站,快来看看吧'; const WXMSG_SHORTVIDEO= '看看帅哥美女都在做什么吧'; const WXMSG_LOCATION = '要寻找身边好吃、好玩的吗?'; private $WeiXinConf; public function __construct() { $wxConf = QFrameConfig::getConfig("WEIXIN_CONF"); $this->WeiXinConf = array( 'token' => $wxConf['Account']['signToken'], 'encodingaeskey' => $wxConf['Account']['encodingAesKey'], 'appid' => $wxConf['Account']['appId'], 'appsecret' => $wxConf['Account']['appSecret'], ); } public function getNoticeAction() { $weObj = new Wechat($this->WeiXinConf); $weObj->valid(); //获取接收事件 $eventInfo = $weObj->getRev()->getRevEvent(); if ( $eventInfo && array_key_exists('event', $eventInfo) && !empty($eventInfo['event']) ) { switch ($eventInfo['event']) { //关注 case Wechat::EVENT_SUBSCRIBE : $weObj->text("欢迎关注")->reply(); break; //取消关注 case Wechat::EVENT_UNSUBSCRIBE : $weObj->text("取消成功")->reply(); break; } exit; } //获取消息类型进行判断 $type = $weObj->getRev()->getRevType(); switch ($type) { //TEXT文本消息以及语音接口转义信息 case Wechat::MSGTYPE_VOICE : case Wechat::MSGTYPE_TEXT : $textInfo = $weObj->getRevContent(); $keyWorldMod = new KeyWordsModel($textInfo); $weObj->text($keyWorldMod->DealText())->reply(); break; case Wechat::MSGTYPE_IMAGE : $weObj->text(self::WXMSG_IMG)->reply(); break; case Wechat::MSGTYPE_VIDEO : $weObj->text(self::WXMSG_VIDEO)->reply(); break; case Wechat::MSGTYPE_SHORTVIDEO : $weObj->text(self::WXMSG_SHORTVIDEO)->reply(); break; case Wechat::MSGTYPE_LOCATION : $weObj->text(self::WXMSG_LOCATION)->reply(); break; default: $weObj->text("收到您的消息")->reply(); exit; } exit; } } 二、关键词接收处理文件 KeyWordsModel.php * @Date : 2016/6/2111:17 */ class KeyWordsModel { const WX_MSG_DEFAULT = 1000; private $_WX_MSGTXT; public function __construct($text) { $this->_WX_MSGTXT = strtolower(trim($text)); } public function DealText(){ switch($this->_WX_MSGTXT){ case 'brave' : $Retext = '欢迎光临~'; break; default : //拓展 break; } return $Retext; } /** * @Desc : 过滤调情EMOJI表情包和QQ表情包 * @Date : 2016-06-21 16:47:03 * @param $msg */ private function ReplaceEmojiAndQQ($msg){ $qqEmoji = array('/::)','/::~','/::b','/:8-)','/::<','/::$','/::x','/::z','/::\'(','/::@','/::p','/::d','/::o','/::(','/::+','/:--b','/::q','/::t','/:,@p','/:,@-d','/::d','/:,@o','/::g','/:|-)','/::!','/::l','/::>','/::,@','/:,@f','/::-s','/:?','/:,@x','/:,@@','/::8','/:,@!','/:!!!','/:xx','/:bye','/:wipe','/:dig','/:handclap','/:&-(','/:b-)','/:<@','/:@>','/::-o','/:p-(','/:x-)','/::*','/:@x','/:8*','/:pd','/:','/:beer','/:basketb','/:oo','/:coffee','/:eat','/:pig','/:rose','/:fade','/:showlove','/:heart','/:break','/:cake','/:li','/:bome','/:kn','/:footb','/:ladybug','/:shit','/:moon','/:sun','/:gift','/:hug','/:strong','/:weak','/:share','/:v','/:@)','/:jj','/:@@','/:bad','/:lvu','/:no','/:ok','/:love','/:','/:jump','/:shake','/:','/:circle','/:kotow','/:turn','/:skip','/:oy','/:#-0','/:hiphot','/:kiss','/:<&','/:&>','/::|','/::\'|','/::-|','/:>-|'); $replace = array(); return str_replace($qqEmoji,$replace,$msg); } } WeChart 工具包下载: https://yunpan.cn/cReutCEmVCi8y (提取码:b330) 赞 0 分享 赏 您可以选择一种方式赞助本站 支付宝扫码赞助 BraveDu 署名: 网络副手~寻路人