FromUserName; $ToUserName = $msgObj->ToUserName; $CreateTime = $msgObj->CreateTime; $MsgType = $msgObj->MsgType; $MsgId = $msgObj->MsgId; if ($MsgType == "text") { $TextContent = trim($msgObj->Content); if (strlen($TextContent) == 0) { $newResponse = "success"; } else { $newTextMsgHandle = new TextMsgHandle; $newTextMsgHandle->SetMsgInfo($FromUserName, $ToUserName, $CreateTime, $MsgType, $MsgId); $newTextMsgHandle->m_TextContent = $TextContent; $newResponse = $newTextMsgHandle->GetResponse(); } } elseif ($MsgType == "event") { $Event = trim($msgObj->Event); $EventKey = trim($msgObj->EventKey); $Latitude = trim($msgObj->Latitude); $Longitude = trim($msgObj->Longitude); $Precision = trim($msgObj->Precision); $Ticket = trim($msgObj->Ticket); if (!empty($Event)) { $newEventMsgHandle = new EventMsgHandle(); $newEventMsgHandle->SetMsgInfo($FromUserName, $ToUserName, $CreateTime, $MsgType, $MsgId); $newEventMsgHandle->m_Event = $Event; $newEventMsgHandle->m_EventKey = $EventKey; $newEventMsgHandle->m_Latitude = $Latitude; $newEventMsgHandle->m_Longitude = $Longitude; $newEventMsgHandle->m_Precision = $Precision; $newEventMsgHandle->m_Ticket = $Ticket; $newResponse = $newEventMsgHandle->GetResponse(); } else { $newResponse = "success"; } } elseif ($MsgType == "location") { $Location_X = trim($msgObj->Location_X); //腾讯接口里面这里X是维度,Y是经度 $Location_Y = trim($msgObj->Location_Y); $Scale = trim($msgObj->Scale); $Label = trim($msgObj->Label); if (!empty($Location_X) && !empty($Location_Y)) { $newLocationMsgHandle = new LocationMsgHandle(); $newLocationMsgHandle->SetMsgInfo($FromUserName, $ToUserName, $CreateTime, $MsgType, $MsgId); $newLocationMsgHandle->m_Location_X = $Location_X; $newLocationMsgHandle->m_Location_Y = $Location_Y; $newLocationMsgHandle->m_Scale = $Scale; $newLocationMsgHandle->m_Label = $Label; $newResponse = $newLocationMsgHandle->GetResponse(); } else { $newResponse = "success"; } } elseif ($MsgType == "image") { $PicUrl = trim($msgObj->PicUrl); $MediaId = trim($msgObj->MediaId); if(!empty($PicUrl) && !empty($MediaId)) { $picturereplytage = PictureReplyTage::model()->find('picurl="'.$PicUrl.'"'); if($picturereplytage) { if($picturereplytage->time + 30 > time()) { exit; } else { $picturereplytage->time = time(); $picturereplytage->update(); } } else { $picturereplytage = new PictureReplyTage(); $picturereplytage->picurl = $PicUrl; $picturereplytage->time = time(); $picturereplytage->save(); } $newImageMsgHandle = new ImageMsgHandle(); $newImageMsgHandle->SetMsgInfo($FromUserName, $ToUserName, $CreateTime, $MsgType, $MsgId); $newResponse = $newImageMsgHandle->GetResponse(); } else { $newResponse = "success"; } } elseif ($MsgType == "voice") { $format = trim($msgObj->Format); $MediaId = trim($msgObj->MediaId); if(!empty($format) && !empty($MediaId)) { $voicereplytage = VoiceReplyTage::model()->find('media_id="'.$MediaId.'"'); if($voicereplytage) { if($voicereplytage->time + 30 > time()) { exit; } else { $voicereplytage->time = time(); $voicereplytage->update(); } } else { $voicereplytage = new VoiceReplyTage(); $voicereplytage->media_id = $MediaId; $voicereplytage->format = $format; $voicereplytage->time = time(); $voicereplytage->save(); } $newVoiceMsgHandle = new VoiceMsgHandle(); $newVoiceMsgHandle->SetMsgInfo($FromUserName, $ToUserName, $CreateTime, $MsgType, $MsgId); $newResponse = $newVoiceMsgHandle->GetResponse(); } else { $newResponse = "success"; } } else { $newResponse = "success"; } if (!isset($newResponse)) { Yii::log("MsgType:" . $MsgType); } return $newResponse; } public static function getDecryptMsg() { $msg_signature = $_GET["msg_signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $postStr = $GLOBALS["HTTP_RAW_POST_DATA"]; $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); if ($postObj == false) { Yii::log("Parsel XML Failed!"); echo "are u kidding?"; exit(); } $encrypt = $postObj->Encrypt; $format = ""; $from_xml = sprintf($format, $encrypt); $appId = LEWAIMAI_PINGTAI_APPID; $token = LEWAIMAI_PINGTAI_TOKEN; $encodingAesKey = LEWAIMAI_PINGTAI_ENCODINGAESKEY; $pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId); //第三方收到公众号平台发送的消息 $msg = ''; $errCode = $pc->decryptMsg($msg_signature, $timestamp, $nonce, $from_xml, $msg); return $msg; } }