推送component_verify_ticket

本文介绍了一个使用PHP实现的微信公众号消息加解密示例代码。该示例展示了如何利用wxBizMsgCrypt类对接收到的加密消息进行解密,并处理来自微信公众号平台的消息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


include_once "wxBizMsgCrypt.php";

// 第三方发送消息给公众平台
$encodingAesKey = "";
$token = "";
$timeStamp = $_GET['timestamp']  ;
$nonce = $_GET['nonce']  ;
$appId = "";
$encryptMsg = file_get_contents ( 'php://input' );


$pc = new WXBizMsgCrypt($token, $encodingAesKey, $appId);

$xml_tree = new DOMDocument();
$xml_tree->loadXML($encryptMsg);
$array_e = $xml_tree->getElementsByTagName('Encrypt');
$array_s = $xml_tree->getElementsByTagName('MsgSignature');
$encrypt = $array_e->item(0)->nodeValue;
$msg_sign = $array_s->item(0)->nodeValue;
$msg_sign = "a2ed9139898089365ede396ef797d866aedecbb8";


$format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%s]]></Encrypt></xml>";
$from_xml = sprintf($format, $encrypt);

// 第三方收到公众号平台发送的消息
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $from_xml, $msg);

if ($errCode == 0) {
    print("解密后: " . $msg . "\n");
} else {
    print($errCode . "\n");
}

$xml = new DOMDocument();
$xml->loadXML($msg);
$array_e = $xml->getElementsByTagName('ComponentVerifyTicket');
echo $encrypt = $array_e->item(0)->nodeValue;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值