導航:首頁 > 編程語言 > 微信samplephp

微信samplephp

發布時間:2025-01-08 14:48:18

『壹』 微信企業號在thinkphp中怎麼使用

微信公眾平台企業號驗證介面、回調 PHP版,本人為了解決這個企業號的驗證和發送消息的問題,整整研究了幾天時間,因為微信企業號剛推出來,網上資料太少了!後來在一些朋友的幫助下和本人反復調試完善下,終於整理得到了比較理想的文檔,經親測,實驗成功。

include_once "WXBizMsgCrypt.php";
// 第三方發送消息給公眾平台
$encodingAesKey = "";
$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('smg_response.txt', $sEncryptMsg); //debug:查看smg
print($sEncryptMsg);
} else {
print($errCode . "\n\n");
}
} else {
print($errCode . "\n\n");
}
?>

WXBizMsgCrypt.php 文件請點擊下面地址下載 :

http://mp.weixin.qq.com/wiki/downloads/SampleCode.zip

閱讀全文

與微信samplephp相關的資料

熱點內容
怎麼查伺服器假死原因日誌在哪看 瀏覽:277
掃描pdf文件 瀏覽:926
解壓密碼百度雲在線解壓 瀏覽:767
傳播學演算法推薦 瀏覽:749
我的世界網路游戲如何查找伺服器 瀏覽:257
安卓和蘋果通訊錄怎麼互傳 瀏覽:203
怎麼打開隱私與應用加密的菜單 瀏覽:416
我的世界伺服器小游戲的地址大全 瀏覽:578
在網路安全中加密安全機制提供了數據的 瀏覽:249
南京前端程序員私活怎麼收費 瀏覽:981
拓撲pdf 瀏覽:440
如何在工行app查我的訂單 瀏覽:214
車壓縮機改電動 瀏覽:83
如何尋找音樂app 瀏覽:831
一加加密的照片 瀏覽:200
阿里雲虛擬主機php 瀏覽:639
不卡點的解壓視頻 瀏覽:391
hex文件下載單片機 瀏覽:873
實現編譯器的自展技術 瀏覽:655
app開發者怎麼突破 瀏覽:418