|
|
|
@@ -13,10 +13,7 @@ import com.iformall.domain.po.*; |
|
|
|
import com.iformall.enums.*; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
import com.iformall.mapper.*; |
|
|
|
import com.iformall.pay.WxPayment; |
|
|
|
import com.iformall.pay.WxProfitSharing; |
|
|
|
import com.iformall.pay.WxProfitSharingP; |
|
|
|
import com.iformall.pay.WxProfitSharingQueryP; |
|
|
|
import com.iformall.pay.*; |
|
|
|
import com.iformall.service.WxProfitSharingOrderService; |
|
|
|
import com.iformall.utils.BeanUtils; |
|
|
|
import com.iformall.utils.Utility; |
|
|
|
@@ -137,6 +134,7 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
public ResultData createSharingOrder(WxPayOrder wxPayOrder, Long merchantId) { |
|
|
|
//添加分账接受方 |
|
|
|
WxProfitSharingReceiver psReceiverQ = new WxProfitSharingReceiver(); |
|
|
|
@@ -152,7 +150,6 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
return createPSOrder(wxPayOrder, merchantId, psReceiverList, false); |
|
|
|
} |
|
|
|
|
|
|
|
@Transactional(isolation=Isolation.SERIALIZABLE, propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) |
|
|
|
private ResultData createPSOrder(WxPayOrder wxPayOrder, Long merchantId, List<WxProfitSharingReceiver> psReceiverList, boolean multiCmd) { |
|
|
|
final IdWorker idworker = IdWorker.get(); |
|
|
|
|
|
|
|
@@ -416,4 +413,49 @@ public class WxProfitSharingOrderServiceImpl implements WxProfitSharingOrderServ |
|
|
|
} |
|
|
|
return new ResultData(returnMap); |
|
|
|
} |
|
|
|
|
|
|
|
// 分账完结 |
|
|
|
private ResultData finishPSOrder(WxPayOrder wxPayOrder) { |
|
|
|
WxAppinfo appInfo = getAppinfo(wxPayOrder); |
|
|
|
WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); |
|
|
|
|
|
|
|
WxOrder wxOrder = wxOrderMapper.selectByPrimaryKey(wxPayOrder.getOrderId()); |
|
|
|
|
|
|
|
//分账提交 |
|
|
|
WxProfitSharingFinishP psFCmd = new WxProfitSharingFinishP(); |
|
|
|
psFCmd.setMch_id(payAccount.getMchId()); |
|
|
|
psFCmd.setSub_mch_id(payAccount.getSubMchId()); |
|
|
|
psFCmd.setAppid(appInfo.getParentAppId()); |
|
|
|
psFCmd.setNonce_str(Utility.generate32UUID()); |
|
|
|
psFCmd.setTransaction_id(wxPayOrder.getTransactionId()); |
|
|
|
psFCmd.setOut_order_no(wxPayOrder.getId().toString()); |
|
|
|
psFCmd.setSign_type("HMAC-SHA256"); |
|
|
|
|
|
|
|
String response; |
|
|
|
try { |
|
|
|
psFCmd.setSign(WxPayment.createSignHMAC(BeanUtils.toStringMap(psFCmd), payAccount.getApiKey())); |
|
|
|
response = WxProfitSharing.finishOrder(BeanUtils.toStringMap(psFCmd), payAccount.getCertPath(), payAccount.getMchId()); |
|
|
|
} catch (Exception e) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED); |
|
|
|
} |
|
|
|
|
|
|
|
logger.info("response: " + response); |
|
|
|
Map<String, String> returnMap = WxPayment.xmlToMap(response); |
|
|
|
String return_code = returnMap.get("return_code"); |
|
|
|
|
|
|
|
if (!"SUCCESS".equals(return_code)) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_REQUEST_FAILED.getCode(), returnMap.get("return_msg")); |
|
|
|
} |
|
|
|
|
|
|
|
if (!WxPayment.verifyNotifyHMAC(returnMap,payAccount.getApiKey())){ |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_RETURN_INVALID.getCode()); |
|
|
|
} |
|
|
|
|
|
|
|
String result_code = returnMap.get("result_code"); |
|
|
|
if (!"SUCCESS".equals(result_code)) { |
|
|
|
return new ResultData(ErrorCode.PROFIT_SHARING_APPLY_FAILED.getCode(), returnMap.get("err_code_des")); |
|
|
|
} |
|
|
|
|
|
|
|
return new ResultData(returnMap); |
|
|
|
} |
|
|
|
} |