小編給大家分享一下PHP中微信公眾平臺企業(yè)號驗證接口的示例分析,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
創(chuàng)新互聯(lián)-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價比扶余網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫,直接使用。一站式扶余網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋扶余地區(qū)。費用合理售后完善,10多年實體公司更值得信賴。具體如下:
微信公眾平臺企業(yè)號驗證接口、回調(diào) PHP版,本人為了解決這個企業(yè)號的驗證和發(fā)送消息的問題,整整研究了幾天時間,因為微信企業(yè)號剛推出來的時候網(wǎng)上資料比較少!后來在一些朋友的幫助下和本人反復(fù)調(diào)試完善下,終于整理得到了比較理想的文檔,經(jīng)親測,實驗成功。
include_once "WXBizMsgCrypt.php"; // 第三方發(fā)送消息給公眾平臺 $encodingAesKey = "rpJmhCphnndiCLIcNKcUmhTn2GQBNjISPU9GfsfOlxx"; $token = "xxxxxxx"; $corpId ="wxa9a0031f24631f9x"; //這里已正確填寫自己的corpid //公眾號服務(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:查看smg print($sEncryptMsg); } else { print($errCode . "\n\n"); } } else { print($errCode . "\n\n"); } ?>
以上是“PHP中微信公眾平臺企業(yè)號驗證接口的示例分析”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道!
分享文章:PHP中微信公眾平臺企業(yè)號驗證接口的示例分析-創(chuàng)新互聯(lián)
標題鏈接:http://muchs.cn/article4/coeeoe.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、靜態(tài)網(wǎng)站、網(wǎng)站排名、手機網(wǎng)站建設(shè)、定制開發(fā)、做網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)