This article describes the PHP WeChat public platform enterprise account verification interface. Share it for your reference, as follows:
WeChat public platform enterprise account verification interface, callback PHP version, in order to solve the problem of verification and sending messages, I have studied it for a few days, because when the WeChat enterprise account was first launched, there was less information online! Later, with the help of some friends and I repeated debugging and improvement, I finally sorted out the relatively ideal document. After personal testing, the experiment was successful.
include_once ""; // A third party sends messages to the public platform$encodingAesKey = "rpJmhCphnndiCLIcNKcUmhTn2GQBNjISPU9GfsfOlxx"; $token = "xxxxxxx"; $corpId ="wxa9a0031f24631f9x"; //I have filled in my corpid correctly here//Official account server data$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 = ""; //The plain text after analysis$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 "Jack Ma": $mycontent="Hello, Jack Ma! I know you created Alibaba!"; break; case "Ma Huateng": $mycontent="Hello, Ma Huateng! I know that the Penguin Empire was created!"; break; case "Shi Yuzhu": $mycontent="Hello, Shi Yuzhu! I know you created the Giant Network!"; break; default : $mycontent="Who are you?! Go cool down!"; break; } $sRespData = "<xml> <ToUserName><![CDATA[".$reqFromUserName."]]></ToUserName> <FromUserName><![CDATA[".$corpId."]]></FromUserName> <CreateTime>".sReqTimeStamp."</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[".$mycontent."]]></Content> </xml>"; $sEncryptMsg = ""; // ciphertext in xml format$errCode = $wxcpt->EncryptMsg($sRespData, $sReqTimeStamp, $sReqNonce, $sEncryptMsg); if ($errCode == 0) { //file_put_contents('smg_response.txt', $sEncryptMsg); //debug: View smgprint($sEncryptMsg); } else { print($errCode . "\n\n"); } } else { print($errCode . "\n\n"); } ?>
Attached:Files click hereDownload this site。
For more information about PHP related content, please check out the topic of this site:Summary of PHP WeChat development skills》、《Summary of PHP encoding and transcoding operation techniques》、《Summary of PHP network programming skills》、《Summary of usage of php strings》、《Summary of data operation techniques for json format in PHP"and"Summary of PHP's XML file operation skills》
I hope this article will be helpful to everyone's PHP programming.