public function sendMsg($request, $response) { /*{{{*/ $msg = $request->msg; DBC::requireNotEmptyString($msg, "消息不能为空!!!"); $wxUser = DAL::get()->find('WxUser', $request->wxUserId); DBC::requireTrue($wxUser instanceof WxUser, "WxUser不存在!!!"); WxApi::kefuTextMsg($wxUser, $msg); $toUser = $wxUser->nickname; WxMgrClient::getInstance()->addAdminReplyMsg($msg, $toUser); $response->setRedirect($_SERVER["HTTP_REFERER"]); }
private function anaPostData($request, $response) { /*{{{*/ //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)) { //保存数据 $wxPostData = WxClient::getInstance()->addWxPostData($postStr); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement'); $msgId = $postObj->MsgId; $msgType = $postObj->MsgType; $event = isset($postObj->Event) ? $postObj->Event : ''; $fromUserName = $postObj->FromUserName; $toUserName = trim($postObj->ToUserName); $content = isset($postObj->Content) ? $postObj->Content : ''; $eventKey = isset($postObj->EventKey) ? $postObj->EventKey : ''; $mediaId = isset($postObj->MediaId) ? $postObj->MediaId : ''; $content = mb_convert_encoding($content, 'gbk', array('auto')); $wxUser = DAL::get()->find_by_openid('WxUser', (string) $fromUserName); //取消关注事件 if (WxApi::isEventMsg($msgType) && $event == 'unsubscribe') { /*{{{*/ WxClient::getInstance()->updateSubscribe($wxUser->id, '0'); } /*}}}*/ //关注事件则创建WxUser并获取微信用户的信息 if (WxApi::isEventMsg($msgType) && $event == 'subscribe') { /*{{{*/ $wxUserId = WxClient::getInstance()->createWxUser((string) $fromUserName); // 关注推送八篇文章(菜单)逻辑 $wxArticleIds = DAL::get()->query_wxarticle_after_subscribe('WxArticle'); $wxArticles = DAL::get()->find('WxArticle', $wxArticleIds); echo WxApi::xiangyingNewsMsg($fromUserName, $wxArticles, $wxUserId); exit; } /*}}}*/ //患者报到事件创建COOKIE同时创建WxBaoDao用户 if (WxApi::isEventMsg($msgType) && $eventKey == "patient_report") { /*{{{*/ $wxArticle = DAL::get()->find_by_code('WxArticle', 'patient_report'); echo WxApi::xiangyingNewsMsg($fromUserName, array($wxArticle), $wxUser->id); exit; } /*}}}*/ if (WxApi::isEventMsg($msgType) && $eventKey == "http://301bleeding.haodf.com/wx/anginaassess") { /*{{{*/ if ($wxUser->isCookie != 1) { $wxArticle = DAL::get()->find_by_code('WxArticle', 'patient_report'); echo WxApi::kefuNewsMsg($wxUser, array($wxArticle), $wxUser->id); } exit; } /*}}}*/ if (WxApi::isEventMsg($msgType) && $eventKey == "http://301bleeding.haodf.com/wx/symptomgrade") { /*{{{*/ if ($wxUser->isCookie != 1) { $wxArticle = DAL::get()->find_by_code('WxArticle', 'patient_report'); echo WxApi::kefuNewsMsg($wxUser, array($wxArticle), $wxUser->id); } exit; } /*}}}*/ if (WxApi::isEventMsg($msgType) && $eventKey == "http://301bleeding.haodf.com/wx/bloodpressuremanage") { /*{{{*/ if ($wxUser->isCookie != 1) { $wxArticle = DAL::get()->find_by_code('WxArticle', 'patient_report'); echo WxApi::kefuNewsMsg($wxUser, array($wxArticle), $wxUser->id); } exit; } /*}}}*/ //普通消息则保存下来并发送指定文章和阅读量最高文章和导航下行消息 if (WxApi::isCommonMsg($msgType) && !WxApi::isDailyPhotoWord($content)) { /*{{{*/ //test 专用清除Cookie if ($content == 'clear cookie 007') { $str = "您好,请慎重使用清除功能。<a href='http://301bleeding.haodf.com/wx/clearcookie?wxuserid={$wxUser->id}'>点此进行清除cookie</a>"; echo WxApi::formatXiangyingTextMsg($fromUserName, $str); exit; } if ($content == 'clear cookie 008') { $str = "您好,请慎重使用清除功能。<a href='http://test.wx.haodf.com/wx/clearcookie?wxuserid={$wxUser->id}'>点此进行清除cookie</a>"; echo WxApi::formatXiangyingTextMsg($fromUserName, $str); exit; } if ($content == 'test diary 008') { $str = "您好,请慎重使用健康日记测试功能。<a href='http://test.wx.haodf.com/wx/healthdiary?wxuserid={$wxUser->id}'>点此进行测试diary</a>"; echo WxApi::formatXiangyingTextMsg($fromUserName, $str); exit; } if ($content == 'test bloodsugar 008') { $str = "您好,请慎重使用血糖测试功能<a href='http://test.wx.haodf.com/wx/bloodsugarmanage?wxuserid={$wxUser->id}'>点此进行测试diary</a>"; echo WxApi::formatXiangyingTextMsg($fromUserName, $str); exit; } $wxMsg = $this->saveCommonMsg($postObj); //保存用户的图片文件到attachment,绑定用户自动同步到复查报告 if ($msgType == 'image' && isset($mediaId)) { /*{{{*/ WxApi::downloadPhoto($mediaId, $wxUser); } /*}}}*/ //text类型关键字消息模糊匹配成功时,推送1-3篇文章 if ($msgType == 'text' && ($wxArticles = WxApi::isKeyWordOfArticle($content, $fromUserName))) { /*{{{*/ echo WxApi::xiangyingNewsMsg($fromUserName, $wxArticles); WxMgrClient::getInstance()->addWxArticleReadLog($wxUser, $wxArticles); } else { /*{{{*/ if (!WxClient::getInstance()->todayIsLastDefaultMessageDate($wxUser)) { exit; } $wxArticleIds = DAL::get()->query_default_and_viewcnt('WxArticle'); $wxArticles = DAL::get()->find('WxArticle', $wxArticleIds); echo WxApi::xiangyingNewsMsg($fromUserName, $wxArticles); WxMgrClient::getInstance()->addWxArticleReadLog($wxUser, $wxArticles); $str = "如果您需了解冠心病知识请浏览【每日知识】栏目,进行疾病管理请进入【疾病管理】栏目,了解我们请进入【关于我们】栏目,其他要求请直接输入文字或语音。"; echo WxApi::kefuTextMsg($wxUser, $str); } /*}}}*/ exit; } /*}}}*/ //每日一图事件每天每种一篇 if (WxApi::isEventMsg($msgType) && ($type = WxApi::isDailyPhotoEvent($eventKey)) || WxApi::isCommonMsg($msgType) && ($type = WxApi::isDailyPhotoWord($content))) { /*{{{*/ $re = DAL::get()->query_cnt_by_wxuserid_and_ctime('WxArticleReadLog', $wxUser->id, $type); if ($re > 0 && !WxApi::isDeveloperOrOperator($fromUserName)) { $wxArticleReadLog = DAL::get()->find_by_wxuserid_and_readdate_and_type('WxArticleReadLog', $wxUser->id, date('Y-m-d'), $type); echo WxApi::formatXiangyingTextMsg($fromUserName, "今天您的[" . $wxArticleReadLog->wxArticle->getTypeDesc() . "]已阅读,敬请期待明天的精彩或阅览其它栏目。"); // $wxArticles = array($wxArticleReadLog->wxArticle); // echo WxApi::xiangyingNewsMsg($fromUserName, $wxArticles); // WxMgrClient::getInstance()->addWxArticleReadLog($wxUser, $wxArticles); exit; } $wxArticleIds = DAL::get()->query_by_notRead_of_wxUserId('WxArticle', $wxUser->id, $type); if (!isset($wxArticleIds) || empty($wxArticleIds)) { $wxArticle = DAL::get()->find_by_type('WxArticle', $type); echo WxApi::formatXiangyingTextMsg($fromUserName, "很抱歉,[" . $wxArticle->getTypeDesc() . "]知识池已空,感谢您一如以往的支持,工作人员会尽快添加更多知识,敬请期待。"); exit; } $wxArticles = DAL::get()->find('WxArticle', $wxArticleIds); echo WxApi::xiangyingNewsMsg($fromUserName, $wxArticles); WxMgrClient::getInstance()->addWxArticleReadLog($wxUser, $wxArticles); } else { $str = "你好,欢迎加入互动峰院后管理微信平台。"; echo WxApi::formatXiangyingTextMsg($fromUserName, $str); } } else { echo mb_convert_encoding("你啥也没说", 'utf-8', 'auto'); } exit; }