小編給大家分享一下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ā)送消息的問(wèn)題,整整研究了幾天時(shí)間,因?yàn)槲⑿牌髽I(yè)號(hào)剛推出來(lái)的時(shí)候網(wǎng)上資料比較少!后來(lái)在一些朋友的幫助下和本人反復(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)建了企鵝帝國(guó)!"; break; case "史玉柱": $mycontent="您好,史玉柱!我知道您創(chuàng)建了巨人網(wǎng)絡(luò)!"; break; default : $mycontent="你是誰(shuí)???!一邊涼快去!"; 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:查看smg print($sEncryptMsg); } else { print($errCode . "\n\n"); } } else { print($errCode . "\n\n"); } ?>
以上是“PHP中微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享文章:PHP中微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口的示例分析-創(chuàng)新互聯(lián)
標(biāo)題鏈接:http://aaarwkj.com/article4/coeeoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、網(wǎng)站排名、手機(jī)網(wǎng)站建設(shè)、定制開(kāi)發(fā)、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容