php 接入微信 验证,PHP实现微信公众平台企业号验证接口
這篇文章主要介紹了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"; //這里已正確填寫(xiě)自己的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 =
"
".sReqTimeStamp."
";
$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");
}
?>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,更多相關(guān)內(nèi)容請(qǐng)關(guān)注PHP中文網(wǎng)!
相關(guān)推薦:
總結(jié)
以上是生活随笔為你收集整理的php 接入微信 验证,PHP实现微信公众平台企业号验证接口的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: php实现标签云,php标签云的实现代码
- 下一篇: PHP发送数据到指定方法,php通过he