예제 #1
0
 /**
  * 普通消息公共调用
  * 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用户私聊管理员
     }
 }
예제 #2
0
 /**
  * 查到用户组里面的所有组员,再向其发送消息 
  */
 function queryGroupUserAndReplyMsg($userGroupId, $postData)
 {
     global $db;
     // 发消息的人自己
     $userSelfOpenid = $postData["FromUserName"];
     $content = $postData["Content"];
     $createtime = DateUtil::getCurrentTime();
     $mediaid = $postData["MediaId"];
     // 用户发送的信息,要保存到数据库
     // 消息类型: 0表示用户发送  1表示管理员回复 2表示管理员群发消息 3 自动回复  4聊天室信息
     DBUtil::saveMsg($userSelfOpenid, "图片消息", $createtime, "", "4", "0");
     // 查询所有的组员
     $arr = array();
     // TODO 这个$res可以缓存到文件中
     $res = $db->query("SELECT * FROM wx_group_user where groupid = '{$userGroupId}' and userisin = '0' ");
     $row = $db->fetch_all($res);
     foreach ($row as $val) {
         // 循环每个人推送一条消息
         $openid = $val['openid'];
         // 从组中除去发信息者自己
         if ($userSelfOpenid != $openid) {
             // 拼接
             /*{
             		    "touser":"******",
             		    "msgtype":"image",
             		    "image":
             		    {
             		      "media_id":"MEDIA_ID"
             		    }
             		}*/
             $paramContent = array("touser" => $openid, "msgtype" => "image", "image" => array("media_id" => $mediaid));
             $data = JsonUtil::getJsonStrFromArray($paramContent);
             LogUtil::logs("queryGroupUserAndReplyMsg data ====>" . $data, getLogFile("/business.log"));
             parent::sendMsgByService($data);
         }
     }
     return getSuccessStr();
 }