Skip to content

Commit

Permalink
Merge pull request #251 from justmd5/master
Browse files Browse the repository at this point in the history
fix #236 释放释放密钥资源
  • Loading branch information
yansongda committed Jun 14, 2019
2 parents 1948e30 + e54001c commit d263105
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions composer.json
Expand Up @@ -17,6 +17,8 @@
"php": ">=7.0",
"ext-openssl": "*",
"ext-simplexml":"*",
"ext-libxml": "*",
"ext-json": "*",
"yansongda/supports": "^1.8",
"monolog/monolog": "^1.23",
"symfony/http-foundation": "^3.0|^4.0",
Expand Down
12 changes: 11 additions & 1 deletion src/Gateways/Alipay/Support.php
Expand Up @@ -171,6 +171,10 @@ public static function generateSign(array $params): string

Log::debug('Alipay Generate Sign', [$params, $sign]);

if (is_resource($privateKey)) {
openssl_free_key($privateKey);
}

return $sign;
}

Expand Down Expand Up @@ -208,7 +212,13 @@ public static function verifySign(array $data, $sync = false, $sign = null): boo
$toVerify = $sync ? mb_convert_encoding(json_encode($data, JSON_UNESCAPED_UNICODE), 'gb2312', 'utf-8') :
self::getSignContent($data, true);

return openssl_verify($toVerify, base64_decode($sign), $publicKey, OPENSSL_ALGO_SHA256) === 1;
$isVerify = openssl_verify($toVerify, base64_decode($sign), $publicKey, OPENSSL_ALGO_SHA256) === 1;

if (is_resource($publicKey)) {
openssl_free_key($publicKey);
}

return $isVerify;
}

/**
Expand Down

0 comments on commit d263105

Please sign in to comment.