public function index() { $weObj = new \System\lib\Wechat\Wechat($this->config('WEIXIN_CONFIG')); $this->weObj = $weObj; //对接验证 $weObj->valid(); $type = $weObj->getRev()->getRevType(); // 获取数据类型 $data = $weObj->getRev()->getRevData(); // 获取微信服务器发来的信息 $this->weixinData = $data; //$openid = $this->weixinData['FromUserName']; //记录日志 file_put_contents("Log/wechat.txt", json_encode($data) . " 日期:" . date("Y-m-d H:i:s") . PHP_EOL, FILE_APPEND); switch ($type) { case $weObj::MSGTYPE_TEXT: // 文本类型 // 记录文本消息到数据库 $this->_saveTextMsg(); //---特殊操作优先--- // 关键字回复 $result = $this->_getKeywordReply(); //自动回复 $auotMsg = $this->_getAutoReply(); break; case $weObj::MSGTYPE_EVENT: // 事件类型 if ($data['Event'] == "subscribe") { // 关注事件 //添加粉丝操作 //$this->_addFans(); //关注回复 $this->_getFollowReply(); } elseif ($data['Event'] == "unsubscribe") { // 取消关注事件 //记录取消关注事件 $this->_saveFollowMsg(); //粉丝操作 $this->_updateFans(); } elseif ($data['Event'] == "LOCATION") { // 获取上报的地理位置事件 //记录用户自动上传的地址位置 $this->_saveLocationMsgAuto(); } elseif ($data['Event'] == "CLICK") { // 自定义菜单 // 记录自定义菜单消息 $this->_saveMenuMsg(); //菜单点击事件 $content = $data["EventKey"]; $result = $this->_getKeywordReply($content); } elseif ($data['Event'] == "VIEW") { // 点击菜单跳转链接时的事件推送 // 记录自定义菜单消息 $this->_saveMenuMsg(); } elseif ($data['Event'] == "SCAN") { //扫二维码进入公众号 // 记录自定义菜单消息 $this->_saveScanMsg(); } elseif (!empty($data['KfAccount'])) { //客服时间 $this->_saveKfMsg(); } break; case $weObj::MSGTYPE_IMAGE: // 图片类型 // 记录图片消息 $this->_saveImgMsg(); break; case $weObj::MSGTYPE_LOCATION: // 地理位置类型 $this->_saveLocationMsg(); $weObj->text("地理位置已接收")->reply(); break; case $weObj::MSGTYPE_LINK: // 链接消息 $this->_saveLinkMsg(); $weObj->text("链接消息已接收")->reply(); break; default: $weObj->text("help info")->reply(); } }