99import java .util .TreeMap ;
1010
1111import org .apache .commons .codec .digest .DigestUtils ;
12+ import org .apache .commons .lang3 .StringUtils ;
1213import org .joor .Reflect ;
1314import org .slf4j .Logger ;
1415import org .slf4j .LoggerFactory ;
@@ -168,6 +169,7 @@ public Map<String, String> getNativePayInfo(String productId,
168169 }
169170
170171 @ Override
172+ @ Deprecated
171173 public Map <String , String > getPayInfo (Map <String , String > parameters )
172174 throws WxErrorException {
173175 WxMpPrepayIdResult wxMpPrepayIdResult = getPrepayId (parameters );
@@ -477,7 +479,7 @@ private void checkParameters(WxUnifiedOrderRequest request) {
477479
478480 if (!TRADE_TYPES .contains (request .getTradeType ())) {
479481 throw new IllegalArgumentException (
480- "trade_type目前必须为" + TRADE_TYPES + "其中之一" );
482+ "trade_type目前必须为" + TRADE_TYPES + "其中之一" );
481483
482484 }
483485
@@ -491,4 +493,39 @@ private void checkParameters(WxUnifiedOrderRequest request) {
491493 }
492494 }
493495
496+ @ Override
497+ public Map <String , String > getPayInfo (WxUnifiedOrderRequest request ) throws WxErrorException {
498+ WxUnifiedOrderResult unifiedOrderResult = this .unifiedOrder (request );
499+
500+ if (!"SUCCESS" .equalsIgnoreCase (unifiedOrderResult .getReturnCode ())
501+ || !"SUCCESS" .equalsIgnoreCase (unifiedOrderResult .getResultCode ())) {
502+ throw new WxErrorException (WxError .newBuilder ().setErrorCode (-1 )
503+ .setErrorMsg ("return_code:" + unifiedOrderResult .getReturnCode () + ";return_msg:"
504+ + unifiedOrderResult .getReturnMsg () + ";result_code:" + unifiedOrderResult .getResultCode () + ";err_code"
505+ + unifiedOrderResult .getErrCode () + ";err_code_des" + unifiedOrderResult .getErrCodeDes ())
506+ .build ());
507+ }
508+
509+ String prepayId = unifiedOrderResult .getPrepayId ();
510+ if (StringUtils .isBlank (prepayId )) {
511+ throw new RuntimeException (String .format ("Failed to get prepay id due to error code '%s'(%s)." ,
512+ unifiedOrderResult .getErrCode (), unifiedOrderResult .getErrCodeDes ()));
513+ }
514+
515+ Map <String , String > payInfo = new HashMap <>();
516+ payInfo .put ("appId" , this .wxMpService .getWxMpConfigStorage ().getAppId ());
517+ // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
518+ payInfo .put ("timeStamp" , String .valueOf (System .currentTimeMillis () / 1000 ));
519+ payInfo .put ("nonceStr" , System .currentTimeMillis () + "" );
520+ payInfo .put ("package" , "prepay_id=" + prepayId );
521+ payInfo .put ("signType" , "MD5" );
522+ if ("NATIVE" .equals (request .getTradeType ())) {
523+ payInfo .put ("codeUrl" , unifiedOrderResult .getCodeURL ());
524+ }
525+
526+ String finalSign = this .createSign (payInfo , this .wxMpService .getWxMpConfigStorage ().getPartnerKey ());
527+ payInfo .put ("paySign" , finalSign );
528+ return payInfo ;
529+ }
530+
494531}
0 commit comments