@@ -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 {
0 commit comments