diff --git a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java index 1aa10324..4b9f5567 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/OutRechargeOrderController.java @@ -9,6 +9,7 @@ import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.SysCode; import com.hai.common.pay.WechatPayUtil; import com.hai.common.pay.entity.WeChatPayReqInfo; +import com.hai.common.pay.util.HttpReqUtil; import com.hai.common.pay.util.MD5Util; import com.hai.common.pay.util.XmlUtil; import com.hai.common.pay.util.sdk.WXPayConstants; @@ -327,6 +328,8 @@ public class OutRechargeOrderController { } } + + public String doRefundRequest(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 @@ -359,33 +362,40 @@ public class OutRechargeOrderController { @RequestMapping(value = "/wxProfitsharing", method = RequestMethod.GET) @ResponseBody - @ApiOperation(value = "订单退款") + @ApiOperation(value = "分账") public ResponseData wxProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { try { Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); //param.put("sub_mch_id" , "1289663601"); - param.put("sub_mch_id" , "1609882817"); // 个体黎杨珍 - param.put("transaction_id" , "4200001165202106115006937316"); + param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 + param.put("transaction_id" , "4200001152202106114622919776"); param.put("out_order_no" , String.valueOf(new Date().getTime())); param.put("nonce_str" , WxUtils.makeNonStr()); - // 分账金额 - BigDecimal porofitSharingAmount = amount; + BigDecimal rake = new BigDecimal("0.01"); + + // 计算微信收取的手续费 支付金额 * 0.002 + // 向“最接近的”数字舍入,如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 + BigDecimal wxHandlingFee = amount.multiply(new BigDecimal("0.002")).setScale(2,BigDecimal.ROUND_HALF_DOWN); + BigDecimal price = amount.subtract(wxHandlingFee); + + // 计算分账金额 手续费后的价格 * 0.01 + // 向“最接近的”数字舍入,如果与两个相邻数字的距离相等,则为上舍入的舍入模式。 + BigDecimal profitSharingAmount = price.multiply(rake).setScale(2,BigDecimal.ROUND_DOWN); List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); - receiversMap.put("account", "1603942866");// 嗨加油 - receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); - receiversMap.put("description", "分给商户1289663601"); + receiversMap.put("account", "1604968055");// 个体户方涛 + receiversMap.put("amount", profitSharingAmount.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.doRefundRequest2(param.get("mch_id"),null, WxUtils.mapToXml(param)); - // 请求分账返回的结果 ResultProfitSharing resultProfitSharing = XmlUtil.getObjectFromXML(resultXmL, ResultProfitSharing.class); return ResponseMsgUtil.success(resultProfitSharing); @@ -404,6 +414,28 @@ public class OutRechargeOrderController { return ResponseMsgUtil.success(e); } } + + @RequestMapping(value = "/wxSelectProfitsharing", method = RequestMethod.GET) + @ResponseBody + @ApiOperation(value = "查询剩余分账金额") + public ResponseData wxSelectProfitsharing(String transaction_id,String out_order_no, BigDecimal amount) { + try { + Map param = new LinkedHashMap<>(); + param.put("mch_id", "1289663601"); + //param.put("sub_mch_id" , "1609882817"); // 个体户黎杨珍 + param.put("transaction_id" , "4200001152202106114622919776"); + ///param.put("out_order_no" , String.valueOf(new Date().getTime())); + param.put("nonce_str" , WxUtils.makeNonStr()); + String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); + param.put("sign", signStr); + String unifiedXmL = WxUtils.mapToXml(param); + return ResponseMsgUtil.success(HttpReqUtil.HttpsDefaultExecute("POST", "https://api.mch.weixin.qq.com/pay/profitsharingorderamountquery", null, unifiedXmL, null)); + + } catch (Exception e) { + log.error("CmsContentController --> getCorporateAdvertising() error!", e); + return ResponseMsgUtil.success(e); + } + } public String doRefundRequest2(String mchId, String url, String data) throws Exception { //小程序退款需要调用双向证书的认证 diff --git a/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java b/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java index bd6d156e..12962365 100644 --- a/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java +++ b/hai-cweb/src/main/java/com/cweb/controller/pay/WechatPayController.java @@ -120,7 +120,7 @@ public class WechatPayController { WxSharingReceiversVO receiversVO = new WxSharingReceiversVO(); receiversVO.setAccount("1604968055"); receiversVO.setType("MERCHANT_ID"); - receiversVO.setName("嗨加油"); + receiversVO.setName("个体户方涛"); receiversVO.setRelation_type("SERVICE_PROVIDER"); Map map = new HashMap<>(); diff --git a/hai-cweb/src/main/resources/dev/application.yml b/hai-cweb/src/main/resources/dev/application.yml index dcf08e5d..eed35273 100644 --- a/hai-cweb/src/main/resources/dev/application.yml +++ b/hai-cweb/src/main/resources/dev/application.yml @@ -9,7 +9,7 @@ debug: false #datasource数据源设置 spring: datasource: - url: jdbc:mysql://139.159.177.244:3306/hsg_pre?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false + url: jdbc:mysql://139.159.177.244:3306/hfkj?allowMultiQueries=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false username: root password: HF123456. type: com.alibaba.druid.pool.DruidDataSource diff --git a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java index 37e96fab..3f1d5dd1 100644 --- a/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java +++ b/hai-service/src/main/java/com/hai/service/pay/impl/GoodsOrderServiceImpl.java @@ -133,8 +133,15 @@ public class GoodsOrderServiceImpl implements PayService { try { Thread.sleep(60*1000); BigDecimal rake = new BigDecimal("0.01"); - BigDecimal profitSharingAmount = order.getPayRealPrice().multiply(rake); + + // 计算微信收取的手续费 支付金额 * 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(); } @@ -149,7 +156,7 @@ public class GoodsOrderServiceImpl implements PayService { Map param = new LinkedHashMap<>(); param.put("appid", "wx637bd6f7314daa46"); param.put("mch_id", "1289663601"); - param.put("sub_mch_id" , "1609882817"); + 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()); @@ -160,9 +167,9 @@ public class GoodsOrderServiceImpl implements PayService { List> receiversList = new ArrayList<>(); Map receiversMap = new LinkedHashMap<>(); receiversMap.put("type", "MERCHANT_ID"); - receiversMap.put("account", "1603942866"); + receiversMap.put("account", "1604968055"); receiversMap.put("amount", porofitSharingAmount.multiply(new BigDecimal("100")).intValue()); - receiversMap.put("description", "分给商户1603942866"); + receiversMap.put("description", "分给商户【个体户方涛】"); receiversList.add(receiversMap); param.put("receivers" , JSONObject.toJSONString(receiversList)); String signStr = WxUtils.generateSignature(param, "Skufk5oi85wDFGl888i6wsRSTkdd5df5" , WXPayConstants.SignType.HMACSHA256); @@ -194,8 +201,8 @@ public class GoodsOrderServiceImpl implements PayService { */ KeyStore keyStore = KeyStore.getInstance("PKCS12"); //P12文件目录 证书路径,这里需要你自己修改,linux下还是windows下的根路径 - //FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); - FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); + FileInputStream instream = new FileInputStream("/home/project/wx_cert/1289663601_apiclient_cert.p12"); + // FileInputStream instream = new FileInputStream("G:\\hurui-project/hai-parent/hai-service/src/main/java/privatekey/1289663601_apiclient_cert.p12"); try { keyStore.load(instream, "1289663601".toCharArray());//这里写密码..默认是你的MCHID } finally {