| @@ -89,6 +89,33 @@ public class WxPayOrder extends TenantEntity { | |||
| } | |||
| return null; | |||
| } | |||
| public WxComposeChildOrderShare getSingleChildOrderShare() { | |||
| if (StringUtils.isBlank(this.childOrderShare)) { | |||
| return new WxComposeChildOrderShare(this.payAmount, this.shareAmount, this.rateAmount,null,null,null,null); | |||
| } | |||
| Map childs = JSON.parseObject(this.childOrderShare, Map.class); | |||
| for (Iterator<String> it = childs.keySet().iterator();it.hasNext();) { | |||
| JSONObject childOrderShare = (JSONObject) childs.get(it.hasNext()); | |||
| return new WxComposeChildOrderShare(childOrderShare.getInteger("realPayMent"), childOrderShare.getInteger("shareAmount"), childOrderShare.getInteger("rateAmount"), | |||
| childOrderShare.getInteger("realRateAmount"), childOrderShare.getInteger("commissionAmount"), | |||
| childOrderShare.getLong("merchantId"),childOrderShare.getString("merchantUid")); | |||
| } | |||
| return null; | |||
| } | |||
| public boolean isMulity() { | |||
| if (StringUtils.isBlank(this.childOrderShare)) { | |||
| return false; | |||
| } | |||
| Map childs = JSON.parseObject(this.childOrderShare, Map.class); | |||
| int size = childs.keySet().size(); | |||
| if (size > 1) { | |||
| return true; | |||
| } | |||
| return false; | |||
| } | |||
| @io.swagger.annotations.ApiModelProperty(value="支付失败原因",name="failReason") | |||
| private String failReason; | |||
| @io.swagger.annotations.ApiModelProperty(value="支付后结果来源(0:callback, 1:query)",name="payEndFrom") | |||
| @@ -10,8 +10,9 @@ import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils; | |||
| import com.github.binarywang.wxpay.exception.WxPayException; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.github.binarywang.wxpay.v3.util.RsaCryptoUtil; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.CombinePayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.PayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.CombinePayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.PayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.PayQueryReq; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -25,8 +26,12 @@ public class WxPayV3 { | |||
| private static final String MERCHANT_TRANSFER_QUERY_URL = "https://api.mch.weixin.qq.com/v3/transfer/batches/out-batch-no/%s"; | |||
| //电商收付通-普通支付-小程序下单 | |||
| private static final String PAY_COMMON_MINIAPP_URL = "https://api.mch.weixin.qq.com/v3/pay/partner/transactions/jsapi"; | |||
| //电商收付通-普通支付-查询 | |||
| private static final String PAY_COMMON_QUERY_URL = "https://api.mch.weixin.qq.com/v3/pay/partner/transactions/out-trade-no/%s"; | |||
| //电商收付通-普合单支付-小程序下单 | |||
| private static final String PAY_COMBINE_MINIAPP_URL = "https://api.mch.weixin.qq.com/v3/combine-transactions/jsapi"; | |||
| //电商收付通-合单支付-查询 | |||
| private static final String PAY_COMBINE_QUERY_URL = "https://api.mch.weixin.qq.com/v3/combine-transactions/out-trade-no/%s"; | |||
| private WxPayV3() { | |||
| } | |||
| @@ -84,6 +89,14 @@ public class WxPayV3 { | |||
| return payService.postV3WithWechatpaySerial(PAY_COMMON_MINIAPP_URL, JSON.toJSONString(payReq)); | |||
| } | |||
| /** | |||
| * 电商收付通-普通支付-查询 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_2_5.shtml | |||
| * @throws WxPayException | |||
| */ | |||
| public static String payCommonQuery(WxPayService payService,PayQueryReq payQuery) throws WxPayException { | |||
| return payService.postV3WithWechatpaySerial(String.format(PAY_COMMON_QUERY_URL, payQuery.getOut_trade_no()), JSON.toJSONString(payQuery)); | |||
| } | |||
| /** | |||
| * 电商收付通-合单支付-小程序下单https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_4.shtml | |||
| * @throws WxPayException | |||
| @@ -92,4 +105,13 @@ public class WxPayV3 { | |||
| return payService.postV3WithWechatpaySerial(PAY_COMBINE_MINIAPP_URL, JSON.toJSONString(payReq)); | |||
| } | |||
| /** | |||
| * 电商收付通-合单支付-查询 https://pay.weixin.qq.com/wiki/doc/apiv3_partner/apis/chapter7_3_11.shtml | |||
| * @throws WxPayException | |||
| */ | |||
| public static String payCombineQuery(WxPayService payService,PayQueryReq payQuery) throws WxPayException { | |||
| return payService.postV3WithWechatpaySerial(String.format(PAY_COMBINE_QUERY_URL, payQuery.getOut_trade_no()), null); | |||
| } | |||
| } | |||
| @@ -53,6 +53,29 @@ public class WxPayOrderServiceHelper { | |||
| } | |||
| } | |||
| public static EnumPayStatus getPayStatus(String trade_state) { | |||
| if ("SUCCESS".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_SUCCESS; | |||
| }else if ("REFUND".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_REFUND; | |||
| }else if ("NOTPAY".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_NOTPAY; | |||
| }else if ("CLOSED".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_CLOSE; | |||
| }else if ("REVOKED".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_REVERSE; | |||
| }else if ("USERPAYING".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_WAIT; | |||
| }else if ("PAYERROR".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_FAIL; | |||
| }else if ("FAIL".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_FAIL; | |||
| }else if ("ACCEPT".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_WAIT; | |||
| } | |||
| return null; | |||
| } | |||
| public static int getPayStatusFromMap(Map<String, String> returnMap,String payOrderNo) { | |||
| String return_code = returnMap.get("return_code"); | |||
| if ("SUCCESS".equalsIgnoreCase(return_code)) { | |||
| @@ -62,23 +85,10 @@ public class WxPayOrderServiceHelper { | |||
| if ("SUCCESS".equals(result_code)) { | |||
| String trade_state = returnMap.get("trade_state"); | |||
| //SUCCESS—支付成功,REFUND—转入退款,NOTPAY—未支付,CLOSED—已关闭,REVOKED—已撤销(刷卡支付),USERPAYING--用户支付中,PAYERROR--支付失败(其他原因,如银行返回失败) | |||
| if ("SUCCESS".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_SUCCESS.getCode(); | |||
| }else if ("REFUND".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_REFUND.getCode(); | |||
| }else if ("NOTPAY".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_NOTPAY.getCode(); | |||
| }else if ("CLOSED".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_CLOSE.getCode(); | |||
| }else if ("REVOKED".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_REVERSE.getCode(); | |||
| }else if ("USERPAYING".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_WAIT.getCode(); | |||
| }else if ("PAYERROR".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_FAIL.getCode(); | |||
| }else if ("FAIL".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_FAIL.getCode(); | |||
| } | |||
| EnumPayStatus payStatus = getPayStatus(trade_state); | |||
| if (null != payStatus) { | |||
| return payStatus.getCode(); | |||
| } | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询微信支付状态非法["+trade_state+"]"+payOrderNo); | |||
| }else { | |||
| String errCode = returnMap.get("err_code"); | |||
| @@ -100,21 +110,10 @@ public class WxPayOrderServiceHelper { | |||
| String result_code = returnMap.get("result_code"); | |||
| if ("SUCCESS".equals(result_code)) { | |||
| String trade_state = returnMap.get("trade_state"); | |||
| if ("SUCCESS".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_SUCCESS.getMessage(); | |||
| }else if ("REFUND".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_REFUND.getMessage(); | |||
| }else if ("NOTPAY".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_NOTPAY.getMessage(); | |||
| }else if ("CLOSED".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_CLOSE.getMessage(); | |||
| }else if ("REVOKED".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_REVERSE.getMessage(); | |||
| }else if ("USERPAYING".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_WAIT.getMessage(); | |||
| }else if ("PAYERROR".equals(trade_state)) { | |||
| return EnumPayStatus.PAY_STATUS_FAIL.getMessage(); | |||
| } | |||
| EnumPayStatus payStatus = getPayStatus(trade_state); | |||
| if (null != payStatus) { | |||
| return payStatus.getMessage(); | |||
| } | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询微信支付状态非法["+trade_state+"]"+payOrderNo); | |||
| }else { | |||
| String errCode = returnMap.get("err_code"); | |||
| @@ -489,7 +489,6 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| logger.debug("wxPayRecord md5 before:"+record.toString()); | |||
| String beforemd5 = HashUtil.md5(record.toString()); | |||
| WxProfitSharingReceiver receiver = payShareServie.getPayReceiver(); | |||
| PayAdapterResult payResult = payAdapterService.pay(payAccount, record,composeOrder,childOrders,productName,isShare,appInfo, currentDate, params); | |||
| String aftermd5 = HashUtil.md5(record.toString()); | |||
| if (beforemd5.equals(aftermd5)) { | |||
| @@ -615,9 +614,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| logger.debug("wxPayRecord md5 before:"+record.toString()); | |||
| String beforemd5 = HashUtil.md5(record.toString()); | |||
| WxProfitSharingReceiver receiver = payServiceFactory.getPayShareAdapterService(payWay.getCode(),payAccount.getPayVersion()).getPayReceiver(); | |||
| List<WxOrder> orderList = orderAdapterService.getChildOrders(composeOrder, appInfo.getTenantId()); | |||
| PayAdapterResult payResult = payServiceFactory.getPayAdapterService(payWay.getCode(),payAccount.getPayVersion()).pay(payAccount,receiver, record,composeOrder,orderList, | |||
| PayAdapterResult payResult = payServiceFactory.getPayAdapterService(payWay.getCode(),payAccount.getPayVersion()).pay(payAccount, record,composeOrder,orderList, | |||
| "付款码支付",isShare,appInfo, currentDate, params); | |||
| String aftermd5 = HashUtil.md5(record.toString()); | |||
| if (beforemd5.equals(aftermd5)) { | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.cashout.wx.v3.entity; | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import com.iformall.domain.po.WxAppinfo; | |||
| import com.iformall.domain.po.WxOrder; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.cashout.wx.v3.entity; | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import lombok.Data; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.cashout.wx.v3.entity; | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import java.util.List; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.cashout.wx.v3.entity; | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import lombok.Data; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.cashout.wx.v3.entity; | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import lombok.Data; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.cashout.wx.v3.entity; | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import lombok.Data; | |||
| @@ -0,0 +1,12 @@ | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import lombok.Data; | |||
| @Data | |||
| public class PayQueryReq { | |||
| private String sp_mchid;//服务商户号。 | |||
| private String sub_mchid;//二级商户号 | |||
| private String out_trade_no;//商户订单号 | |||
| } | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.cashout.wx.v3.entity; | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import lombok.Data; | |||
| @@ -1,4 +1,4 @@ | |||
| package com.iformall.service.pay.service.cashout.wx.v3.entity; | |||
| package com.iformall.service.pay.service.pay.wx.v3.entity; | |||
| import lombok.Data; | |||
| @@ -12,6 +12,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.alibaba.fastjson.JSON; | |||
| import com.alibaba.fastjson.JSONArray; | |||
| import com.alibaba.fastjson.JSONObject; | |||
| import com.github.binarywang.wxpay.service.WxPayService; | |||
| import com.iformall.common.ErrorCode; | |||
| @@ -29,20 +30,22 @@ import com.iformall.pay.WxPayOrderP; | |||
| import com.iformall.pay.WxPayOrderSP; | |||
| import com.iformall.pay.WxPayV3; | |||
| import com.iformall.pay.WxPayment; | |||
| import com.iformall.service.helper.WxPayOrderServiceHelper; | |||
| import com.iformall.service.order.entity.WxComposeChildOrderShare; | |||
| import com.iformall.service.order.entity.WxComposeOrder; | |||
| import com.iformall.service.pay.entity.PayExtraParam; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.CombineItemOrder; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.CombinePayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.CombinePayerReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.PayAmountReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.PayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.PaySettleReq; | |||
| import com.iformall.service.pay.service.cashout.wx.v3.entity.PayerReq; | |||
| import com.iformall.service.pay.service.pay.CDrivingPayService; | |||
| import com.iformall.service.pay.service.pay.entity.PayAdapterResult; | |||
| import com.iformall.service.pay.service.pay.entity.PayQueryAdapterResult; | |||
| import com.iformall.service.pay.service.pay.wx.v2.BaseWxPayAdapterService; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.CombineItemOrder; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.CombinePayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.CombinePayerReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.PayAmountReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.PayCommonMiniAppReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.PayQueryReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.PaySettleReq; | |||
| import com.iformall.service.pay.service.pay.wx.v3.entity.PayerReq; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.MaUtil; | |||
| import com.iformall.utils.MapUtil; | |||
| @@ -176,25 +179,74 @@ public class WxMiniAppPayV3AdapterService implements CDrivingPayService{ | |||
| return getOrderPResult(response); | |||
| } | |||
| } | |||
| private PayQueryAdapterResult getPayCommonQueryResult(String response) { | |||
| JSONObject result = JSON.parseObject(response); | |||
| String transtionId = result.getString("transaction_id"); | |||
| String tradeState = result.getString("trade_state"); | |||
| String tradeStateDesc = result.getString("trade_state_desc"); | |||
| String successTime = result.getString("success_time"); | |||
| EnumPayStatus payStatus = WxPayOrderServiceHelper.getPayStatus(tradeState); | |||
| if (null == payStatus) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询微信支付状态非法["+tradeState+"]"); | |||
| } | |||
| if (StringUtils.isBlank(tradeStateDesc)) { | |||
| tradeStateDesc = payStatus.getMessage(); | |||
| } | |||
| PayQueryAdapterResult qresult = new PayQueryAdapterResult(payStatus.getCode(), tradeStateDesc,null, response,transtionId,successTime); | |||
| return qresult; | |||
| } | |||
| private PayQueryAdapterResult getPayCombineQueryResult(String response) { | |||
| JSONObject result = JSON.parseObject(response); | |||
| JSONArray subOrders = result.getJSONArray("sub_orders"); | |||
| String transtionId = result.getString("transaction_id"); | |||
| String tradeState = result.getString("trade_state"); | |||
| String tradeStateDesc = result.getString("trade_state_desc"); | |||
| String successTime = result.getString("success_time"); | |||
| EnumPayStatus payStatus = WxPayOrderServiceHelper.getPayStatus(tradeState); | |||
| if (null == payStatus) { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "订单查询微信支付状态非法["+tradeState+"]"); | |||
| } | |||
| PayQueryAdapterResult qresult = new PayQueryAdapterResult(payStatus.getCode(), tradeStateDesc,null, response,transtionId,successTime); | |||
| return qresult; | |||
| } | |||
| @Override | |||
| public PayQueryAdapterResult queryPayStatus(WxPayOrder oldRecord, WxAppinfo appInfo, | |||
| WxPayAccount payAccount) throws Exception { | |||
| //return super.queryPayStatus(oldRecord,appInfo, payAccount); | |||
| return null; | |||
| WxPayService payService = maUtil.getWxPayService(appInfo, payAccount); | |||
| PayQueryReq req = new PayQueryReq(); | |||
| if (!oldRecord.isMulity()) { | |||
| req.setSp_mchid(payAccount.getMchId()); | |||
| req.setSub_mchid(oldRecord.getSingleChildOrderShare().getMerchantUid()); | |||
| req.setOut_trade_no(String.valueOf(oldRecord.getId())); | |||
| String response = WxPayV3.payCommonQuery(payService, req); | |||
| if (StringUtils.isBlank(response)){ | |||
| log.error("pay common v3 query response is null."+JSON.toJSONString(req)); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"pay common v3 query response is null."+JSON.toJSONString(req)); | |||
| } | |||
| return getPayCommonQueryResult(response); | |||
| }else { | |||
| req.setOut_trade_no(String.valueOf(oldRecord.getId())); | |||
| String response = WxPayV3.payCombineQuery(payService, req); | |||
| if (StringUtils.isBlank(response)){ | |||
| log.error("pay combine v3 query response is null."+JSON.toJSONString(req)); | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"pay common v3 query response is null."+JSON.toJSONString(req)); | |||
| } | |||
| return getPayCombineQueryResult(response); | |||
| } | |||
| } | |||
| @Override | |||
| public int queryPayStatus(PayQueryAdapterResult statusObject, String orderOutNo) throws Exception { | |||
| //return super.queryPayStatus(statusObject, orderOutNo); | |||
| return 0; | |||
| return getPayCommonQueryResult((String)statusObject.getData()).getCode(); | |||
| } | |||
| @Override | |||
| public int queryPayStatusCode(WxPayOrder oldRecord, WxAppinfo appInfo, WxPayAccount payAccount) | |||
| throws Exception { | |||
| //return super.queryPayStatusCode(oldRecord, appInfo, payAccount); | |||
| return 0; | |||
| return queryPayStatus(oldRecord, appInfo, payAccount).getCode(); | |||
| } | |||
| @Override | |||