Skip to content

Commit f226012

Browse files
committed
fix: 保留小程序纯签约版本字段兼容性
1 parent 22765e2 commit f226012

2 files changed

Lines changed: 56 additions & 10 deletions

File tree

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/request/WxMaEntrustRequest.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.google.gson.GsonBuilder;
77
import com.google.gson.annotations.SerializedName;
88
import com.thoughtworks.xstream.annotations.XStreamAlias;
9+
import com.thoughtworks.xstream.annotations.XStreamOmitField;
910
import lombok.*;
1011
import me.chanjar.weixin.common.annotation.Required;
1112

@@ -101,18 +102,12 @@ public class WxMaEntrustRequest extends BaseWxPayRequest {
101102
private String notifyUrl;
102103

103104
/**
104-
* <pre>
105-
* 版本号
106-
* sign
107-
* 是
108-
* string(8)
109-
* 1.0
110-
* 固定值1.0
111-
* </pre>
105+
* @deprecated 小程序纯签约接口不支持该参数,设置后不会参与请求序列化或签名。
112106
*/
113-
@Required
107+
@Deprecated
108+
@XStreamOmitField
114109
@XStreamAlias("version")
115-
private String version;
110+
private transient String version;
116111

117112

118113
/**
@@ -155,6 +150,11 @@ protected boolean needNonceStr() {
155150
return false;
156151
}
157152

153+
@Override
154+
protected String[] getIgnoredParamsForSign() {
155+
return new String[]{"version"};
156+
}
157+
158158
@Override
159159
protected void storeMap(Map<String, String> map) {
160160
map.put("plan_id", planId);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.github.binarywang.wxpay.bean.request;
2+
3+
import com.github.binarywang.wxpay.config.WxPayConfig;
4+
import com.github.binarywang.wxpay.constant.WxPayConstants;
5+
import com.github.binarywang.wxpay.util.SignUtils;
6+
import com.github.binarywang.wxpay.util.XmlConfig;
7+
import org.testng.annotations.Test;
8+
9+
import static org.assertj.core.api.Assertions.assertThat;
10+
11+
/**
12+
* Tests for {@link WxMaEntrustRequest}.
13+
*/
14+
public class WxMaEntrustRequestTest {
15+
16+
@Test
17+
public void versionIsExcludedFromPayloadAndSignature() throws Exception {
18+
WxMaEntrustRequest request = WxMaEntrustRequest.newBuilder()
19+
.planId("plan-id")
20+
.contractCode("contract-code")
21+
.requestSerial(1L)
22+
.contractDisplayAccount("account")
23+
.notifyUrl("https://example.com/notify")
24+
.timestamp("1710000000")
25+
.version("1.0")
26+
.build();
27+
WxPayConfig config = new WxPayConfig();
28+
config.setAppId("wx-app-id");
29+
config.setMchId("mch-id");
30+
config.setMchKey("mch-key");
31+
32+
request.checkAndSign(config);
33+
34+
assertThat(request.toString()).doesNotContain("version");
35+
assertThat(request.toXML()).doesNotContain("<version>");
36+
boolean fastMode = XmlConfig.fastMode;
37+
try {
38+
XmlConfig.fastMode = true;
39+
assertThat(request.toXML()).doesNotContain("<version>");
40+
} finally {
41+
XmlConfig.fastMode = fastMode;
42+
}
43+
assertThat(request.getSign()).isEqualTo(SignUtils.createSign(
44+
request, WxPayConstants.SignType.MD5, config.getMchKey(), new String[]{"version"}));
45+
}
46+
}

0 commit comments

Comments
 (0)