PHP實作微信公眾平台企業號驗證接口

不言
發布: 2023-04-01 16:14:02
原創
2531 人瀏覽過

這篇文章主要介紹了PHP程式設計之微信公眾平台企業號驗證介面,是透過回呼操作實現的企業號驗證功能介面,需要的朋友可以參考下

本文實例講述了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(&#39;smg_response.txt&#39;, $sEncryptMsg); //debug:查看smg
print($sEncryptMsg);
} else {
print($errCode . "\n\n");
}
} else {
print($errCode . "\n\n");
}
?>
登入後複製

以上就是本文的全部內容,希望對大家的學習有所幫助,更多相關內容請關注PHP中文網!

相關推薦:

如何用PHP程式碼實作微信跳一跳

#如何使用php動態產生版權所有信息的方法

#

以上是PHP實作微信公眾平台企業號驗證接口的詳細內容。更多資訊請關注PHP中文網其他相關文章!

相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
作者最新文章
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!