本文實(shí)例講述了PHP微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口。分享給大家供大家參考,具體如下:
微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口、回調(diào) PHP版,本人為了解決這個(gè)企業(yè)號(hào)的驗(yàn)證和發(fā)送消息的問題,整整研究了幾天時(shí)間,因?yàn)槲⑿牌髽I(yè)號(hào)剛推出來的時(shí)候網(wǎng)上資料比較少!后來在一些朋友的幫助下和本人反復(fù)調(diào)試完善下,終于整理得到了比較理想的文檔,經(jīng)親測(cè),實(shí)驗(yàn)成功。
include_once WXBizMsgCrypt.php // 第三方發(fā)送消息給公眾平臺(tái)$encodingAesKey = rpJmhCphnndiCLIcNKcUmhTn2GQBNjISPU9GfsfOlxx $token = xxxxxxx $corpId = wxa9a0031f24631f9x //這里已正確填寫自己的corpid//公眾號(hào)服務(wù)器數(shù)據(jù)$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= 您好,馬云!我知道您創(chuàng)建了阿里巴巴! break;case 馬化騰 :$mycontent= 您好,馬化騰!我知道創(chuàng)建了企鵝帝國! break;case 史玉柱 :$mycontent= 您好,史玉柱!我知道您創(chuàng)建了巨人網(wǎng)絡(luò)! 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 ?
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請(qǐng)關(guān)注PHP !
相關(guān)推薦:
如何用PHP代碼實(shí)現(xiàn)微信跳一跳
如何使用php動(dòng)態(tài)生成版權(quán)所有信息的方法
以上就是PHP實(shí)現(xiàn)微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口的詳細(xì)內(nèi)容,PHP教程
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答
圖片精選