This commit is contained in:
xl
2023-11-14 00:06:57 +08:00
parent d64ffe4b07
commit c97302ae76
6 changed files with 147 additions and 34 deletions
+10 -5
View File
@@ -21,12 +21,17 @@ class TransferBatches extends SmallProgram
#[ArrayShape([])]
public function request(TransferDetail $detail): array
{
$body = [];
$body['appid'] = $this->getConfig()->getAppid();
$payConfig = $this->getPayConfig();
$body = [];
if ($payConfig->typeIsApp()) {
$body['appid'] = $payConfig->pay->wx->appId;
} else {
$body['appid'] = $payConfig->appId;
}
$body['out_batch_no'] = $detail->out_detail_no;
$body["batch_name"] = $this->getConfig()->getBody();
$body["body"] = $this->getConfig()->getBody();
$body["batch_remark"] = $this->getConfig()->getBody();
$body["batch_name"] = $payConfig->getBody();
$body["body"] = $payConfig->getBody();
$body["batch_remark"] = $payConfig->getBody();
$body["total_amount"] = $detail->transfer_amount;
$body["total_num"] = 1;
$body["transfer_detail_list"] = [$detail->toArray()];
+2 -2
View File
@@ -54,7 +54,7 @@ class WxV3PaymentNotify extends SmallProgram
*/
public function verify(RequestInterface $request): bool
{
$platformPublicKeyInstance = $this->rsaFrom($this->payConfig->wx->mchKey, KEY_TYPE_PUBLIC);
$platformPublicKeyInstance = $this->rsaFrom($this->payConfig->pay->wx->mchKey, KEY_TYPE_PUBLIC);
$inWechatpaySignature = $request->getHeaderLine('Wechatpay-Signature'); // 请根据实际情况获取
$inWechatpayTimestamp = $request->getHeaderLine('Wechatpay-Timestamp'); // 请根据实际情况获取
$inWechatpayNonce = $request->getHeaderLine('Wechatpay-Nonce'); // 请根据实际情况获取
@@ -127,7 +127,7 @@ class WxV3PaymentNotify extends SmallProgram
*/
public function decode($ciphertext, $nonce, $associated_data): bool
{
$data = $this->decrypt($ciphertext, $this->payConfig->wx->secret, $nonce, $associated_data);
$data = $this->decrypt($ciphertext, $this->payConfig->pay->wx->secret, $nonce, $associated_data);
$this->notifyModel = new NotifyModel();
$this->notifyModel->amount = $data['amount'];
$this->notifyModel->payer = $data['payer'];
+16 -9
View File
@@ -44,12 +44,17 @@ trait WxV3PaymentTait
*/
public function getInitCore($orderNo, $total): array
{
$body['appid'] = $this->getConfig()->getAppid();
$body['mchid'] = $this->getConfig()->getMchId();
$body['description'] = $this->getConfig()->getBody();
$payConfig = $this->getPayConfig();
if ($payConfig->typeIsApp()) {
$body['appid'] = $payConfig->pay->wx->appId;
} else {
$body['appid'] = $payConfig->appId;
}
$body['mchid'] = $payConfig->pay->wx->mchId;
$body['description'] = $payConfig->getBody();
$body['out_trade_no'] = $orderNo;
$body['notify_url'] = $this->getConfig()->getNotifyUrl();
$body['amount'] = ['total' => $total, 'currency' => 'CNY'];
$body['notify_url'] = $payConfig->getNotifyUrl();
$body['amount'] = ['total' => $total, 'currency' => $payConfig->getCurrency()];
return $body;
}
@@ -84,6 +89,8 @@ trait WxV3PaymentTait
*/
public function signature(string $http_method, string $canonical_url, string $body = ''): string
{
$payConfig = $this->getPayConfig();
$rand = md5(random_bytes(32));
$time = time();
@@ -91,8 +98,8 @@ trait WxV3PaymentTait
$sign = $this->openssl_signature($message);
return sprintf('%s mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $this->getConfig()->getSchema(),
$this->getConfig()->getMchId(), $rand, $time, $this->getConfig()->getSerialNo(), $sign);
return sprintf('%s mchid="%s",nonce_str="%s",timestamp="%d",serial_no="%s",signature="%s"', $payConfig->pay->wx->schema,
$payConfig->pay->wx->mchId, $rand, $time, $payConfig->pay->wx->SerialNumber, $sign);
}
@@ -102,9 +109,9 @@ trait WxV3PaymentTait
*/
public function openssl_signature($body): string
{
$pem = file_get_contents($this->getConfig()->getMchKey());
$payConfig = $this->getPayConfig();
$mch_private_key = openssl_get_privatekey($pem);
$mch_private_key = openssl_get_privatekey($payConfig->pay->wx->mchKey);
openssl_sign($body, $raw_sign, $mch_private_key, 'sha256WithRSAEncryption');
return base64_encode($raw_sign);