提交代码

dev-discount
胡锐 3 years ago
parent a2163d8b35
commit 48ae277b5d
  1. 2
      hai-cweb/src/main/java/com/cweb/controller/HighTestController.java
  2. 14
      hai-cweb/src/main/java/com/cweb/controller/pay/OrderController.java
  3. 8
      hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java
  4. 2
      hai-service/src/main/java/com/hai/config/WxOrderConfig.java
  5. 111
      hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java

File diff suppressed because one or more lines are too long

@ -183,6 +183,8 @@ public class OrderController {
map.put("body","购买产品");
map.put("subject","购买产品");
// 是否分账
String profitSharing = "N";
//微信支付
String nonce_str = MD5Util.MD5Encode(String.valueOf(ThreadLocalRandom.current().nextInt(10000)), "UTF-8");
int total_fee = MathUtils.objectConvertBigDecimal(map.get("payPrice")).multiply(new BigDecimal("100")).intValue();
@ -199,12 +201,12 @@ public class OrderController {
weChatPayReqInfo.setSub_mch_id(SysConst.getSysConfig().getWxGzSubMchId());//商户号
} else if (order.getHighChildOrderList().get(0).getGoodsType() == 3) {
weChatPayReqInfo.setSub_mch_id("1609882817");//商户号
weChatPayReqInfo.setSub_mch_id("1624126902"); // 浩联商户号
profitSharing = "Y";
} else {
//子商户号
weChatPayReqInfo.setSub_mch_id(SysConst.getSysConfig().getWxSubMchId());
}
//子商户号
// weChatPayReqInfo.setOpenid(openId);
weChatPayReqInfo.setSub_openid(openId);
@ -216,7 +218,8 @@ public class OrderController {
weChatPayReqInfo.setNotify_url(SysConst.getSysConfig().getNotifyUrl()); //通知url
weChatPayReqInfo.setTrade_type("JSAPI"); //交易类型
weChatPayReqInfo.setAttach(map.get("orderScene").toString());
weChatPayReqInfo.setProfit_sharing("N");
weChatPayReqInfo.setProfit_sharing(profitSharing);
//附加数据,区分订单类型
Map<String,String> payMap = new HashMap<>();
@ -224,6 +227,9 @@ public class OrderController {
payMap.put("api_key",SysConst.getSysConfig().getWxApiKey());
payMap.put("unified_order_url",SysConst.getSysConfig().getWxUnifiedOrderUrl());
SortedMap<Object, Object> sortedMap = wechatPayUtil.goWechatPay(weChatPayReqInfo,payMap);
order.setExt1(weChatPayReqInfo.getSub_appid());
highOrderService.updateOrderDetail(order);
return ResponseMsgUtil.success(sortedMap);
} catch (Exception e) {
log.error("orderToPay error!", e);

@ -148,16 +148,16 @@ public class WechatPayController {
try {
WxSharingReceiversVO receiversVO = new WxSharingReceiversVO();
receiversVO.setAccount("1611202250");
receiversVO.setAccount("1603942866");
receiversVO.setType("MERCHANT_ID");
receiversVO.setName("重庆众卡汇电子商务有限公司");
receiversVO.setName("重庆惠昕石化有限责任公司");
receiversVO.setRelation_type("SERVICE_PROVIDER");
Map<String , String> map = new HashMap<>();
map.put("mch_id" , "1289663601");
map.put("sub_mch_id" , "1607303848");
map.put("appid" , "wx637bd6f7314daa46");
map.put("sub_mch_id" , "1624126902");
map.put("appid" , "wxa075e8509802f826");
map.put("nonce_str" , WxUtils.makeNonStr());
map.put("sign_type" , "HMAC-SHA256");
map.put("receiver" , JSONObject.toJSONString(receiversVO));

@ -67,7 +67,7 @@ public class WxOrderConfig {
Map<String,String> param = new HashMap<>();
param.put("appid", "wx637bd6f7314daa46");
param.put("mch_id", "1289663601");
param.put("sub_mch_id" , "1609882817");
param.put("sub_mch_id" , "1624126902");
param.put("nonce_str", WxUtils.makeNonStr());
param.put("transaction_id", paySerialNo);
param.put("out_refund_no", "HFR"+new Date().getTime());

@ -380,33 +380,64 @@ public class GoodsOrderServiceImpl implements PayService {
highOrderService.updateOrder(order);
new Thread(() -> {
try {
Thread.sleep(120*1000);
BigDecimal rake = new BigDecimal("0.01");
// 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。
BigDecimal wxHandlingFee = order.getPayRealPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN);
BigDecimal price = order.getPayRealPrice().subtract(wxHandlingFee);
// 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。
BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN);
this.wxProfitsharing(order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
if (order.getHighChildOrderList().get(0).getGoodsType().equals(3)) {
new Thread(() -> {
try {
Thread.sleep(120*1000);
BigDecimal rake = new BigDecimal("0.05");
// 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。
BigDecimal wxHandlingFee = order.getPayRealPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN);
BigDecimal price = order.getPayRealPrice().subtract(wxHandlingFee);
// 计算分账金额 手续费后的价格 * 0.05 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。
BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN);
this.wxGasProfitsharing(order.getExt1(), order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
} else {
new Thread(() -> {
try {
Thread.sleep(120*1000);
BigDecimal rake = new BigDecimal("0.01");
// 计算微信收取的手续费 支付金额 * 0.002 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。
BigDecimal wxHandlingFee = order.getPayRealPrice().multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN);
BigDecimal price = order.getPayRealPrice().subtract(wxHandlingFee);
// 计算分账金额 手续费后的价格 * 0.01 注:如果与两个相邻数字的距离相等,则为上舍入的舍入模式。
BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN);
this.wxProfitsharing(order.getExt1(), order.getPaySerialNo(),order.getOrderNo(),profitSharingAmount);
} catch (InterruptedException e) {
e.printStackTrace();
}
}).start();
}
}
}
}
public static void main(String[] args) {
BigDecimal totalPrice = new BigDecimal("100");
public void wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) {
BigDecimal wxHandlingFee = totalPrice.multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN);
System.out.println("手续费:" + wxHandlingFee);
BigDecimal price = totalPrice.subtract(wxHandlingFee);
System.out.println("扣除手机费后的价格:" + price);
BigDecimal profitSharingAmount = price.multiply(new BigDecimal("0.05")).setScale(2,BigDecimal.ROUND_DOWN);
System.out.println("实际分账价格:" + profitSharingAmount);
}
public void wxGasProfitsharing(String appid, String transaction_id,String out_order_no, BigDecimal amount) {
try {
Map<String,String> param = new LinkedHashMap<>();
param.put("appid", "wx637bd6f7314daa46");
param.put("appid", appid);
param.put("mch_id", "1289663601");
param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍
param.put("sub_mch_id" , "1624126902"); // 渝北区浩联物资经营部
param.put("transaction_id" , transaction_id);
param.put("out_order_no" , out_order_no);
param.put("nonce_str" , WxUtils.makeNonStr());
@ -444,6 +475,48 @@ public class GoodsOrderServiceImpl implements PayService {
}
}
public void wxProfitsharing(String appid,String transaction_id,String out_order_no, BigDecimal amount) {
try {
Map<String,String> param = new LinkedHashMap<>();
param.put("appid", appid);
param.put("mch_id", "1289663601");
param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍
param.put("transaction_id" , transaction_id);
param.put("out_order_no" , out_order_no);
param.put("nonce_str" , WxUtils.makeNonStr());
// 分账金额
BigDecimal porofitSharingAmount = amount;
List<Map<String,Object>> receiversList = new ArrayList<>();
Map<String,Object> receiversMap = new LinkedHashMap<>();
receiversMap.put("type", "MERCHANT_ID");
receiversMap.put("account", "1603942866");
receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue());
receiversMap.put("description", "分给商户【惠昕石化】");
receiversList.add(receiversMap);
param.put("receivers" , JSONObject.toJSONString(receiversList));
String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256);
param.put("sign" , signStr);
String resultXmL = this.doRefundRequest(param.get("mch_id"),null, WxUtils.mapToXml(param));
// 请求分账返回的结果
ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class);
HighProfitSharingRecord sharingRecord = new HighProfitSharingRecord();
sharingRecord.setOutOrderNo(out_order_no);
sharingRecord.setTransactionId(transaction_id);
sharingRecord.setOrderId(resultProfitSharing.getOrder_id());
sharingRecord.setStatus(resultProfitSharing.getResult_code());
sharingRecord.setPrice(amount);
sharingRecord.setCreateTime(new Date());
sharingRecord.setContent(resultXmL);
highProfitSharingRecordService.insert(sharingRecord);
} catch (Exception e) {
log.error("CmsContentController --> getCorporateAdvertising() error!", e);
}
}
public CloseableHttpClient readCertificate(String mchId) throws Exception{
/**

Loading…
Cancel
Save