mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-06 21:57:48 +08:00
Merge remote-tracking branch 'upstream/develop' into develop
update from upstream
This commit is contained in:
commit
fa55bf67eb
@ -23,7 +23,7 @@ weixin-java-tools
|
||||
<dependency>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-mp</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.3</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
@ -33,7 +33,7 @@ weixin-java-tools
|
||||
<dependency>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-cp</artifactId>
|
||||
<version>1.3.2</version>
|
||||
<version>1.3.3</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -5,7 +5,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-parent</artifactId>
|
||||
<version>1.3.3-SNAPSHOT</version>
|
||||
<version>1.3.4-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>WeiXin Java Tools - Parent</name>
|
||||
<description>微信公众号、企业号上级POM</description>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-parent</artifactId>
|
||||
<version>1.3.3-SNAPSHOT</version>
|
||||
<version>1.3.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-common</artifactId>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-parent</artifactId>
|
||||
<version>1.3.3-SNAPSHOT</version>
|
||||
<version>1.3.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>weixin-java-cp</artifactId>
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>me.chanjar</groupId>
|
||||
<artifactId>weixin-java-parent</artifactId>
|
||||
<version>1.3.3-SNAPSHOT</version>
|
||||
<version>1.3.4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<artifactId>weixin-java-mp</artifactId>
|
||||
<name>WeiXin Java Tools - MP</name>
|
||||
|
@ -921,19 +921,20 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
SortedMap<String, String> packageParams = new TreeMap<String, String>();
|
||||
packageParams.put("appid", wxMpConfigStorage.getAppId());
|
||||
packageParams.put("mch_id", wxMpConfigStorage.getPartnerId());
|
||||
if (transactionId != null && !"".equals(transactionId.trim()))
|
||||
packageParams.put("transaction_id", transactionId);
|
||||
else if (outTradeNo != null && !"".equals(outTradeNo.trim()))
|
||||
packageParams.put("out_trade_no", outTradeNo);
|
||||
else
|
||||
throw new IllegalArgumentException("Either 'transactionId' or 'outTradeNo' must be given.");
|
||||
packageParams.put("nonce_str", nonce_str);
|
||||
packageParams.put("sign", WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey()));
|
||||
|
||||
String sign = WxCryptUtil.createSign(packageParams, wxMpConfigStorage.getPartnerKey());
|
||||
String xml = "<xml>" +
|
||||
"<appid>" + wxMpConfigStorage.getAppId() + "</appid>" +
|
||||
"<mch_id>" + wxMpConfigStorage.getPartnerId() + "</mch_id>" +
|
||||
"<transaction_id>" + transactionId + "</transaction_id>" +
|
||||
"<out_trade_no>" + outTradeNo + "</out_trade_no>" +
|
||||
"<nonce_str>" + nonce_str + "</nonce_str>" +
|
||||
"<sign>" + sign + "</sign>" +
|
||||
"</xml>";
|
||||
StringBuilder request = new StringBuilder("<xml>");
|
||||
for (Entry<String, String> para : packageParams.entrySet()) {
|
||||
request.append(String.format("<%s>%s</%s>", para.getKey(), para.getValue(), para.getKey()));
|
||||
}
|
||||
request.append("</xml>");
|
||||
|
||||
HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/pay/orderquery");
|
||||
if (httpProxy != null) {
|
||||
@ -941,7 +942,7 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
httpPost.setConfig(config);
|
||||
}
|
||||
|
||||
StringEntity entity = new StringEntity(xml, Consts.UTF_8);
|
||||
StringEntity entity = new StringEntity(request.toString(), Consts.UTF_8);
|
||||
httpPost.setEntity(entity);
|
||||
try {
|
||||
CloseableHttpResponse response = httpClient.execute(httpPost);
|
||||
@ -951,9 +952,8 @@ public class WxMpServiceImpl implements WxMpService {
|
||||
WxMpPayResult wxMpPayResult = (WxMpPayResult) xstream.fromXML(responseContent);
|
||||
return wxMpPayResult;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("Failed to query order due to IO exception.", e);
|
||||
}
|
||||
return new WxMpPayResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,9 +1,9 @@
|
||||
package me.chanjar.weixin.mp.bean.result;
|
||||
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder;
|
||||
|
||||
public class WxMpOAuth2AccessToken implements Serializable {
|
||||
|
||||
private String accessToken;
|
||||
@ -16,6 +16,8 @@ public class WxMpOAuth2AccessToken implements Serializable {
|
||||
|
||||
private String scope;
|
||||
|
||||
private String unionId;
|
||||
|
||||
public String getRefreshToken() {
|
||||
return refreshToken;
|
||||
}
|
||||
@ -56,6 +58,14 @@ public class WxMpOAuth2AccessToken implements Serializable {
|
||||
this.expiresIn = expiresIn;
|
||||
}
|
||||
|
||||
public String getUnionId() {
|
||||
return unionId;
|
||||
}
|
||||
|
||||
public void setUnionId(String unionId) {
|
||||
this.unionId = unionId;
|
||||
}
|
||||
|
||||
public static WxMpOAuth2AccessToken fromJson(String json) {
|
||||
return WxMpGsonBuilder.create().fromJson(json, WxMpOAuth2AccessToken.class);
|
||||
}
|
||||
@ -68,6 +78,7 @@ public class WxMpOAuth2AccessToken implements Serializable {
|
||||
", refreshToken='" + refreshToken + '\'' +
|
||||
", openId='" + openId + '\'' +
|
||||
", scope='" + scope + '\'' +
|
||||
", unionId='" + unionId + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,11 @@ import java.io.Serializable;
|
||||
* @author ukid
|
||||
*/
|
||||
public class WxMpPayResult implements Serializable {
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = -570934170727777190L;
|
||||
|
||||
private String return_code;
|
||||
private String return_msg;
|
||||
private String appid;
|
||||
@ -23,6 +28,7 @@ public class WxMpPayResult implements Serializable {
|
||||
private String err_code;
|
||||
private String err_code_des;
|
||||
private String trade_state;
|
||||
private String trade_state_desc;
|
||||
private String device_info;
|
||||
private String openid;
|
||||
private String is_subscribe;
|
||||
@ -212,4 +218,40 @@ public class WxMpPayResult implements Serializable {
|
||||
this.time_end = time_end;
|
||||
}
|
||||
|
||||
public String getTrade_state_desc() {
|
||||
return trade_state_desc;
|
||||
}
|
||||
|
||||
public void setTrade_state_desc(String trade_state_desc) {
|
||||
this.trade_state_desc = trade_state_desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "WxMpPayResult{" +
|
||||
"return_code=" + return_code +
|
||||
", return_msg='" + return_msg + '\'' +
|
||||
", appid='" + appid + '\'' +
|
||||
", mch_id='" + mch_id + '\'' +
|
||||
", nonce_str='" + nonce_str + '\'' +
|
||||
", sign='" + sign + '\'' +
|
||||
", result_code='" + result_code + '\'' +
|
||||
", err_code='" + err_code + '\'' +
|
||||
", err_code_des='" + err_code_des + '\'' +
|
||||
", trade_state=" + trade_state +
|
||||
", trade_state_desc=" + trade_state_desc +
|
||||
", device_info='" + device_info + '\'' +
|
||||
", openid='" + openid + '\'' +
|
||||
", is_subscribe='" + is_subscribe + '\'' +
|
||||
", trade_type='" + trade_type + '\'' +
|
||||
", bank_type='" + bank_type + '\'' +
|
||||
", total_fee='" + total_fee + '\'' +
|
||||
", coupon_fee='" + coupon_fee + '\'' +
|
||||
", fee_type='" + fee_type + '\'' +
|
||||
", transaction_id='" + transaction_id + '\'' +
|
||||
", out_trade_no='" + out_trade_no + '\'' +
|
||||
", attach='" + attach + '\'' +
|
||||
", time_end='" + time_end + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,16 @@
|
||||
package me.chanjar.weixin.mp.util.json;
|
||||
|
||||
import com.google.gson.*;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class WxMpOAuth2AccessTokenAdapter implements JsonDeserializer<WxMpOAuth2AccessToken> {
|
||||
|
||||
public WxMpOAuth2AccessToken deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws
|
||||
@ -28,6 +33,9 @@ public class WxMpOAuth2AccessTokenAdapter implements JsonDeserializer<WxMpOAuth2
|
||||
if (accessTokenJsonObject.get("scope") != null && !accessTokenJsonObject.get("scope").isJsonNull()) {
|
||||
accessToken.setScope(GsonHelper.getAsString(accessTokenJsonObject.get("scope")));
|
||||
}
|
||||
if (accessTokenJsonObject.get("unionid") != null && !accessTokenJsonObject.get("unionid").isJsonNull()) {
|
||||
accessToken.setUnionId(GsonHelper.getAsString(accessTokenJsonObject.get("unionid")));
|
||||
}
|
||||
return accessToken;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user