本文實例講述了PHP微信公眾平臺企業號驗證接口。分享給大家供大家參考,具體如下:
微信公眾平臺企業號驗證接口、回調 PHP版,本人為了解決這個企業號的驗證和發送消息的問題,整整研究了幾天時間,因為微信企業號剛推出來的時候網上資料比較少!后來在一些朋友的幫助下和本人反復調試完善下,終于整理得到了比較理想的文檔,經親測,實驗成功。
include_once WXBizMsgCrypt.php // 第三方發送消息給公眾平臺$encodingAesKey = rpJmhCphnndiCLIcNKcUmhTn2GQBNjISPU9GfsfOlxx $token = xxxxxxx $corpId = wxa9a0031f24631f9x //這里已正確填寫自己的corpid//公眾號服務器數據$sReqMsgSig = $sVerifyMsgSig = $_GET[ msg_signature $sReqTimeStamp = $sVerifyTimeStamp = $_GET[ timestamp $sReqNonce = $sVerifyNonce = $_GET[ nonce $sReqData = file_get_contents( php://input ;$sVerifyEchoStr = $_GET[ echostr $wxcpt = new WXBizMsgCrypt($token, $encodingAesKey, $corpId);if($sVerifyEchoStr){$sEchoStr = $errCode = $wxcpt- VerifyURL($sVerifyMsgSig, $sVerifyTimeStamp, $sVerifyNonce, $sVerifyEchoStr, $sEchoStr);if ($errCode == 0) {print($sEchoStr);} else {print($errCode . /n/n exit;//decrypt$sMsg = //解析之后的明文$errCode = $wxcpt- DecryptMsg($sReqMsgSig, $sReqTimeStamp, $sReqNonce, $sReqData, $sMsg);if ($errCode == 0) {$xml = new DOMDocument();$xml- loadXML($sMsg);$reqToUserName = $xml- getElementsByTagName( ToUserName )- item(0)- nodeValue;$reqFromUserName = $xml- getElementsByTagName( FromUserName )- item(0)- nodeValue;$reqCreateTime = $xml- getElementsByTagName( CreateTime )- item(0)- nodeValue;$reqMsgType = $xml- getElementsByTagName( MsgType )- item(0)- nodeValue;$reqContent = $xml- getElementsByTagName( Content )- item(0)- nodeValue;$reqMsgId = $xml- getElementsByTagName( MsgId )- item(0)- nodeValue;$reqAgentID = $xml- getElementsByTagName( AgentID )- item(0)- nodeValue;switch($reqContent){case 馬云 :$mycontent= 您好,馬云!我知道您創建了阿里巴巴! break;case 馬化騰 :$mycontent= 您好,馬化騰!我知道創建了企鵝帝國! break;case 史玉柱 :$mycontent= 您好,史玉柱!我知道您創建了巨人網絡! break;default :$mycontent= 你是誰啊?!一邊涼快去! break;$sRespData = xml ToUserName ![CDATA[ .$reqFromUserName. ]] /ToUserName FromUserName ![CDATA[ .$corpId. ]] /FromUserName CreateTime .sReqTimeStamp. /CreateTime MsgType ![CDATA[text]] /MsgType Content ![CDATA[ .$mycontent. ]] /Content /xml $sEncryptMsg = //xml格式的密文$errCode = $wxcpt- EncryptMsg($sRespData, $sReqTimeStamp, $sReqNonce, $sEncryptMsg);if ($errCode == 0) {//file_put_contents( smg_response.txt , $sEncryptMsg); //debug:查看smgprint($sEncryptMsg);} else {print($errCode . /n/n } else {print($errCode . /n/n ?
以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP !
相關推薦:
如何用PHP代碼實現微信跳一跳
如何使用php動態生成版權所有信息的方法
以上就是PHP實現微信公眾平臺企業號驗證接口的詳細內容,PHP教程
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。
新聞熱點
疑難解答