mirror of
https://gitee.com/zoujingli/WeChatDeveloper.git
synced 2025-06-22 06:59:16 +08:00
Pre Merge pull request !6 from 承诺/master
This commit is contained in:
commit
ef419c8c63
@ -49,13 +49,13 @@ abstract class BasicWePay
|
||||
'mch_id' => '', // 微信商户编号,需要配置
|
||||
'mch_v3_key' => '', // 微信商户密钥,需要配置
|
||||
'cert_serial' => '', // 商户证书序号,无需配置
|
||||
'cert_public' => '', // 商户公钥内容,需要配置
|
||||
'cert_private' => '', // 商户密钥内容,需要配置
|
||||
'ssl_cer' => '', // 商户公钥内容,需要配置
|
||||
'ssl_key' => '', // 商户密钥内容,需要配置
|
||||
];
|
||||
|
||||
/**
|
||||
* BasicWePayV3 constructor.
|
||||
* @param array $options [mch_id, mch_v3_key, cert_public, cert_private]
|
||||
* @param array $options [mch_id, mch_v3_key, ssl_cer, ssl_key]
|
||||
*/
|
||||
public function __construct(array $options = [])
|
||||
{
|
||||
@ -65,35 +65,35 @@ abstract class BasicWePay
|
||||
if (empty($options['mch_v3_key'])) {
|
||||
throw new InvalidArgumentException("Missing Config -- [mch_v3_key]");
|
||||
}
|
||||
if (empty($options['cert_private'])) {
|
||||
throw new InvalidArgumentException("Missing Config -- [cert_private]");
|
||||
if (empty($options['ssl_key'])) {
|
||||
throw new InvalidArgumentException("Missing Config -- [ssl_key]");
|
||||
}
|
||||
if (empty($options['cert_public'])) {
|
||||
throw new InvalidArgumentException("Missing Config -- [cert_public]");
|
||||
if (empty($options['ssl_cer'])) {
|
||||
throw new InvalidArgumentException("Missing Config -- [ssl_cer]");
|
||||
}
|
||||
|
||||
if (stripos($options['cert_public'], '-----BEGIN CERTIFICATE-----') === false) {
|
||||
if (file_exists($options['cert_public'])) {
|
||||
$options['cert_public'] = file_get_contents($options['cert_public']);
|
||||
if (stripos($options['ssl_cer'], '-----BEGIN CERTIFICATE-----') === false) {
|
||||
if (file_exists($options['ssl_cer'])) {
|
||||
$options['ssl_cer'] = file_get_contents($options['ssl_cer']);
|
||||
} else {
|
||||
throw new InvalidArgumentException("File Non-Existent -- [cert_public]");
|
||||
throw new InvalidArgumentException("File Non-Existent -- [ssl_cer]");
|
||||
}
|
||||
}
|
||||
|
||||
if (stripos($options['cert_private'], '-----BEGIN PRIVATE KEY-----') === false) {
|
||||
if (file_exists($options['cert_private'])) {
|
||||
$options['cert_private'] = file_get_contents($options['cert_private']);
|
||||
if (stripos($options['ssl_key'], '-----BEGIN PRIVATE KEY-----') === false) {
|
||||
if (file_exists($options['ssl_key'])) {
|
||||
$options['ssl_key'] = file_get_contents($options['ssl_key']);
|
||||
} else {
|
||||
throw new InvalidArgumentException("File Non-Existent -- [cert_private]");
|
||||
throw new InvalidArgumentException("File Non-Existent -- [ssl_key]");
|
||||
}
|
||||
}
|
||||
|
||||
$this->config['appid'] = isset($options['appid']) ? $options['appid'] : '';
|
||||
$this->config['mch_id'] = $options['mch_id'];
|
||||
$this->config['mch_v3_key'] = $options['mch_v3_key'];
|
||||
$this->config['cert_public'] = $options['cert_public'];
|
||||
$this->config['cert_private'] = $options['cert_private'];
|
||||
$this->config['cert_serial'] = openssl_x509_parse($this->config['cert_public'])['serialNumberHex'];
|
||||
$this->config['ssl_cer'] = $options['ssl_cer'];
|
||||
$this->config['ssl_key'] = $options['ssl_key'];
|
||||
$this->config['cert_serial'] = openssl_x509_parse($this->config['ssl_cer'])['serialNumberHex'];
|
||||
|
||||
if (empty($this->config['cert_serial'])) {
|
||||
throw new InvalidArgumentException("Failed to parse certificate public key");
|
||||
@ -194,7 +194,7 @@ abstract class BasicWePay
|
||||
*/
|
||||
protected function signBuild($data)
|
||||
{
|
||||
$pkeyid = openssl_pkey_get_private($this->config['cert_private']);
|
||||
$pkeyid = openssl_pkey_get_private($this->config['ssl_key']);
|
||||
openssl_sign($data, $signature, $pkeyid, 'sha256WithRSAEncryption');
|
||||
return base64_encode($signature);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user