From 3268e19c61bf151a42a28d7f6b40c27faf993c5e Mon Sep 17 00:00:00 2001 From: Anyon Date: Wed, 11 Mar 2020 10:04:31 +0800 Subject: [PATCH] Update BasicAliPay.php --- WeChat/Contracts/BasicAliPay.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/WeChat/Contracts/BasicAliPay.php b/WeChat/Contracts/BasicAliPay.php index 468b03a..4532cc6 100644 --- a/WeChat/Contracts/BasicAliPay.php +++ b/WeChat/Contracts/BasicAliPay.php @@ -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 需要进行签名数据