/** * 通过客服接口发送多条图文消息到多个人 * $openid * $articles 参考sendImageTextMsg */ function sendMultiImageTextMsgToMultiUser($openidarr, $articles) { $news = array("articles" => $articles); foreach ($openidarr as $openid) { $data = JsonUtil::getJsonStrFromArray(array("touser" => $openid, "msgtype" => "news", "news" => $news)); parent::sendMsgByService($data); } }
function reply() { // msgid 是回复的目标消息id 对应表 的 replyid $msgid = $_POST["msgid"]; if (empty($msgid)) { return; } $content = $_POST["content"]; if (empty($content)) { return; } $openid = $_POST["createby"]; if (empty($openid)) { return; } // 回复消息要做2件事 // 1 调微信接口 $paramContent = array(); $contentTemp = array("content" => "管理员回复:\r\n" . $content); $paramContent = array("msgtype" => "text", "text" => $contentTemp); $data = JsonUtil::getJsonStrFromArray(array_merge($paramContent, array("touser" => $openid))); //LogUtil::logs("queryGroupUserAndReplyMsg data ====>".$data, getLogFile("/business.log")); $tp = new TypeParent(); $response = $tp->sendMsgByService($data); if ($response["errcode"] == 0) { // 回复成功 // 2 保存回复的消息 $msgtype = "1"; // 消息类型: 0表示用户发送 1表示管理员回复 2表示管理员群发消息 3 自动回复 4聊天室信息 $status = "0"; // 消息状态 :0: 消息发送成功 1: 发送中 2 发送失败, 保存成功 3 发送成功, 保存失败 4 表示这条信息是用户送的,并且已经得到回复 $createtime = DateUtil::getCurrentTime(); $createby = $_SESSION['cn_sysadmin']['user_id']; // 消息类型: 0表示用户发送 1表示管理员回复 2表示管理员群发消息 3 自动回复 4聊天室信息 DBUtil::saveMsg($createby, $content, $createtime, $msgid, $msgtype, $status); // 原来设计是将状态改为4用来标识已回复,现在能查到回复内容,就取消这个方案了 // $sql = "update wx_user_msg set status = '4' where id ='$msgid'"; // DBUtil::updateMsg($sql); } showlist(); }
/** * 查到用户组里面的所有组员,再向其发送消息 */ function queryGroupUserAndReplyMsg($userGroup, $postData) { global $db; // 发消息的人自己 $userSelfOpenid = $postData["FromUserName"]; $content = $postData["Content"]; $createtime = DateUtil::getCurrentTime(); // 用户发送的信息,要保存到数据库 // 消息类型: 0表示用户发送 1表示管理员回复 2表示管理员群发消息 3 自动回复 4聊天室信息 DBUtil::saveMsg($userSelfOpenid, $content, $createtime, "", "4", "0"); // 查询所有的组员 $arr = array(); $userGroupId = $userGroup['groupid']; $nickname = $userGroup['nickname']; // TODO 这个$res可以缓存到文件中 $res = $db->query("SELECT a.*, b.nickname, b.headimgurl FROM wx_group_user a left join wx_user_info b \r\n\t\t on a.openid = b.openid \r\n\t\t where a.groupid = '{$userGroupId}' and a.userisin = '0' "); $row = $db->fetch_all($res); //LogUtil::logs("用户组: ====>".print_r($row,true), getLogFile("/business.log")); foreach ($row as $val) { //LogUtil::logs("ppppppp ====>".print_r($val,true), getLogFile("/business.log")); // 循环每个人推送一条消息 $openid = $val['openid']; if ($userSelfOpenid != $openid) { // 从组中除去发信息者自己 $headimgurl = $val['headimgurl']; $contentTemp = array("content" => $nickname . "说:\r\n" . $content); $paramContent = array("touser" => $openid, "msgtype" => "text", "text" => $contentTemp); $data = JsonUtil::getJsonStrFromArray($paramContent); LogUtil::logs("queryGroupUserAndReplyMsg data ====>" . $data, getLogFile("/business.log")); parent::sendMsgByService($data); } } return getSuccessStr(); }
/** * 查到用户组里面的所有组员,再向其发送消息 */ 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(); }