工具型应用订购对接流程–订购消息解密
class Aes
{
protected $encryptedMsg; //加密消息
protected $secret; //应用App Secret
/**
* Aes constructor.
* @param $msg
* @param $secret
*/
public function __construct($msg, $secret)
{
$this->encryptedMsg = $msg;
$this->secret = $secret;
}
/**
* 阿里云产品优惠领取链接
* https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=50kjssue
* @return string
*/
function AesDecrypt()
{
$key = preg_replace('#-#', '', $this->secret);
return $this->decryptMsg($this->encryptedMsg, $key);
}
/**
* @param $msg
* @param $key
* @return string
*/
public function decryptMsg($msg, $key)
{
$msg = base64_decode($msg);
$iv = substr($key, 0, 16);
return openssl_decrypt($msg, 'AES256', $key, OPENSSL_RAW_DATA, $iv);
}
注意: 如果PHP缺少扩展OpenSSL或者其他扩展需要自行安装