Skip to content

Commit 435eb12

Browse files
committed
果断去掉旧有接口代码
1 parent 8619430 commit 435eb12

File tree

3 files changed

+1
-289
lines changed

3 files changed

+1
-289
lines changed

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

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,6 @@
1919
*/
2020
public interface WxMpPayService {
2121

22-
/**
23-
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
24-
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
25-
*
26-
* @param openId 支付人openId
27-
* @param outTradeNo 商户端对应订单号
28-
* @param amt 金额(单位元)
29-
* @param body 商品描述
30-
* @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP
31-
* @param ip 发起支付的客户端IP
32-
* @param notifyUrl 通知地址
33-
* @throws WxErrorException
34-
* @deprecated Use me.chanjar.weixin.mp.api.WxMpService.getPrepayId(Map<String, String>) instead
35-
*/
36-
@Deprecated
37-
WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt,
38-
String body, String tradeType, String ip, String notifyUrl)
39-
throws WxErrorException;
40-
41-
/**
42-
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
43-
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
44-
*
45-
* @param parameters All required/optional parameters for weixin payment
46-
* @throws WxErrorException
47-
* @deprecated use me.chanjar.weixin.mp.api.WxMpPayService.unifiedOrder(WxUnifiedOrderRequest) instead
48-
*/
49-
@Deprecated
50-
WxMpPrepayIdResult getPrepayId(Map<String, String> parameters)
51-
throws WxErrorException;
52-
5322
/**
5423
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_1)
5524
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
@@ -60,54 +29,13 @@ WxMpPrepayIdResult getPrepayId(Map<String, String> parameters)
6029
WxUnifiedOrderResult unifiedOrder(WxUnifiedOrderRequest request)
6130
throws WxErrorException;
6231

63-
/**
64-
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
65-
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
66-
*
67-
* @param parameters the required or optional parameters
68-
* @deprecated use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead.
69-
*/
70-
@Deprecated
71-
Map<String, String> getPayInfo(Map<String, String> parameters) throws WxErrorException;
72-
7332
/**
7433
* 该接口调用“统一下单”接口,并拼装发起支付请求需要的参数
7534
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
7635
*
7736
*/
7837
Map<String, String> getPayInfo(WxUnifiedOrderRequest request) throws WxErrorException;
7938

