Skip to content

Commit fa55bf6

Browse files
committed
Merge remote-tracking branch 'upstream/develop' into develop
update from upstream
2 parents db11c2a + 72aab0d commit fa55bf6

File tree

9 files changed

+305
-244
lines changed

9 files changed

+305
-244
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ weixin-java-tools
2323
<dependency>
2424
<groupId>me.chanjar</groupId>
2525
<artifactId>weixin-java-mp</artifactId>
26-
<version>1.3.2</version>
26+
<version>1.3.3</version>
2727
</dependency>
2828
```
2929

@@ -33,7 +33,7 @@ weixin-java-tools
3333
<dependency>
3434
<groupId>me.chanjar</groupId>
3535
<artifactId>weixin-java-cp</artifactId>
36-
<version>1.3.2</version>
36+
<version>1.3.3</version>
3737
</dependency>
3838
```
3939

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>me.chanjar</groupId>
77
<artifactId>weixin-java-parent</artifactId>
8-
<version>1.3.3-SNAPSHOT</version>
8+
<version>1.3.4-SNAPSHOT</version>
99
<packaging>pom</packaging>
1010
<name>WeiXin Java Tools - Parent</name>
1111
<description>微信公众号、企业号上级POM</description>

weixin-java-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>me.chanjar</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.3.3-SNAPSHOT</version>
9+
<version>1.3.4-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-common</artifactId>

weixin-java-cp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>me.chanjar</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.3.3-SNAPSHOT</version>
9+
<version>1.3.4-SNAPSHOT</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-cp</artifactId>

weixin-java-mp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>me.chanjar</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.3.3-SNAPSHOT</version>
9+
<version>1.3.4-SNAPSHOT</version>
1010
</parent>
1111
<artifactId>weixin-java-mp</artifactId>
1212
<name>WeiXin Java Tools - MP</name>

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpServiceImpl.java

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -916,44 +916,44 @@ public Map<String, String> getJSSDKPayInfo(Map<String, String> parameters) {
916916

917917
@Override
918918
public WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo) {
919-
String nonce_str = System.currentTimeMillis() + "";
919+
String nonce_str = System.currentTimeMillis() + "";
920920

921-
SortedMap<String, String> packageParams = new TreeMap<String, String>();
922-
packageParams.put("appid", wxMpConfigStorage.getAppId());
923-
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
921+
SortedMap<String, String> packageParams = new TreeMap<String, String>();
922+
packageParams.put("appid", wxMpConfigStorage.getAppId());
923+
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
924+
if (transactionId != null && !"".equals(transactionId.trim()))
924925
packageParams.put("transaction_id", transactionId);
926+
else if (outTradeNo != null && !"".equals(outTradeNo.trim()))
925927
packageParams.put("out_trade_no", outTradeNo);
926-
packageParams.put("nonce_str", nonce_str);
927-
928-
String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey());
929-
String xml = "<xml>" +
930-
"<appid>" + wxMpConfigStorage.getAppId() + "</appid>" +
931-
"<mch_id>" + wxMpConfigStorage.getPartnerId() + "</mch_id>" +
932-
"<transaction_id>" + transactionId + "</transaction_id>" +
933-
"<out_trade_no>" + outTradeNo + "</out_trade_no>" +
934-
"<nonce_str>" + nonce_str + "</nonce_str>" +
935-
"<sign>" + sign + "</sign>" +
936-
"</xml>";
937-
938-
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery");
939-
if (httpProxy != null) {
940-
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
941-
httpPost.setConfig(config);
942-
}
928+
else
929+
throw new IllegalArgumentException("Either 'transactionId' or 'outTradeNo' must be given.");
930+
packageParams.put("nonce_str", nonce_str);
931+
packageParams.put("sign", WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey()));
943932

944-
StringEntity entity = new StringEntity(xml, Consts.UTF_8);
945-
httpPost.setEntity(entity);
946-
try {
947-
CloseableHttpResponse response = httpClient.execute(httpPost);
948-
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
949-
XStream xstream = XStreamInitializer.getInstance();
950-
xstream.alias("xml", WxMpPayResult.class);
951-
WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent);
952-
return wxMpPayResult;
953-
} catch (IOException e) {
954-
e.printStackTrace();
955-
}
956-
return new WxMpPayResult();
933+
StringBuilder request = new StringBuilder("<xml>");
934+
for (Entry<String, String> para : packageParams.entrySet()) {
935+
request.append(String.format("<%s>%s</%s>", para.getKey(), para.getValue(), para.getKey()));
936+
}
937+
request.append("</xml>");
938+
939+
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery");
940+
if (httpProxy != null) {
941+
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
942+
httpPost.setConfig(config);
943+
}
944+
945+
StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8);
946+
httpPost.setEntity(entity);
947+
try {
948+
CloseableHttpResponse response = httpClient.execute(httpPost);
949+
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
950+
XStream xstream = XStreamInitializer.getInstance();
951+
xstream.alias("xml", WxMpPayResult.class);
952+
WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent);
953+
return wxMpPayResult;
954+
} catch (IOException e) {
955+
throw new RuntimeException("Failed to query order due to IO exception.", e);
956+
}
957957
}
958958

959959
@Override

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/result/WxMpOAuth2AccessToken.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package me.chanjar.weixin.mp.bean.result;
22

3-
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
4-
53
import java.io.Serializable;
64

5+
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
6+
77
public class WxMpOAuth2AccessToken implements Serializable {
88

99
private String accessToken;
@@ -16,6 +16,8 @@ public class WxMpOAuth2AccessToken implements Serializable {
1616

1717
private String scope;
1818

19+
private String unionId;
20+
1921
public String getRefreshToken() {
2022
return refreshToken;
2123
}
@@ -56,6 +58,14 @@ public void setExpiresIn(int expiresIn) {
5658
this.expiresIn = expiresIn;
5759
}
5860

61+
public String getUnionId() {
62+
return unionId;
63+
}
64+
65+
public void setUnionId(String unionId) {
66+
this.unionId = unionId;
67+
}
68+
5969
public static WxMpOAuth2AccessToken fromJson(String json) {
6070
return WxMpGsonBuilder.create().fromJson(json, WxMpOAuth2AccessToken.class);
6171
}
@@ -68,6 +78,7 @@ public String toString() {
6878
", refreshToken='" + refreshToken + '\'' +
6979
", openId='" + openId + '\'' +
7080
", scope='" + scope + '\'' +
81+
", unionId='" + unionId + '\'' +
7182
'}';
7283
}
7384
}

0 commit comments

Comments
 (0)