private function anaPostData4Space($request,$response) {/*{{{*/ //get post data, May be due to the different environments $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; if (!empty($postStr)) { //保存数据 $weixPostData = WeixClient::getInstance()->addWeixPostData($postStr, WeixUser::WEIXINTYPE_SPACE); $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $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:''; $weixintype = WeixUser::WEIXINTYPE_SPACE; $Content = mb_convert_encoding($Content, 'gbk', array('auto')); $weixUser = DAL::get()->find_by_openid_and_weixintype('WeixUser', (string)$FromUserName, WeixUser::WEIXINTYPE_SPACE); if(WeixApi::isEventMsg($MsgType) && $Event == 'unsubscribe') {/*{{{*/ WeixClient::getInstance()->updateSubscribe($weixUser->id, WeixUser::WEIXIN_STATUS_UNSUB); }/*}}}*/ if(WeixApi::isEventMsg($MsgType) && WeixApi::isSubscribe($Event)) {/*{{{*/ $sceneId = str_replace('qrscene_', '', $EventKey); if($weixUser->isNull()) { $weixUserId = WeixClient::getInstance()->createWeixUser((string)$FromUserName, WeixUser::WEIXINTYPE_SPACE); $weixUser = DAL::get()->find('WeixUser', $weixUserId); } else { WeixClient::getInstance()->updateSubscribe($weixUser->id, WeixUser::WEIXIN_STATUS_SUB); } $echoStr = ''; if(!$sceneId) { $echoStr = WeixApi::xiangyingNewsMsg($FromUserName, $Event, $FromUserName, 0, false, WeixUser::WEIXINTYPE_SPACE); } else { $doctorscene = DAL::get()->find_by_sceneid('WeixDoctorQrcodeScene', $sceneId); $echoStr = WeixApi::xiangyingNewsMsg($FromUserName, $Event, $FromUserName, $doctorscene->spaceId, false, WeixUser::WEIXINTYPE_SPACE); } echo $echoStr; exit; }/*}}}*/ if(WeixApi::isEventMsg($MsgType) && WeixApi::isScan($Event)) {/*{{{*/ $sceneId = $EventKey; if($weixUser->isNull()) { $weixUserId = WeixClient::getInstance()->createWeixUser((string)$FromUserName, WeixUser::WEIXINTYPE_SPACE); $weixUser = DAL::get()->find('WeixUser', $weixUserId); } else { WeixClient::getInstance()->updateSubscribe($weixUser->id, WeixUser::WEIXIN_STATUS_SUB); } $echoStr = ''; if(!$sceneId) { $echoStr = WeixApi::xiangyingNewsMsg($FromUserName, $Event, $FromUserName, 0, false, WeixUser::WEIXINTYPE_SPACE); } else { $doctorscene = DAL::get()->find_by_sceneid('WeixDoctorQrcodeScene', $sceneId); $echoStr = WeixApi::xiangyingNewsMsg($FromUserName, $Event, $FromUserName, $doctorscene->spaceId, false, WeixUser::WEIXINTYPE_SPACE); } echo $echoStr; exit; }/*}}}*/ if(WeixApi::isEventMsg($MsgType) && $EventKey == 'contactkefu') {/*{{{*/ $str = SpaceWeixMessage::sendMsg4ContactUs(); echo WeixApi::formatXiangyingTextMsg($FromUserName, $str, $weixintype); exit; }/*}}}*/ if(WeixApi::isEventMsg($MsgType) && $EventKey == 'everydayinfo') {/*{{{*/ $space = $weixUser->getSpace(); if($space->isNull()) { $str = SpaceWeixMessage::getCommonMsg(); } else { $msg = new SpaceWeixMessage($space); $str = $msg->sendMsg4DailySummary(); } $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; }/*}}}*/ if(WeixApi::isEventMsg($MsgType) && $EventKey == 'patientsignin') {/*{{{*/ $space = $weixUser->getSpace(); if($space->isNull()) { $str = SpaceWeixMessage::getCommonMsg(); } else { $msg = new SpaceWeixMessage($space); $str = $msg-> sendMsg4PatientSignin(); } $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; }/*}}}*/ if(WeixApi::isEventMsg($MsgType) && $EventKey == 'toworktip') {/*{{{*/ $space = $weixUser->getSpace(); if($space->isNull()) { $str = SpaceWeixMessage::getCommonMsg(); $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; } $proposalCnt = $this->getUnRepliedProposalCount($weixUser); $str = "处理完成全部新患者咨询 ------------------------ <a href=\"http://a.app.qq.com/o/simple.jsp?pkgname=com.haodf.android.doctor\">下载App</a>可以查看与处理之前与患者交流的内容,尽享更多高级功能。"; $echoStr = WeixApi::formatXiangyingTextMsg($FromUserName, $str, $weixintype); if($proposalCnt > 0) { $weixDealingProposal = $this->getDealingProposal($weixUser->id); if(false == $weixDealingProposal->isNull()) { $goto = 1; } $echoStr = WeixApi::xiangyingNewsMsg($FromUserName, $EventKey, $FromUserName, 0, false, WeixUser::WEIXINTYPE_SPACE); } if(isset($goto)) { $MsgType = 'text'; $Content = '1'; } else { echo $echoStr; exit; } }/*}}}*/ if(WeixApi::isCommonMsg($MsgType)) {/*{{{*/ if(WeixApi::isTextMsg($MsgType) && $Content == '1') {/*{{{*/ $space = $weixUser->getSpace(); if($space->isNull()) { $str = SpaceWeixMessage::getCommonMsg(); $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; } $weixDealingProposal = $this->getDealingProposal($weixUser->id); if(false == $weixDealingProposal->isNull()) { $weixMsgIds = DAL::get()->query_by_weixuserid_and_status("WeixMsg", $weixUser->id, WeixMsg::WEIXMSG_STATUS_INIT); if(empty($weixMsgIds)) { echo $this->getDealWrongMsg($FromUserName, $weixDealingProposal); exit; } $this->submitReplay($weixUser, $weixDealingProposal, $weixMsgIds); } $proposal = $this->getFirstRepliedProposal($weixUser); if($proposal->isNull()) { $this->echoKefuDoneMsg($FromUserName, $weixintype); exit; } $newDealingProposalId = WeixClient::getInstance()->createWeixDealingProposal($weixUser, $proposal->id); $newDealingProposal = DAL::get()->find("WeixDealingProposal", $newDealingProposalId); if($newDealingProposal->isNull()) { $this->echoCommonMsg($postObj, $FromUserName, $weixintype); exit; } ProposalClient::getInstance()->markRead($proposal); $this->pushProposal($proposal, $FromUserName); exit; }/*}}}*/ else if(WeixApi::isTextMsg($MsgType) && $Content == '2') {/*{{{*/ $space = $weixUser->getSpace(); if($space->isNull()) { $str = SpaceWeixMessage::getCommonMsg(); $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; } $weixDealingProposal = $this->getDealingProposal($weixUser->id); if(false == $weixDealingProposal->isNull()) { $this->unDispatchPost($weixUser, $weixDealingProposal->proposalId); WeixClient::getInstance()->finishDealingProposal($weixUser->id, $weixDealingProposal->proposalId); $this->echoUndispatchMsg($weixDealingProposal->proposalId, $weixUser, $weixintype); exit; } else { $this->echoCommonMsg($postObj, $FromUserName, $weixintype); exit; } }/*}}}*/ else if(WeixApi::isTextMsg($MsgType) && $Content == '3') {/*{{{*/ $space = $weixUser->getSpace(); if($space->isNull()) { $str = SpaceWeixMessage::getCommonMsg(); $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; } $weixDealingProposal = $this->getDealingProposal($weixUser->id); $weixMsgIds = DAL::get()->query_by_weixuserid_and_status("WeixMsg", $weixUser->id, WeixMsg::WEIXMSG_STATUS_INIT); if(false == $weixDealingProposal->isNull() && !empty($weixMsgIds)) { $this->submitReplay($weixUser, $weixDealingProposal, $weixMsgIds); } else { WeixClient::getInstance()->stopDealingProposal($weixUser->id, $weixDealingProposal->proposalId); } $this->echoStopWorkMsg($weixUser, $FromUserName, $weixintype); exit; }/*}}}*/ else if(WeixApi::isVoiceMsg($MsgType)) {/*{{{*/ $space = $weixUser->getSpace(); if($space->isNull()) { $str = SpaceWeixMessage::getCommonMsg(); $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; } $weixDealingProposal = $this->getDealingProposal($weixUser->id); if(false == $weixDealingProposal->isNull()) { $dealingVoiceMsg = $this->getDealingVoiceMsg($FromUserName); $proposal = DAL::get()->find('Proposal', $weixDealingProposal->proposalId); $str = "回复内容已发送给" . $proposal->patient->userName; if(false == $dealingVoiceMsg->isNull()) { $str = "目前不支持多次回复语音消息"; $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; } $wxMsg = $this->saveCommonMsg($postObj, $weixintype); if($wxMsg->isNull()) exit; $str .= $this->getReturnPostFixMsg(); $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; } else { $this->echoCommonMsg($postObj, $FromUserName, $weixintype); } }/*}}}*/ else if(WeixApi::isTextMsg($MsgType) || WeixApi::isImageMsg($MsgType)) {/*{{{*/ $space = $weixUser->getSpace(); if($space->isNull()) { $str = SpaceWeixMessage::getCommonMsg(); $this->xiangyingTextMsg($FromUserName, $str, $weixintype); exit; } $weixDealingProposal = $this->getDealingProposal($weixUser->id); if(false == $weixDealingProposal->isNull()) { $wxMsg = $this->saveCommonMsg($postObj, $weixintype); if($wxMsg->isNull()) exit; $this->pushDealSuccessMsg($weixUser, $weixDealingProposal, $weixintype); exit; } else { $this->echoCommonMsg($postObj, $FromUserName, $weixintype); } }/*}}}*/ else {/*{{{*/ $this->echoCommonMsg($postObj, $FromUserName, $weixintype); }/*}}}*/ }/*}}}*/ }else { echo mb_convert_encoding("你啥也没说", 'utf-8','auto'); } exit; }/*}}}*/