@@ -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