Skip to content

Commit 839ecad

Browse files
committed
增加新的统一下单接口,并添加对接口格式的单元测试,并未对实际功能进行测试
1 parent c483829 commit 839ecad

File tree

10 files changed

+1093
-370
lines changed

10 files changed

+1093
-370
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/SimplePostRequestExecutor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public String execute(CloseableHttpClient httpclient, HttpHost httpProxy, String
3535

3636
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
3737
String responseContent = Utf8ResponseHandler.INSTANCE.handleResponse(response);
38+
if (responseContent.isEmpty()) {
39+
throw new WxErrorException(
40+
WxError.newBuilder().setErrorCode(9999).setErrorMsg("无响应内容")
41+
.build());
42+
}
43+
3844
if (responseContent.startsWith("<xml>")) {
3945
//xml格式输出直接返回
4046
return responseContent;

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
import me.chanjar.weixin.mp.bean.pay.WxMpPayCallback;
77
import me.chanjar.weixin.mp.bean.pay.WxMpPayRefundResult;
88
import me.chanjar.weixin.mp.bean.pay.WxMpPayResult;
9+
import me.chanjar.weixin.mp.bean.pay.WxMpPrepayIdResult;
910
import me.chanjar.weixin.mp.bean.pay.WxRedpackResult;
1011
import me.chanjar.weixin.mp.bean.pay.WxSendRedpackRequest;
1112
import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderRequest;
12-
import me.chanjar.weixin.mp.bean.result.WxMpPrepayIdResult;
13+
import me.chanjar.weixin.mp.bean.pay.WxUnifiedOrderResult;
1314

1415
/**
1516
* 微信支付相关接口
@@ -48,9 +49,11 @@ public interface WxMpPayService {
4849
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
4950
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
5051
* 接口地址:https://api.mch.weixin.qq.com/pay/unifiedorder
52+
* @throws WxErrorException
5153
*
5254
*/
53-
WxMpPrepayIdResult unifiedOrder(WxUnifiedOrderRequest request);
55+
WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
56+
throws WxErrorException;
5457

5558
/**
5659
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImpl.java

Lines changed: 178 additions & 94 deletions
Large diffs are not rendered by default.
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
package me.chanjar.weixin.mp.bean.pay;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* <pre>
7+
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"返回的结果
8+
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
9+
* </pre>
10+
*
11+
* @author chanjarster
12+
*/
13+
@Deprecated
14+
public class WxMpPrepayIdResult implements Serializable {
15+
private static final long serialVersionUID = -8970574397788396143L;
16+
private String return_code;
17+
private String return_msg;
18+
private String appid;
19+
private String mch_id;
20+
private String nonce_str;
21+
private String sign;
22+
private String result_code;
23+
private String prepay_id;
24+
private String trade_type;
25+
private String err_code;
26+
private String err_code_des;
27+
private String code_url;
28+
29+
public String getReturn_code() {
30+
return this.return_code;
31+
}
32+
33+
public void setReturn_code(String return_code) {
34+
this.return_code = return_code;
35+
}
36+
37+
public String getReturn_msg() {
38+
return this.return_msg;
39+
}
40+
41+
public void setReturn_msg(String return_msg) {
42+
this.return_msg = return_msg;
43+
}
44+
45+
public String getAppid() {
46+
return this.appid;
47+
}
48+
49+
public void setAppid(String appid) {
50+
this.appid = appid;
51+
}
52+
53+
public String getMch_id() {
54+
return this.mch_id;
55+
}
56+
57+
public void setMch_id(String mch_id) {
58+
this.mch_id = mch_id;
59+
}
60+
61+
public String getNonce_str() {
62+
return this.nonce_str;
63+
}
64+
65+
public void setNonce_str(String nonce_str) {
66+
this.nonce_str = nonce_str;
67+
}
68+
69+
public String getSign() {
70+
return this.sign;
71+
}
72+
73+
public void setSign(String sign) {
74+
this.sign = sign;
75+
}
76+
77+
public String getResult_code() {
78+
return this.result_code;
79+
}
80+
81+
public void setResult_code(String result_code) {
82+
this.result_code = result_code;
83+
}
84+
85+
public String getPrepay_id() {
86+
return this.prepay_id;
87+
}
88+
89+
public void setPrepay_id(String prepay_id) {
90+
this.prepay_id = prepay_id;
91+
}
92+
93+
public String getTrade_type() {
94+
return this.trade_type;
95+
}
96+
97+
public void setTrade_type(String trade_type) {
98+
this.trade_type = trade_type;
99+
}
100+
101+
public String getErr_code() {
102+
return this.err_code;
103+
}
104+
105+
public void setErr_code(String err_code) {
106+
this.err_code = err_code;
107+
}
108+
109+
public String getErr_code_des() {
110+
return this.err_code_des;
111+
}
112+
113+
public void setErr_code_des(String err_code_des) {
114+
this.err_code_des = err_code_des;
115+
}
116+
117+
public String getCode_url() {
118+
return this.code_url;
119+
}
120+
121+
public void setCode_url(String code_url) {
122+
this.code_url = code_url;
123+
}
124+
}

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxRedpackResult.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,32 @@ public class WxRedpackResult implements Serializable {
1919
private static final long serialVersionUID = -4837415036337132073L;
2020

2121
@XStreamAlias("return_code")
22-
String returnCode;
22+
private String returnCode;
2323
@XStreamAlias("return_msg")
24-
String returnMsg;
24+
private String returnMsg;
2525
@XStreamAlias("sign")
26-
String sign;
26+
private String sign;
2727
@XStreamAlias("result_code")
28-
String resultCode;
28+
private String resultCode;
2929

3030
@XStreamAlias("err_code")
31-
String errCode;
31+
private String errCode;
3232
@XStreamAlias("err_code_des")
33-
String errCodeDes;
33+
private String errCodeDes;
3434
@XStreamAlias("mch_billno")
35-
String mchBillno;
35+
private String mchBillno;
3636
@XStreamAlias("mch_id")
37-
String mchId;
37+
private String mchId;
3838
@XStreamAlias("wxappid")
39-
String wxappid;
39+
private String wxappid;
4040
@XStreamAlias("re_openid")
41-
String reOpenid;
41+
private String reOpenid;
4242
@XStreamAlias("total_amount")
43-
int totalAmount;
43+
private int totalAmount;
4444
@XStreamAlias("send_time")
45-
String sendTime;
45+
private String sendTime;
4646
@XStreamAlias("send_listid")
47-
String sendListid;
47+
private String sendListid;
4848

4949
public String getErrCode() {
5050
return this.errCode;

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/bean/pay/WxSendRedpackRequest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -158,135 +158,135 @@ public class WxSendRedpackRequest {
158158
private String consumeMchId;
159159

160160
public String getMchBillno() {
161-
return mchBillno;
161+
return this.mchBillno;
162162
}
163163

164164
public void setMchBillno(String mchBillno) {
165165
this.mchBillno = mchBillno;
166166
}
167167

168168
public String getSendName() {
169-
return sendName;
169+
return this.sendName;
170170
}
171171

172172
public void setSendName(String sendName) {
173173
this.sendName = sendName;
174174
}
175175

176176
public String getReOpenid() {
177-
return reOpenid;
177+
return this.reOpenid;
178178
}
179179

180180
public void setReOpenid(String reOpenid) {
181181
this.reOpenid = reOpenid;
182182
}
183183

184184
public Integer getTotalAmount() {
185-
return totalAmount;
185+
return this.totalAmount;
186186
}
187187

188188
public void setTotalAmount(Integer totalAmount) {
189189
this.totalAmount = totalAmount;
190190
}
191191

192192
public Integer getTotalNum() {
193-
return totalNum;
193+
return this.totalNum;
194194
}
195195

196196
public void setTotalNum(Integer totalNum) {
197197
this.totalNum = totalNum;
198198
}
199199

200200
public String getAmtType() {
201-
return amtType;
201+
return this.amtType;
202202
}
203203

204204
public void setAmtType(String amtType) {
205205
this.amtType = amtType;
206206
}
207207

208208
public String getWishing() {
209-
return wishing;
209+
return this.wishing;
210210
}
211211

212212
public void setWishing(String wishing) {
213213
this.wishing = wishing;
214214
}
215215

216216
public String getClientIp() {
217-
return clientIp;
217+
return this.clientIp;
218218
}
219219

220220
public void setClientIp(String clientIp) {
221221
this.clientIp = clientIp;
222222
}
223223

224224
public String getActName() {
225-
return actName;
225+
return this.actName;
226226
}
227227

228228
public void setActName(String actName) {
229229
this.actName = actName;
230230
}
231231

232232
public String getRemark() {
233-
return remark;
233+
return this.remark;
234234
}
235235

236236
public void setRemark(String remark) {
237237
this.remark = remark;
238238
}
239239

240240
public String getWxAppid() {
241-
return wxAppid;
241+
return this.wxAppid;
242242
}
243243

244244
public void setWxAppid(String wxAppid) {
245245
this.wxAppid = wxAppid;
246246
}
247247

248248
public String getMchId() {
249-
return mchId;
249+
return this.mchId;
250250
}
251251

252252
public void setMchId(String mchId) {
253253
this.mchId = mchId;
254254
}
255255

256256
public String getNonceStr() {
257-
return nonceStr;
257+
return this.nonceStr;
258258
}
259259

260260
public void setNonceStr(String nonceStr) {
261261
this.nonceStr = nonceStr;
262262
}
263263

264264
public String getSign() {
265-
return sign;
265+
return this.sign;
266266
}
267267

268268
public void setSign(String sign) {
269269
this.sign = sign;
270270
}
271271

272272
public String getSceneId() {
273-
return sceneId;
273+
return this.sceneId;
274274
}
275275

276276
public void setSceneId(String sceneId) {
277277
this.sceneId = sceneId;
278278
}
279279

280280
public String getRiskInfo() {
281-
return riskInfo;
281+
return this.riskInfo;
282282
}
283283

284284
public void setRiskInfo(String riskInfo) {
285285
this.riskInfo = riskInfo;
286286
}
287287

288288
public String getConsumeMchId() {
289-
return consumeMchId;
289+
return this.consumeMchId;
290290
}
291291

292292
public void setConsumeMchId(String consumeMchId) {

0 commit comments

Comments
 (0)