fix: app 支付调起签名中时间戳参数大小写问题 (#510)

* fix: app 支付调起签名中时间戳参数大小写问题

* changelog
This commit is contained in:
yansongda 2021-11-04 12:11:13 +08:00 committed by GitHub
parent 796ce44dbc
commit 223732dbcc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 3 deletions

View File

@ -1,3 +1,9 @@
## v3.0.13
### fixed
- fixed: app 支付调起签名中时间戳参数大小写问题 (#510)
## v3.0.12
### fixed

View File

@ -5,6 +5,7 @@ declare(strict_types=1);
namespace Yansongda\Pay\Plugin\Wechat\Pay\App;
use Yansongda\Pay\Rocket;
use Yansongda\Supports\Collection;
use Yansongda\Supports\Config;
use Yansongda\Supports\Str;
@ -32,6 +33,22 @@ class InvokePrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\InvokeP
return $config;
}
/**
* @throws \Yansongda\Pay\Exception\ContainerDependencyException
* @throws \Yansongda\Pay\Exception\ContainerException
* @throws \Yansongda\Pay\Exception\InvalidConfigException
* @throws \Yansongda\Pay\Exception\ServiceNotFoundException
*/
protected function getSign(Collection $invokeConfig, array $params): string
{
$contents = $invokeConfig->get('appid', '')."\n".
$invokeConfig->get('timestamp', '')."\n".
$invokeConfig->get('nonceStr', '')."\n".
$invokeConfig->get('package', '')."\n";
return get_wechat_sign($params, $contents);
}
protected function getAppid(Rocket $rocket): string
{
$config = get_wechat_config($rocket->getParams());

View File

@ -33,7 +33,7 @@ class InvokePrepayPlugin implements PluginInterface
$prepayId = $rocket->getDestination()->get('prepay_id');
if (is_null($prepayId)) {
Logger::error('[wechat][InvokePrepayPlugin] 预下单失败:响应缺少 prepay_id 参数', $rocket->getDestination()->all());
Logger::error('[wechat][InvokePrepayPlugin] 预下单失败:响应缺少 prepay_id 参数,请自行检查参数是否符合微信要求', $rocket->getDestination()->all());
throw new InvalidResponseException(Exception::RESPONSE_MISSING_NECESSARY_PARAMS, 'Prepay Response Error: Missing PrepayId', $rocket->getDestination()->all());
}
@ -55,7 +55,7 @@ class InvokePrepayPlugin implements PluginInterface
*/
protected function getSign(Collection $invokeConfig, array $params): string
{
$contents = $invokeConfig->get('appid', $invokeConfig->get('appId'))."\n".
$contents = $invokeConfig->get('appId', '')."\n".
$invokeConfig->get('timeStamp', '')."\n".
$invokeConfig->get('nonceStr', '')."\n".
$invokeConfig->get('package', '')."\n";

View File

@ -22,5 +22,6 @@ class InvokePrepayPluginTest extends TestCase
self::assertArrayHasKey('package', $contents->all());
self::assertEquals('Sign=WXPay', $contents->get('package'));
self::assertArrayHasKey('sign', $contents->all());
self::assertArrayHasKey('timestamp', $contents->all());
}
}

View File

@ -2,6 +2,7 @@
namespace Yansongda\Pay\Tests\Plugin\Wechat\Pay\Common;
use Yansongda\Pay\Exception\Exception;
use Yansongda\Pay\Exception\InvalidResponseException;
use Yansongda\Pay\Plugin\Wechat\Pay\Common\InvokePrepayPlugin;
use Yansongda\Pay\Rocket;
@ -21,6 +22,7 @@ class InvokePrepayPluginTest extends TestCase
self::assertArrayHasKey('appId', $contents->all());
self::assertArrayHasKey('package', $contents->all());
self::assertArrayHasKey('paySign', $contents->all());
self::assertArrayHasKey('timeStamp', $contents->all());
}
public function testWrongPrepayId()
@ -28,7 +30,7 @@ class InvokePrepayPluginTest extends TestCase
$rocket = (new Rocket())->setDestination(new Collection([]));
self::expectException(InvalidResponseException::class);
self::expectExceptionCode(InvalidResponseException::RESPONSE_MISSING_NECESSARY_PARAMS);
self::expectExceptionCode(Exception::RESPONSE_MISSING_NECESSARY_PARAMS);
(new InvokePrepayPlugin())->assembly($rocket, function ($rocket) { return $rocket; });
}