callback
This commit is contained in:
parent
8cdfe0c4ef
commit
1f1d2d26d5
@ -60,6 +60,7 @@ class WechatPayController extends Controller
|
||||
Log::info("请求头", ["headers" => $headers]);
|
||||
Log::info("请求体", ["body" => $body]);
|
||||
$res = WechatPayService::mchTransferCallback($headers, $body);
|
||||
dd($res);
|
||||
if (empty($res)) {
|
||||
return $this->failure("回调失败");
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
use App\Http\Response\ResponseJson;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use WeChatPay\Builder;
|
||||
@ -10,6 +11,7 @@ use WeChatPay\Crypto\Rsa;
|
||||
|
||||
class WechatPayService
|
||||
{
|
||||
use ResponseJson;
|
||||
/**
|
||||
* 初始化一个APIv3客户端
|
||||
* @return void
|
||||
@ -116,13 +118,13 @@ class WechatPayService
|
||||
// Log::error('微信回调验签失败', ['headers' => $headers]);
|
||||
// return null; // 返回 500 让微信重试
|
||||
// }
|
||||
|
||||
$decryptData = $this->decryptToString($rawBody);
|
||||
// 4. 解密回调数据
|
||||
$decryptData = $this->decryptNotifyData($rawBody);
|
||||
if (!$decryptData) {
|
||||
Log::error('数据解密失败');
|
||||
return null;
|
||||
}
|
||||
// $decryptData = $this->decryptNotifyData($rawBody);
|
||||
// if (!$decryptData) {
|
||||
// Log::error('数据解密失败');
|
||||
// return null;
|
||||
// }
|
||||
|
||||
return $decryptData;
|
||||
}
|
||||
@ -218,6 +220,41 @@ class WechatPayService
|
||||
return json_decode($decrypted, true);
|
||||
}
|
||||
|
||||
public function decryptToString($data)
|
||||
{
|
||||
try {
|
||||
$resource = $data['resource'];
|
||||
$nonceStr = $resource['nonce'];
|
||||
$ciphertext = $resource['ciphertext'];
|
||||
$associatedData = $resource['associated_data'] ?? '';
|
||||
$apiV3Key = config("wechatpay.payment.api3_key");
|
||||
|
||||
$ciphertext = base64_decode($ciphertext);
|
||||
if (strlen($ciphertext) <= 16) {
|
||||
return false;
|
||||
}
|
||||
if (in_array('aes-256-gcm', openssl_get_cipher_methods())) {
|
||||
$ctext = substr($ciphertext, 0, -16);
|
||||
$authTag = substr($ciphertext, -16);
|
||||
$res = openssl_decrypt(
|
||||
$ctext,
|
||||
'aes-256-gcm',
|
||||
$apiV3Key,
|
||||
OPENSSL_RAW_DATA,
|
||||
$nonceStr,
|
||||
$authTag,
|
||||
$associatedData
|
||||
);
|
||||
return json_decode($res, true);
|
||||
}
|
||||
return null;
|
||||
} catch (Exception $e) {
|
||||
$this->getError($e);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 商家批量转账到零钱
|
||||
*/
|
||||
|
||||
Loading…
Reference in New Issue
Block a user