Beispiel #1
0
 /**
  * 通过客服接口发送多条图文消息到多个人
  * $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);
     }
 }
Beispiel #2
0
 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);
 }
Beispiel #3
0
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();
}
Beispiel #4
0
 /**
  * 点击按钮菜单时,同步返回信息
  */
 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);
     }
 }
Beispiel #5
0
/**
 * 调用群发接口,发送多条图文消息,服务号每个月4次
 */
function sendmultinewmsg()
{
    // 当前php文件所在目录
    //define('DIR_ROOT', str_replace('\\', '/', dirname(__FILE__)));
    // 项目根目录
    define('DIR_ROOT', $_SERVER['DOCUMENT_ROOT']);
    //define('DIR_ROOT', "/wwwroot/");
    $courseids = $_POST["courseids"];
    /*$inTemp = "";
    	foreach($courseids as $courseid){
    		$inTemp = $inTemp.$courseid.",";
    	}
    	$in = substr($inTemp, 0, strlen($inTemp) -1);
    	*/
    // 根据courseid查询对应的课程(推送)信息
    $querysql = "select * from cn_news where id in  (" . $courseids . ")";
    global $db;
    global $smarty;
    $res = $db->query($querysql);
    $rowlist = $db->fetch_all($res);
    // 先判断下是否存在不满足条件的数据
    $errortitle = "";
    foreach ($rowlist as $row) {
        if (empty($row["simage"])) {
            $errortitle .= "<font color='red'>\"" . $row["id"] . "\"</font><br />";
        }
    }
    if (!empty($errortitle)) {
        echo "编号为:<br />" . $errortitle . "的信息不完善,请重新编辑,添加图片、缩略图信息";
        return;
    }
    // TODO 先保存图片素材,得到media_id, 页面提示用户,图片素材数量上限
    // 图片(image)、语音(voice)、视频(video)和缩略图(thumb)
    $meidaType = "image";
    //
    // 循环所有的消息,制成成图片消息,拿到media id 数组
    $articles = array();
    $showcoverpic = "0";
    // 是否显示封面,1为显示,0为不显示
    foreach ($rowlist as $row) {
        //获取当前文件物理路径
        $tmp_file = DIR_ROOT . "/" . $row["simage"];
        //echo $tmp_file;
        if (file_exists($tmp_file)) {
            // 先循环制作所有的图片素材, 调素材管理接口上传图片,得到meidaid
            $response = WxUtil::uploadpic($meidaType, $tmp_file);
            if ($response["errcode"] == 0) {
                // 制作成功的,拼成一条信息
                $picmediaid = $response["media_id"];
                $title = $row["title"];
                $sourceurl = "http://bangmaisiw.w107.mc-test.com/wap/Course-Details.php?id=" . $row["id"];
                $content = $row["contents"];
                $digest = "";
                $article = array("thumb_media_id" => $picmediaid, "author" => "", "title" => $title, "content_source_url" => $sourceurl, "content" => $content, "digest" => $digest, "show_cover_pic" => $showcoverpic);
                $articles[] = $article;
            } else {
                LogUtil::logs("批量创建图片素材失败:消息来源id:" . $row["id"] . ",错误信息:" . $response["errmsg"], getLogFile("/business.log"));
            }
        } else {
            LogUtil::logs("文件不存在:" . $row["image"], getLogFile("/business.log"));
        }
    }
    $pictextResp = WxUtil::uploadmultipicmsg($articles);
    //echo print_r($pictextResp);
    // 图文消息 media_id
    if ($pictextResp["errcode"] == 0) {
        $pictextMediaid = $pictextResp["media_id"];
        // 拿到mediaid, 就可以发起推送了
        // 先获取openid列表
        $openidsql = "select openid, nickname from wx_user_info where subscribe = '1' ";
        $openidres = $db->query($openidsql);
        // php的json格式:array(""=>"")
        $openidList = $db->fetch_all($openidres);
        // 循环下,转成无key的值数组
        $openidarr = array();
        $lognickname = "";
        foreach ($openidList as $openid) {
            $lognickname .= $openid["nickname"] . ",";
            $openidarr[] = $openid["openid"];
        }
        //echo print_r($openidarr);
        $tp = new TypeParent();
        echo $tp->batchSendPicMsg($openidarr, $pictextMediaid);
        echo "<br />消息发送到:" . $lognickname;
        //		$yulanopenid = "osp6swvOvVa1aXcjbFGui0Ur88V4";
        //		echo $tp -> batchSendPicMsgYulan($yulanopenid, $pictextMediaid);
    } else {
        echo "消息发送失败:" . $pictextResp["errmsg"];
    }
}
Beispiel #6
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用户私聊管理员
     }
 }
Beispiel #7
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();
 }