mirror of
https://gitee.com/yansongda/pay.git
synced 2024-12-03 12:48:24 +08:00
fix: 微信内网页支付供应商模式 sub_appid 非必填 (#628)
* fixed: 公众号支付供应商模式 sub_appid 非必填 * refactor: 优化代码 Co-authored-by: BranchZero Sun <branchzero@elemenx.com> Co-authored-by: yansongda <me@yansongda.cn>
This commit is contained in:
parent
cc8ad8cafa
commit
c51793e88a
@ -1,3 +1,9 @@
|
||||
## v3.1.7
|
||||
|
||||
### fixed
|
||||
|
||||
- fix: 微信内网页支付供应商模式 sub_appid 非必填(#628)
|
||||
|
||||
## v3.1.6
|
||||
|
||||
### fixed
|
||||
|
@ -4,9 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\App;
|
||||
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Config;
|
||||
|
||||
class PrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\PrepayPlugin
|
||||
{
|
||||
@ -20,22 +18,8 @@ class PrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\PrepayPlugin
|
||||
return 'v3/pay/partner/transactions/app';
|
||||
}
|
||||
|
||||
protected function getWechatId(Config $config, Rocket $rocket): array
|
||||
protected function getConfigKey(array $params): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
if (Pay::MODE_SERVICE == $config->get('mode')) {
|
||||
return [
|
||||
'sp_appid' => $config->get('app_id', ''),
|
||||
'sp_mchid' => $config->get('mch_id', ''),
|
||||
'sub_appid' => $payload->get('sub_appid', $config->get('sub_app_id')),
|
||||
'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id')),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'appid' => $config->get('app_id', ''),
|
||||
'mchid' => $config->get('mch_id', ''),
|
||||
];
|
||||
return 'app_id';
|
||||
}
|
||||
}
|
||||
|
@ -41,19 +41,31 @@ class PrepayPlugin extends GeneralPlugin
|
||||
protected function getWechatId(Config $config, Rocket $rocket): array
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
$configKey = $this->getConfigKey($rocket->getParams());
|
||||
|
||||
if (Pay::MODE_SERVICE == $config->get('mode')) {
|
||||
return [
|
||||
'sp_appid' => $config->get('mp_app_id', ''),
|
||||
'sp_mchid' => $config->get('mch_id', ''),
|
||||
'sub_appid' => $payload->get('sub_appid', $config->get('sub_mp_app_id')),
|
||||
'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id')),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'appid' => $config->get('mp_app_id', ''),
|
||||
$result = [
|
||||
'appid' => $config->get($configKey, ''),
|
||||
'mchid' => $config->get('mch_id', ''),
|
||||
];
|
||||
|
||||
if (Pay::MODE_SERVICE == $config->get('mode')) {
|
||||
$result = [
|
||||
'sp_appid' => $config->get($configKey, ''),
|
||||
'sp_mchid' => $config->get('mch_id', ''),
|
||||
'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id')),
|
||||
];
|
||||
|
||||
$subAppId = $payload->get('sub_appid', $config->get('sub_'.$configKey));
|
||||
if (!empty($subAppId)) {
|
||||
$result['sub_appid'] = $subAppId;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected function getConfigKey(array $params): string
|
||||
{
|
||||
return 'mp_app_id';
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Yansongda\Pay\Plugin\Wechat\Pay\H5;
|
||||
|
||||
use Yansongda\Pay\Pay;
|
||||
use Yansongda\Pay\Rocket;
|
||||
use Yansongda\Supports\Config;
|
||||
|
||||
class PrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\PrepayPlugin
|
||||
{
|
||||
@ -20,27 +18,13 @@ class PrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\PrepayPlugin
|
||||
return 'v3/pay/partner/transactions/h5';
|
||||
}
|
||||
|
||||
protected function getWechatId(Config $config, Rocket $rocket): array
|
||||
protected function getConfigKey(array $params): string
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
|
||||
$key = ($rocket->getParams()['_type'] ?? 'mp').'_app_id';
|
||||
$key = ($params['_type'] ?? 'mp').'_app_id';
|
||||
if ('app_app_id' === $key) {
|
||||
$key = 'app_id';
|
||||
}
|
||||
|
||||
if (Pay::MODE_SERVICE == $config->get('mode')) {
|
||||
return [
|
||||
'sp_appid' => $config->get($key, ''),
|
||||
'sp_mchid' => $config->get('mch_id', ''),
|
||||
'sub_appid' => $payload->get('sub_appid', $config->get('sub_'.$key)),
|
||||
'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id')),
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'appid' => $config->get($key, ''),
|
||||
'mchid' => $config->get('mch_id', ''),
|
||||
];
|
||||
return $key;
|
||||
}
|
||||
}
|
||||
|
@ -12,26 +12,17 @@ class PrepayPlugin extends \Yansongda\Pay\Plugin\Wechat\Pay\Common\PrepayPlugin
|
||||
{
|
||||
protected function getWechatId(Config $config, Rocket $rocket): array
|
||||
{
|
||||
$payload = $rocket->getPayload();
|
||||
$wechatId = parent::getWechatId($config, $rocket);
|
||||
|
||||
$result = [
|
||||
'appid' => $config->get('mini_app_id', ''),
|
||||
'mchid' => $config->get('mch_id', ''),
|
||||
];
|
||||
|
||||
if (Pay::MODE_SERVICE == $config->get('mode')) {
|
||||
$result = [
|
||||
'sp_appid' => $config->get('mini_app_id', $config->get('mp_app_id', '')),
|
||||
'sp_mchid' => $config->get('mch_id', ''),
|
||||
'sub_mchid' => $payload->get('sub_mchid', $config->get('sub_mch_id')),
|
||||
];
|
||||
|
||||
$subAppId = $payload->get('sub_appid', $config->get('sub_mini_app_id'));
|
||||
if (!empty($subAppId)) {
|
||||
$result['sub_appid'] = $subAppId;
|
||||
}
|
||||
if (Pay::MODE_SERVICE == $config->get('mode') && empty($wechatId['sp_appid'])) {
|
||||
$wechatId['sp_appid'] = $config->get('mp_app_id', '');
|
||||
}
|
||||
|
||||
return $result;
|
||||
return $wechatId;
|
||||
}
|
||||
|
||||
protected function getConfigKey(array $params): string
|
||||
{
|
||||
return 'mini_app_id';
|
||||
}
|
||||
}
|
||||
|
@ -81,4 +81,17 @@ class PrepayPluginTest extends TestCase
|
||||
self::assertEquals('123', $payload->get('sub_appid'));
|
||||
self::assertEquals('1600314070', $payload->get('sub_mchid'));
|
||||
}
|
||||
|
||||
public function testPartnerDirectPayloadWithoutSubAppId()
|
||||
{
|
||||
$rocket = new Rocket();
|
||||
$rocket->setParams(['_config' => 'service_provider4'])->setPayload(new Collection());
|
||||
|
||||
$result = $this->plugin->assembly($rocket, function ($rocket) { return $rocket; });
|
||||
|
||||
$payload = $result->getPayload();
|
||||
|
||||
self::assertArrayNotHasKey('sub_appid', $payload->all());
|
||||
self::assertEquals('1600314070', $payload->get('sub_mchid'));
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,22 @@ class TestCase extends \PHPUnit\Framework\TestCase
|
||||
'sub_mch_id' => '1600314072',
|
||||
'mode' => Pay::MODE_SERVICE,
|
||||
],
|
||||
'service_provider4' => [
|
||||
'mp_app_id' => 'wx55955316af4ef13',
|
||||
'mch_id' => '1600314069',
|
||||
'mini_app_id' => 'wx55955316af4ef14',
|
||||
'mch_secret_key' => '53D67FCB97E68F9998CBD17ED7A8D1E2',
|
||||
'mch_secret_cert' => __DIR__.'/Cert/wechatAppPrivateKey.pem',
|
||||
'mch_public_cert_path' => __DIR__.'/Cert/wechatAppPublicKey.pem',
|
||||
'wechat_public_cert_path' => [
|
||||
'45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__.'/Cert/wechatPublicKey.crt',
|
||||
],
|
||||
'sub_mp_app_id' => '',
|
||||
'sub_app_id' => 'wx55955316af4ef16',
|
||||
'sub_mini_app_id' => 'wx55955316af4ef17',
|
||||
'sub_mch_id' => '1600314070',
|
||||
'mode' => Pay::MODE_SERVICE,
|
||||
],
|
||||
'empty_wechat_public_cert' => [
|
||||
'app_id' => 'yansongda',
|
||||
'mp_app_id' => 'wx55955316af4ef13',
|
||||
|
Loading…
Reference in New Issue
Block a user