mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2026-09-04 15:04:32 +08:00
fix: 增加参数检测及处理
This commit is contained in:
parent
d923c00feb
commit
550c2def40
@ -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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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'])) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user