Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.SerializedName;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamOmitField;
import lombok.*;
import me.chanjar.weixin.common.annotation.Required;

Expand Down Expand Up @@ -101,18 +102,12 @@ public class WxMaEntrustRequest extends BaseWxPayRequest {
private String notifyUrl;

/**
* <pre>
* 版本号
* sign
* 是
* string(8)
* 1.0
* 固定值1.0
* </pre>
* @deprecated 小程序纯签约接口不支持该参数,设置后不会参与请求序列化或签名。
*/
@Required
@Deprecated
@XStreamOmitField
@XStreamAlias("version")
private String version;
private transient String version;


/**
Expand Down Expand Up @@ -155,6 +150,11 @@ protected boolean needNonceStr() {
return false;
}

@Override
protected String[] getIgnoredParamsForSign() {
return new String[]{"version"};
}

@Override
protected void storeMap(Map<String, String> map) {
map.put("plan_id", planId);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.binarywang.wxpay.bean.request;

import com.github.binarywang.wxpay.config.WxPayConfig;
import com.github.binarywang.wxpay.constant.WxPayConstants;
import com.github.binarywang.wxpay.util.SignUtils;
import com.github.binarywang.wxpay.util.XmlConfig;
import org.testng.annotations.Test;

import static org.assertj.core.api.Assertions.assertThat;

/**
* Tests for {@link WxMaEntrustRequest}.
*/
public class WxMaEntrustRequestTest {

@Test
public void versionIsExcludedFromPayloadAndSignature() throws Exception {
WxMaEntrustRequest request = WxMaEntrustRequest.newBuilder()
.planId("plan-id")
.contractCode("contract-code")
.requestSerial(1L)
.contractDisplayAccount("account")
.notifyUrl("https://example.com/notify")
.timestamp("1710000000")
.version("1.0")
.build();
WxPayConfig config = new WxPayConfig();
config.setAppId("wx-app-id");
config.setMchId("mch-id");
config.setMchKey("mch-key");

request.checkAndSign(config);

assertThat(request.toString()).doesNotContain("version");
assertThat(request.toXML()).doesNotContain("<version>");
boolean fastMode = XmlConfig.fastMode;
try {
XmlConfig.fastMode = true;
assertThat(request.toXML()).doesNotContain("<version>");
} finally {
XmlConfig.fastMode = fastMode;
}
assertThat(request.getSign()).isEqualTo(SignUtils.createSign(
request, WxPayConstants.SignType.MD5, config.getMchKey(), new String[]{"version"}));
}
}