欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHP編程之微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口示例【回調(diào)操作】

 更新時(shí)間:2017年08月21日 10:40:15   作者:027099  
這篇文章主要介紹了PHP編程之微信公眾平臺(tái)企業(yè)號(hào)驗(yàn)證接口,是通過(guò)回調(diào)操作實(shí)現(xiàn)的企業(yè)號(hào)驗(yàn)證功能接口,需要的朋友可以參考下

本文實(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ā)送消息的問(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");
}
?>

附:WXBizMsgCrypt.php 文件點(diǎn)擊此處本站下載。

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP微信開(kāi)發(fā)技巧匯總》、《PHP編碼與轉(zhuǎn)碼操作技巧匯總》、《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《php字符串(string)用法總結(jié)》、《PHP中json格式數(shù)據(jù)操作技巧匯總》及《PHP針對(duì)XML文件操作技巧總結(jié)

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論