yansongda / pay

可能是我用过的最优雅的 Alipay/WeChat/Douyin/Unipay/江苏银行 的支付 SDK 扩展包了
http://pay.yansongda.cn
MIT License
5.06k stars 1.04k forks source link

fix: 未配置微信证书时,自动获取证书后仍然使用之前的微信配置 #1026

Closed Wsmallnews closed 2 months ago

Wsmallnews commented 2 months ago

当调用 商家转账到零钱 接口,配置中未设置 微信平台公钥证书路径 时,报错 参数异常: 微信公钥序列号为找到

经排查代码在 get_wechat_serial_no 方法中会做判断如果配置中未设置 微信平台公钥证书路径 时,会自动生成 微信平台公钥证书,并更新配置参数

但在接下来调用 get_wechat_public_key,方法获取证书时,使用的是之前获取的 config 信息,而这里面还没有包含新生成的 微信平台公钥证书,导致证书找不到报错 参数异常: 微信公钥序列号为找到

修复方式如下, 提现举例:

    protected function encryptSensitiveData(array $params, array $config, Collection $payload): array
    {
        $data['transfer_detail_list'] = $payload->get('transfer_detail_list', []);
        $data['_serial_no'] = get_wechat_serial_no($params);

        $config = get_provider_config('wechat', $params);      // 获取证书前,重新读取配置
        $publicKey = get_wechat_public_key($config, $data['_serial_no']);

        foreach ($data['transfer_detail_list'] as $key => $list) {
            if (!empty($list['user_name'])) {
                $data['transfer_detail_list'][$key]['user_name'] = encrypt_wechat_contents($list['user_name'], $publicKey);
            }
        }

        return $data;
    }
netlify[bot] commented 2 months ago

Deploy Preview for pay-yansongda canceled.

Name Link
Latest commit 68a41f37ebeb4fb9c5e3943b62e3c0079235126c
Latest deploy log https://app.netlify.com/sites/pay-yansongda/deploys/66e10d24b011f3000829ed9d
codecov[bot] commented 2 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 97.41%. Comparing base (2ea20b7) to head (68a41f3). Report is 1 commits behind head on master.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #1026 +/- ## ========================================= Coverage 97.41% 97.41% Complexity 1032 1032 ========================================= Files 374 374 Lines 6763 6768 +5 ========================================= + Hits 6588 6593 +5 Misses 175 175 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.