微信退款的回调中有个字段是req_info。该字段微信官方给的解密方法是:
解密步骤如下:
(1)对加密串A做base64解码,得到加密串B
(2)对商户key做md5,得到32位小写key* ( key设置路径:微信商户平台(pay.weixin.qq.com)-->账户设置-->API安全-->密钥设置 )
(3)用key*对加密串B做AES-256-ECB解密(PKCS7Padding)
解密方法如下:
WxEncrypt.php:
<?php
/**
* 微信退款回调参数解密类
* User Demo
* Data 2018-07-18
*/
namespace App\Services\Payment\wxpay;
use Exception;
class WxEncrypt {
//解密秘钥,默认应该为用户的秘钥key
private $key = '';
//加密的串
private $encStr = "";
public function __construct($str, $key) {
if (empty($str) || empty($key)) {
throw new Exception('解密参数错误!');
}
$this->encStr = base64_decode($str);
$this->key = md5($key);
}
/**
* 获取解密的串
*/
public function getDecStr() {
return $this->decrypt($this->encStr);
}
/**
* 对密文进行解密
* @param string $encrypted 需要解密的密文
* @return string 解密得到的明文
*/