80-
/**
81-
* 该接口调用“统一下单”接口,并拼装NATIVE发起支付请求需要的参数
82-
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
83-
* tradeType 交易类型 NATIVE (其他交易类型JSAPI,APP,WAP)
84-
*
85-
* @param productId 商户商品ID
86-
* @param outTradeNo 商户端对应订单号
87-
* @param amt 金额(单位元)
88-
* @param body 商品描述
89-
* @param ip 发起支付的客户端IP
90-
* @param notifyUrl 通知地址
91-
* @deprecated Use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead
92-
*/
93-
@Deprecated
94-
Map<String, String> getNativePayInfo(String productId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
95-
96-
/**
97-
* 该接口调用“统一下单”接口,并拼装JSAPI发起支付请求需要的参数
98-
* 详见http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN
99-
* tradeType 交易类型 JSAPI(其他交易类型NATIVE,APP,WAP)
100-
*
101-
* @param openId 支付人openId
102-
* @param outTradeNo 商户端对应订单号
103-
* @param amt 金额(单位元)
104-
* @param body 商品描述
105-
* @param ip 发起支付的客户端IP
106-
* @param notifyUrl 通知地址
107-
* @deprecated Use me.chanjar.weixin.mp.api.WxMpPayService.getPayInfo(WxUnifiedOrderRequest) instead
108-
*/
109-
@Deprecated
110-
Map<String, String> getJsapiPayInfo(String openId, String outTradeNo, double amt, String body, String ip, String notifyUrl) throws WxErrorException;
11139

11240
/**
11341
* 该接口提供所有微信支付订单的查询,当支付通知处理异常戒丢失的情冴,商户可以通过该接口查询订单支付状态。
@@ -148,30 +76,6 @@ WxMpPayResult getJSSDKPayResult(String transactionId, String outTradeNo)
14876
*/
14977
boolean checkJSSDKCallbackDataSignature(Map<String, String> kvm, String signature);
15078

151-
/**
152-
* 发送普通微信红包给个人用户
153-
* <pre>
154-
* 需要传入的必填参数如下:
155-
* mch_billno//商户订单号
156-
* send_name//商户名称
157-
* re_openid//用户openid
158-
* total_amount//红包总额
159-
* total_num//红包发放总人数
160-
* wishing//红包祝福语
161-
* client_ip//服务器Ip地址
162-
* act_name//活动名称
163-
* remark //备注
164-
* 文档详见:https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
165-
* 使用现金红包功能需要在xml配置文件中额外设置:
166-
* </pre>
167-
* <partnerId></partnerId>微信商户平台ID
168-
* <partnerKey></partnerKey>商户平台设置的API密钥
169-
* @deprecated use me.chanjar.weixin.mp.api.WxMpPayService.sendRedpack(WxSendRedpackRequest) instead
170-
*
171-
*/
172-
@Deprecated
173-
WxRedpackResult sendRedpack(Map<String, String> parameters) throws WxErrorException;
174-
17579
/**
17680
* 发送微信红包给个人用户
17781
* <pre>

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

Lines changed: 0 additions & 192 deletions
Original file line numberDiff line numberDiff line change
@@ -44,173 +44,12 @@ public class WxMpPayServiceImpl implements WxMpPayService {
4444
private static final List<String> TRADE_TYPES = Lists.newArrayList("JSAPI",
4545
"NATIVE", "APP");
4646
private final Logger log = LoggerFactory.getLogger(WxMpPayServiceImpl.class);
47-
private final String[] REQUIRED_ORDER_PARAMETERS = new String[] { "appid",
48-
"mch_id", "body", "out_trade_no", "total_fee", "spbill_create_ip",
49-
"notify_url", "trade_type" };
5047
private WxMpService wxMpService;
5148

5249
public WxMpPayServiceImpl(WxMpService wxMpService) {
5350
this.wxMpService = wxMpService;
5451
}
5552

56-
@Override
57-
@Deprecated
58-
public WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo,
59-
double amt, String body, String tradeType, String ip,
60-
String callbackUrl) throws WxErrorException {
61-
Map<String, String> packageParams = new HashMap<>();
62-
packageParams.put("appid",
63-
this.wxMpService.getWxMpConfigStorage().getAppId());
64-
packageParams.put("mch_id",
65-
this.wxMpService.getWxMpConfigStorage().getPartnerId());
66-
packageParams.put("body", body);
67-
packageParams.put("out_trade_no", outTradeNo);
68-
packageParams.put("total_fee", (int) (amt * 100) + "");
69-
packageParams.put("spbill_create_ip", ip);
70-
packageParams.put("notify_url", callbackUrl);
71-
packageParams.put("trade_type", tradeType);
72-
packageParams.put("openid", openId);
73-
74-
return getPrepayId(packageParams);
75-
}
76-
77-
@Override
78-
@Deprecated
79-
public WxMpPrepayIdResult getPrepayId(final Map<String, String> parameters)
80-
throws WxErrorException {
81-
final SortedMap<String, String> packageParams = new TreeMap<>(parameters);
82-
packageParams.put("appid",
83-
this.wxMpService.getWxMpConfigStorage().getAppId());
84-
packageParams.put("mch_id",
85-
this.wxMpService.getWxMpConfigStorage().getPartnerId());
86-
packageParams.put("nonce_str", System.currentTimeMillis() + "");
87-
checkParameters(packageParams);
88-
89-
String sign = this.createSign(packageParams,
90-
this.wxMpService.getWxMpConfigStorage().getPartnerKey());
91-
packageParams.put("sign", sign);
92-
93-
StringBuilder request = new StringBuilder("<xml>");
94-
for (Map.Entry<String, String> para : packageParams.entrySet()) {
95-
request.append(String.format("<%s>%s</%s>", para.getKey(),
96-
para.getValue(), para.getKey()));
97-
}
98-
99-
request.append("</xml>");
100-
101-
String url = "https://api.mch.weixin.qq.com/pay/unifiedorder";
102-
String responseContent = this.wxMpService.post(url, request.toString());
103-
XStream xstream = XStreamInitializer.getInstance();
104-
xstream.alias("xml", WxMpPrepayIdResult.class);
105-
return (WxMpPrepayIdResult) xstream.fromXML(responseContent);
106-
}
107-
108-
private void checkParameters(Map<String, String> parameters) {
109-
for (String para : this.REQUIRED_ORDER_PARAMETERS) {
110-
if (!parameters.containsKey(para)) {
111-
throw new IllegalArgumentException(
112-
"Reqiured argument '" + para + "' is missing.");
113-
}
114-
}
115-
116-
if ("JSAPI".equals(parameters.get("trade_type"))
117-
&& !parameters.containsKey("openid")) {
118-
throw new IllegalArgumentException(
119-
"Reqiured argument 'openid' is missing when trade_type is 'JSAPI'.");
120-
}
121-
122-
if ("NATIVE".equals(parameters.get("trade_type"))
123-
&& !parameters.containsKey("product_id")) {
124-
throw new IllegalArgumentException(
125-
"Reqiured argument 'product_id' is missing when trade_type is 'NATIVE'.");
126-
}
127-
}
128-
129-
@Override
130-
@Deprecated
131-
public Map<String, String> getJsapiPayInfo(String openId, String outTradeNo,
132-
double amt, String body, String ip, String callbackUrl)
133-
throws WxErrorException {
134-
Map<String, String> packageParams = new HashMap<>();
135-
packageParams.put("appid",
136-
this.wxMpService.getWxMpConfigStorage().getAppId());
137-
packageParams.put("mch_id",
138-
this.wxMpService.getWxMpConfigStorage().getPartnerId());
139-
packageParams.put("body", body);
140-
packageParams.put("out_trade_no", outTradeNo);
141-
packageParams.put("total_fee", (int) (amt * 100) + "");
142-
packageParams.put("spbill_create_ip", ip);
143-
packageParams.put("notify_url", callbackUrl);
144-
packageParams.put("trade_type", "JSAPI");
145-
packageParams.put("openid", openId);
146-
147-
return getPayInfo(packageParams);
148-
}
149-
150-
@Override
151-
@Deprecated
152-
public Map<String, String> getNativePayInfo(String productId,
153-
String outTradeNo, double amt, String body, String ip, String callbackUrl)
154-
throws WxErrorException {
155-
Map<String, String> packageParams = new HashMap<>();
156-
packageParams.put("appid",
157-
this.wxMpService.getWxMpConfigStorage().getAppId());
158-
packageParams.put("mch_id",
159-
this.wxMpService.getWxMpConfigStorage().getPartnerId());
160-
packageParams.put("body", body);
161-
packageParams.put("out_trade_no", outTradeNo);
162-
packageParams.put("total_fee", (int) (amt * 100) + "");
163-
packageParams.put("spbill_create_ip", ip);
164-
packageParams.put("notify_url", callbackUrl);
165-
packageParams.put("trade_type", "NATIVE");
166-
packageParams.put("product_id", productId);
167-
168-
return getPayInfo(packageParams);
169-
}
170-
171-
@Override
172-
@Deprecated
173-
public Map<String, String> getPayInfo(Map<String, String> parameters)
174-
throws WxErrorException {
175-
WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId(parameters);
176-
177-
if (!"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getReturn_code())
178-
|| !"SUCCESS".equalsIgnoreCase(wxMpPrepayIdResult.getResult_code())) {
179-
WxError error = new WxError();
180-
error.setErrorCode(-1);
181-
error.setErrorMsg("return_code:" + wxMpPrepayIdResult.getReturn_code()
182-
+ ";return_msg:" + wxMpPrepayIdResult.getReturn_msg()
183-
+ ";result_code:" + wxMpPrepayIdResult.getResult_code() + ";err_code"
184-
+ wxMpPrepayIdResult.getErr_code() + ";err_code_des"
185-
+ wxMpPrepayIdResult.getErr_code_des());
186-
throw new WxErrorException(error);
187-
}
188-
189-
String prepayId = wxMpPrepayIdResult.getPrepay_id();
190-
if (prepayId == null || prepayId.equals("")) {
191-
throw new RuntimeException(
192-
String.format("Failed to get prepay id due to error code '%s'(%s).",
193-
wxMpPrepayIdResult.getErr_code(),
194-
wxMpPrepayIdResult.getErr_code_des()));
195-
}
196-
197-
Map<String, String> payInfo = new HashMap<>();
198-
payInfo.put("appId", this.wxMpService.getWxMpConfigStorage().getAppId());
199-
// 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
200-
payInfo.put("timeStamp", String.valueOf(System.currentTimeMillis() / 1000));
201-
payInfo.put("nonceStr", System.currentTimeMillis() + "");
202-
payInfo.put("package", "prepay_id=" + prepayId);
203-
payInfo.put("signType", "MD5");
204-
if ("NATIVE".equals(parameters.get("trade_type"))) {
205-
payInfo.put("codeUrl", wxMpPrepayIdResult.getCode_url());
206-
}
207-
208-
String finalSign = this.createSign(payInfo,
209-
this.wxMpService.getWxMpConfigStorage().getPartnerKey());
210-
payInfo.put("paySign", finalSign);
211-
return payInfo;
212-
}
213-
21453
@Override
21554
public WxMpPayResult getJSSDKPayResult(String transactionId,
21655
String outTradeNo) throws WxErrorException {
@@ -313,37 +152,6 @@ public boolean checkJSSDKCallbackDataSignature(Map<String, String> kvm,
313152
this.wxMpService.getWxMpConfigStorage().getPartnerKey()));
314153
}
315154

316-
@Override
317-
@Deprecated
318-
public WxRedpackResult sendRedpack(Map<String, String> parameters)
319-
throws WxErrorException {
320-
SortedMap<String, String> packageParams = new TreeMap<>(parameters);
321-
packageParams.put("wxappid",
322-
this.wxMpService.getWxMpConfigStorage().getAppId());
323-
packageParams.put("mch_id",
324-
this.wxMpService.getWxMpConfigStorage().getPartnerId());
325-
packageParams.put("nonce_str", System.currentTimeMillis() + "");
326-
327-
String sign = this.createSign(packageParams,
328-
this.wxMpService.getWxMpConfigStorage().getPartnerKey());
329-
packageParams.put("sign", sign);
330-
331-
StringBuilder request = new StringBuilder("<xml>");
332-
for (Map.Entry<String, String> para : packageParams.entrySet()) {
333-
request.append(String.format("<%s>%s</%s>", para.getKey(),
334-
para.getValue(), para.getKey()));
335-
}
336-
337-
request.append("</xml>");
338-
339-
String url = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack";
340-
341-
String responseContent = this.wxMpService.post(url, request.toString());
342-
XStream xstream = XStreamInitializer.getInstance();
343-
xstream.processAnnotations(WxRedpackResult.class);
344-
return (WxRedpackResult) xstream.fromXML(responseContent);
345-
}
346-
347155
@Override
348156
public WxRedpackResult sendRedpack(WxSendRedpackRequest request)
349157
throws WxErrorException {

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpPayServiceImplTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void testUnifiedOrder() throws WxErrorException {
8585
WxUnifiedOrderResult result = this.wxService.getPayService()
8686
.unifiedOrder(WxUnifiedOrderRequest.builder().body("1111111")
8787
.totalFee(1).spbillCreateIp("111111").notifyURL("111111")
88-
.tradeType("JSAPI1").openid("122").outTradeNo("111111").build());
88+
.tradeType("JSAPI").openid("122").outTradeNo("111111").build());
8989
System.err.println(result);
9090
}
9191
}

0 commit comments

Comments
 (0)