Files
liche/www/wxpay/index.php
T
2021-08-13 10:56:24 +08:00

30 lines
1.1 KiB
PHP

<?php
require_once "AesUtil.php";
$data = isset($_POST) ? $_POST : ''; //原样推送微信数据过来
$resource = isset($data['resource']) ? $data['resource'] : '';
$nonceStr = isset($resource['nonce']) ? $resource['nonce'] : '';
$associatedData = isset($resource['associated_data']) ? $resource['associated_data'] : '';
$ciphertext = isset($resource['ciphertext']) ? $resource['ciphertext'] : '';
$aesKey = '056afb568e28468defe86dd0102f8d33';
$req = ['code'=> 0,'msg'=> ''];
if(!$resource || !$nonceStr || !$associatedData || !$ciphertext){
$req['msg'] = '参数错误';
die(json_encode($req,JSON_UNESCAPED_UNICODE));
}
$AesUtil = new AesUtil($aesKey);
try {
$result = $AesUtil->decryptToString($associatedData,$nonceStr,$ciphertext);
if($result){
$req['code'] = 1;
$req['data'] = json_decode($result);
$req['msg'] = '解密成功';
die(json_encode($req,JSON_UNESCAPED_UNICODE));
}else{
$req['msg'] = '解密失败';
die(json_encode($req,JSON_UNESCAPED_UNICODE));
}
} catch (Exception $e) {
$req['msg'] = $e->getMessage();
die(json_encode($req,JSON_UNESCAPED_UNICODE));
}