public function deal($postData) { LogUtil::logs("TypeVoice deal=====> " . print_r($postData, true), getLogFile("/business.log")); $FromUserName = $postData["FromUserName"]; $Recognition = $postData["Recognition"]; $paramsData['Content'] = empty($Recognition) ? "没听清,请再说一次" : $Recognition; $paramsData['MsgType'] = 'text'; // 同步响应 echo parent::packageData($postData, $paramsData); }
/** * 点击按钮菜单时,同步返回信息 */ public function dealByAychReturn($postData) { LogUtil::logs(" TypeEvent EventKey nodb=====> " . print_r($postData, true), getLogFile("/business.log")); $FromUserName = $postData["FromUserName"]; $Event = $postData["Event"]; $EventKey = $postData["EventKey"]; // 对应自定义的key 值 LogUtil::logs(" TypeEvent EventKey nodb=====> " . $EventKey, getLogFile("/business.log")); // 拿事件类型 和 点击的按钮key值判断 可以决定业务类型 if ($Event == "CLICK") { $returnStr = ""; $paramContent = array(); $content = ""; if ($EventKey == getEnterKeyName()) { // 进入聊天室 // 更新自己在聊天室的状态 $this->updateDbStatus('0', $FromUserName); // 回复文本消息 $content = "您已进入聊天室, 可以和大家聊天啦"; } else { if ($EventKey == getExitKeyName()) { // 退出聊天室 // 更新自己在聊天室的状态 $this->updateDbStatus('1', $FromUserName); // 回复文本消息 $content = "您已退出聊天室"; } } $paramsData['Content'] = $content; $paramsData['MsgType'] = 'text'; // 同步响应 echo parent::packageData($postData, $paramsData); } elseif ($Event == "unsubscribe") { // 用户取消关注 // 根据用户id查询用户基本信息 $userInfo = parent::getUserInfoFromWx($FromUserName); LogUtil::logs(" TypeEvent unsubscribe userInfo=====> " . print_r($userInfo, true), getLogFile("/business.log")); $this->synchronizedUserInfo($userInfo, $Event); } elseif ($Event == "subscribe") { // 用户关注 // 根据用户id查询用户基本信息 $userInfo = parent::getUserInfoFromWx($FromUserName); LogUtil::logs(" TypeEvent subscribe userInfo=====> " . print_r($userInfo, true), getLogFile("/business.log")); $this->synchronizedUserInfo($userInfo, $Event); } }
/** * 普通消息公共调用 * MsgType : text image voice video 等 */ function autoReplay($postData) { $openid = $postData["FromUserName"]; $content = $postData["Content"]; $createtime = DateUtil::getCurrentTime(); $msgData = array(); if ($postData['MsgType'] == 'text' && !empty($content)) { // 判断是否修改信息 // $strrule = "/^更新信息+.*/"; $strrule = "/^备注#.*/"; LogUtil::logs("autoReplay content ====>" . $content, getLogFile("/business.log")); if (preg_match($strrule, $content)) { LogUtil::logs("autoReplay content ====>" . $content, getLogFile("/business.log")); //$arr = explode("+", $content); $arr = explode("#", $content); $returnmsg = ""; $backup = $arr[1]; if (!preg_match("/^.{0,30}\$/", $backup)) { $returnmsg .= " 亲备注信息不要超过30个字符哦/:,@-D"; $paramsData['Content'] = $returnmsg; $paramsData['MsgType'] = 'text'; return parent::packageData($postData, $paramsData); } /*$mobile = $arr[2]; if(!preg_match("/^1[3|4|5|7|8][0-9]\\d{8}$/", $mobile)){ $returnmsg .= " 手机号格式不正确"; }*/ if (empty($returnmsg)) { $returnmsg = "信息更新申请成功"; } global $db; //$db -> exec("update wx_user_info set localnickname='$localnickname', mobile='$mobile' where openid='$openid'"); $db->exec("update wx_user_info set backup='{$backup}', mobile='{$mobile}' where openid='{$openid}'"); // 用户申请更新信息 $paramsData['Content'] = $returnmsg; $paramsData['MsgType'] = 'text'; return parent::packageData($postData, $paramsData); } else { // 不更新信息的情况下,只要保存到后台即可 DBUtil::saveMsg($openid, $content, $createtime, "", "5", "0"); return getSuccessStr(); } // 用户发送的信息,要保存到数据库// 消息类型: 0表示用户发送 1表示管理员回复 2表示管理员群发消息 3 自动回复 4聊天室信息 5用户私聊管理员 } }