use org\Wechat;
//加密参数获取
$timestamp = input('get.timestamp');
$nonce = input('get.nonce');
$msg_signature = input('get.msg_signature');
$encrypt_type = input('get.encrypt_type');
//获取微信发送数据
$postStr = $this->decryption($msg_signature,$timestamp,$nonce,$GLOBALS["HTTP_RAW_POST_DATA"]);
//解密
public function decryption($msg_sign,$timeStamp,$nonce,$text)
{
$pc = new Wechat(config("token"), config("encodingAesKey"), config("appId"));
// 第三方收到公众号平台发送的消息
$msg = '';
$errCode = $pc->decryptMsg($msg_sign, $timeStamp, $nonce, $text, $msg);
if ($errCode == 0) {
return $msg;
} else {
return $errCode;
}
}
//加密
public function encrypting($timeStamp, $nonce,$text)
{
$pc = new Wechat(config("token"), config("encodingAesKey"), config("appId"));
$encryptMsg = '';
$errCode = $pc->encryptMsg($text, $timeStamp, $nonce, $encryptMsg);
if ($errCode == 0) {
return $encryptMsg;
} else {
return $errCode;
}
}
插件包地址https://pan.baidu.com/s/1bo9ZidL
