|
|
|
@ -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<String,String> 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<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", "分给商户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<String,String> 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 { |
|
|
|
|
|
|
|
|
|
//小程序退款需要调用双向证书的认证
|
|
|
|
|