微信加密解密

浏览:2203 发布日期:2017/12/09 分类:用法示例 关键字: 微信开发, 微信消息解密,微信消息加密
tp5微信系统消息加密解密
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
评论( 相关
后面还有条评论,点击查看>>