GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — 【微信支付】修复公钥模式下V3接口未设置Wechatpay-Serial请求头导致的验签失败 by HerveyHall · Pull Request #3548 · binarywang/WxJava

Conversation

@HerveyHall

@HerveyHall HerveyHall commented Apr 11, 2025

Copy link
Copy Markdown
Contributor

实际使用过程中发现公钥模式下调用微信支付V3接口时,未设置Wechatpay-Serial请求头会返回错误信息“应答的微信支付签名验证失败”,但如果兼容两种模式并设置正确的Wechatpay-Serial请求头就可以解决该问题

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@HerveyHall
【微信支付】修复公钥模式下V3接口未设置Wechatpay-Serial请求头导致的验签失败
1536eca
@HerveyHall

HerveyHall commented Apr 11, 2025

Copy link
Copy Markdown
Contributor Author

目前查看源码发现postV3方法中请求接口时已经添加Wechatpay-Serial请求头,所以对于get请求也可以暂时在获取WxPayService实例时通过重写getV3方法来解决,代码如下:

    private static com.github.binarywang.wxpay.service.WxPayService getWxPayService(WxPayConfig payConfig) {
        com.github.binarywang.wxpay.service.WxPayService wxPayService = new com.github.binarywang.wxpay.service.impl.WxPayServiceImpl() {
            @Override
            public String getV3(String url) throws WxPayException {
                HttpGet httpGet = new HttpGet(url);
                httpGet.addHeader("Accept", "application/json");
                httpGet.addHeader("Content-Type", "application/json");
                httpGet.addHeader("Wechatpay-Serial", getWechatpaySerial(this.getConfig()));
                return this.requestV3(url, httpGet);
            }

            private String getWechatpaySerial(WxPayConfig wxPayConfig) {
                if (StringUtils.isNotBlank(wxPayConfig.getPublicKeyId())) {
                    return wxPayConfig.getPublicKeyId();
                }
                return wxPayConfig.getVerifier().getValidCertificate().getSerialNumber().toString(16).toUpperCase();
            }
        };
        wxPayService.setConfig(payConfig);
        return wxPayService;
    }
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@binarywang

binarywang commented Apr 11, 2025

Copy link
Copy Markdown
Owner

那现在getV3存在的意义是什么?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@HerveyHall

HerveyHall commented Apr 11, 2025

Copy link
Copy Markdown
Contributor Author

那现在getV3存在的意义是什么?

很遗憾,我的项目里WxJava只用于支付场景,而getV3方法在很多其他场景下也会有调用,我无法确定是否都存在同样问题,因此还需要更多的验证

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@binarywang

binarywang commented Apr 14, 2025

Copy link
Copy Markdown
Owner

是不是可以在配置里加一个参数,根据它来决定调用哪个get方法?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@binarywang binarywang added this to the 4.7.5 milestone Apr 14, 2025
HerveyHall added 2 commits April 15, 2025 11:38
@HerveyHall
增加配置参数,决定是否在请求v3接口时全部添加Wechatpay-Serial请求头,默认需要添加
a815366
@HerveyHall
调整配置参数strictlyNeedWechatPaySerial的默认值,改为默认不添加
ba91545
binarywang
binarywang reviewed Apr 15, 2025
View reviewed changes
Comment thread ...in-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread ...a-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

@binarywang
binarywang merged commit e16e0e9 into binarywang:develop Apr 15, 2025
This was referenced Jun 30, 2025
Feature implementation from commits b225afb..854b50b codeOwlAI/WxJava#2
Open
Feature implementation from commits 71fbc2b..6a4ed91 codeOwlAI/WxJava#3
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@binarywang binarywang binarywang left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

4.7.5

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@HerveyHall @binarywang
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.