|
|
@ -26,7 +26,9 @@ import org.springframework.beans.factory.annotation.Value; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@Service(value = "wxPayService") |
|
|
@ -122,9 +124,53 @@ public class WxPayServiceImpl implements WxPayService { |
|
|
|
String businessId = ContextUtil.getProject(); |
|
|
|
CereBusinessWxpay businessWxpay = cereBusinessWxpayService.getByBusinessId(Long.valueOf(businessId)); |
|
|
|
|
|
|
|
return wxPayStrategy.prepay(businessWxpay.getAppId(), businessWxpay.getAppAppId(), openid, |
|
|
|
Map<String, String> result = wxPayStrategy.prepay(businessWxpay.getAppId(), businessWxpay.getAppAppId(), openid, |
|
|
|
businessWxpay.getMchId(), app_notify_url, redirectUrl, ip, money, |
|
|
|
orderFormId, businessWxpay.getMchKey()); |
|
|
|
|
|
|
|
// 在支付成功后执行分账逻辑 |
|
|
|
if (result != null && "SUCCESS".equals(result.get("return_code"))) { |
|
|
|
String transactionId = result.get("transaction_id"); |
|
|
|
String outOrderNo = "PS_" + orderFormId; // 生成分账单号 |
|
|
|
List<Map<String, String>> receivers = new ArrayList<>(); |
|
|
|
// 添加分账接收方信息 |
|
|
|
Map<String, String> receiver = new HashMap<>(); |
|
|
|
receiver.put("type", "MERCHANT_ID"); |
|
|
|
receiver.put("account", "分账接收方商户号"); |
|
|
|
receiver.put("amount", money.multiply(new BigDecimal("0.8")).multiply(BigDecimal.valueOf(100)).intValue() + ""); |
|
|
|
receiver.put("description", "分账给接收方"); |
|
|
|
receivers.add(receiver); |
|
|
|
createProfitSharing(transactionId, outOrderNo, receivers); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建分账 |
|
|
|
* |
|
|
|
* @param transactionId 微信支付订单号 |
|
|
|
* @param outOrderNo 商户系统内部的分账单号 |
|
|
|
* @param receivers 分账接收方列表 |
|
|
|
* @return 分账结果 |
|
|
|
* @throws Exception |
|
|
|
*/ |
|
|
|
public Map<String, String> createProfitSharing(String transactionId, String outOrderNo, List<Map<String, String>> receivers) throws Exception { |
|
|
|
String businessId = ContextUtil.getProject(); |
|
|
|
CereBusinessWxpay businessWxpay = cereBusinessWxpayService.getByBusinessId(Long.valueOf(businessId)); |
|
|
|
|
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("transaction_id", transactionId); |
|
|
|
params.put("out_order_no", outOrderNo); |
|
|
|
params.put("receivers", receivers); |
|
|
|
|
|
|
|
JSONObject obj = wxPayV3Util.doPostWeixinV3(WXPayV3Util.api_v3_profitsharing_ur, JSON.toJSONString(params)); |
|
|
|
log.info("createProfitSharing result: {}", JSON.toJSONString(obj)); |
|
|
|
|
|
|
|
Map<String, String> result = new HashMap<>(); |
|
|
|
result.put("return_code", obj.getString("status")); |
|
|
|
result.put("return_msg", obj.getString("message")); |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|