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
+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);