Update BasicAliPay.php

This commit is contained in:
Anyon 2020-03-11 10:04:31 +08:00
parent 9dbabfe89e
commit 3268e19c61

View File

@ -198,7 +198,7 @@ abstract class BasicAliPay
*/
protected function getSign()
{
$content = wordwrap($this->config->get('private_key'), 64, "\n", true);
$content = wordwrap($this->trimCert($this->config->get('private_key')), 64, "\n", true);
$string = "-----BEGIN RSA PRIVATE KEY-----\n{$content}\n-----END RSA PRIVATE KEY-----";
if ($this->options->get('sign_type') === 'RSA2') {
openssl_sign($this->getSignContent($this->options->get(), true), $sign, $string, OPENSSL_ALGO_SHA256);
@ -208,6 +208,17 @@ abstract class BasicAliPay
return base64_encode($sign);
}
/**
* 去除证书前后内容及空白
* @param string $sign
* @return string
*/
protected function trimCert($sign)
{
if (file_exists($sign)) $sign = file_get_contents($sign);
return preg_replace(['/\s+/', '/\-{5}.*?\-{5}/'], '', $sign);
}
/**
* 数据签名处理
* @param array $data 需要进行签名数据