fix: 增加参数检测及处理

This commit is contained in:
Anyon 2025-12-12 09:33:53 +08:00
parent d923c00feb
commit 550c2def40
2 changed files with 16 additions and 1 deletions

View File

@ -333,7 +333,15 @@ abstract class BasicWePay
protected function signBuild($data) protected function signBuild($data)
{ {
$pkeyid = openssl_pkey_get_private($this->config['cert_private']); $pkeyid = openssl_pkey_get_private($this->config['cert_private']);
openssl_sign($data, $signature, $pkeyid, 'sha256WithRSAEncryption'); if ($pkeyid === false) {
throw new InvalidArgumentException("Invalid private key -- [cert_private]");
}
$signature = '';
if (!openssl_sign($data, $signature, $pkeyid, 'sha256WithRSAEncryption')) {
openssl_free_key($pkeyid);
throw new InvalidArgumentException("Failed to sign data with private key");
}
openssl_free_key($pkeyid);
return base64_encode($signature); return base64_encode($signature);
} }

View File

@ -52,6 +52,13 @@ class Order extends BasicWePay
if (empty($types[$type])) { if (empty($types[$type])) {
throw new InvalidArgumentException("Payment {$type} not defined."); throw new InvalidArgumentException("Payment {$type} not defined.");
} else { } else {
// 自动填充 mchid 和 appid如果未提供
if (empty($data['mchid']) && !empty($this->config['mch_id'])) {
$data['mchid'] = $this->config['mch_id'];
}
if (empty($data['appid']) && !empty($this->config['appid'])) {
$data['appid'] = $this->config['appid'];
}
// 创建预支付码 // 创建预支付码
$result = $this->doRequest('POST', $types[$type], json_encode($data, JSON_UNESCAPED_UNICODE), true); $result = $this->doRequest('POST', $types[$type], json_encode($data, JSON_UNESCAPED_UNICODE), true);
if (empty($result['h5_url']) && empty($result['code_url']) && empty($result['prepay_id'])) { if (empty($result['h5_url']) && empty($result['code_url']) && empty($result['prepay_id'])) {