|
@@ -3,27 +3,24 @@ package com.miaxis.wx.service.impl;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
import com.github.wxpay.sdk.WXPay;
|
|
|
import com.github.wxpay.sdk.WXPayConfig;
|
|
|
import com.github.wxpay.sdk.WXPayConstants;
|
|
|
import com.github.wxpay.sdk.WXPayUtil;
|
|
|
import com.miaxis.common.config.WxPayConfigImpl;
|
|
|
import com.miaxis.common.config.WxpayConfig;
|
|
|
-import com.miaxis.common.core.domain.entity.SysDictData;
|
|
|
import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
-import com.miaxis.common.enums.OrderStatusEnum;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.RSAUtils;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
import com.miaxis.common.utils.XmlUtil;
|
|
|
+import com.miaxis.order.domain.OrderInfo;
|
|
|
+import com.miaxis.order.service.IOrderInfoService;
|
|
|
import com.miaxis.system.service.ISysConfigService;
|
|
|
import com.miaxis.user.service.IUserInfoService;
|
|
|
import com.miaxis.wx.domain.WxExtract;
|
|
|
import com.miaxis.wx.domain.WxExtractBank;
|
|
|
import com.miaxis.wx.domain.WxOrder;
|
|
|
-import com.miaxis.wx.dto.PcWxOrderListDTO;
|
|
|
-import com.miaxis.wx.dto.QuerySchoolOrderListDTO;
|
|
|
import com.miaxis.wx.dto.WxExtractBankDTO;
|
|
|
import com.miaxis.wx.mapper.WxOrderMapper;
|
|
|
import com.miaxis.wx.service.IWxExtractBankService;
|
|
@@ -31,10 +28,6 @@ import com.miaxis.wx.service.IWxExtractService;
|
|
|
import com.miaxis.wx.service.IWxOrderService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
-import org.apache.http.HttpResponse;
|
|
|
-import org.apache.http.client.HttpClient;
|
|
|
-import org.apache.http.client.methods.HttpPost;
|
|
|
-import org.apache.http.entity.StringEntity;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -42,7 +35,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
import java.util.TreeMap;
|
|
@@ -59,8 +51,6 @@ import static com.miaxis.common.utils.OrderCodeFactory.getOrderCode;
|
|
|
@Slf4j
|
|
|
public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> implements IWxOrderService {
|
|
|
|
|
|
- @Autowired
|
|
|
- private HttpClient httpClient;
|
|
|
|
|
|
@Resource
|
|
|
private WxOrderMapper wxOrderMapper;
|
|
@@ -68,6 +58,9 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
@Autowired
|
|
|
private IWxExtractService wxExtractService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IOrderInfoService orderInfoService;
|
|
|
+
|
|
|
@Autowired
|
|
|
private RSAUtils rsaUtils;
|
|
|
|
|
@@ -82,12 +75,96 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
@Autowired
|
|
|
private IWxExtractBankService wxExtractBankService;
|
|
|
|
|
|
- @Value("${gzh.appid}")
|
|
|
- private String appid;
|
|
|
-
|
|
|
- @Value("${xcx.appid}")
|
|
|
+ @Value("${xcx.appId}")
|
|
|
private String xcxAppid;
|
|
|
|
|
|
+ @Value("${xcx.mchId}")
|
|
|
+ private String mchId;
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public String wxAddFenZhang() throws Exception {
|
|
|
+ String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver";
|
|
|
+
|
|
|
+ String nonceStr = RandomStringUtils.randomAlphanumeric(32);
|
|
|
+ //用于签名
|
|
|
+ Map<String, String> sortMap = new TreeMap<String, String>();
|
|
|
+ sortMap.put("mch_id", mchId);
|
|
|
+ sortMap.put("appid", xcxAppid);
|
|
|
+ sortMap.put("nonce_str", nonceStr);
|
|
|
+ sortMap.put("sign_type", "HMAC-SHA256");
|
|
|
+ Map<String, String> receiverMap = new TreeMap<String, String>();
|
|
|
+ receiverMap.put("type", "PERSONAL_OPENID");
|
|
|
+ receiverMap.put("account", "o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
+ receiverMap.put("relation_type", "SERVICE_PROVIDER"); //合作合伙
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String receiverMapJson = objectMapper.writeValueAsString(receiverMap);
|
|
|
+ sortMap.put("receiver", receiverMapJson);
|
|
|
+
|
|
|
+ WXPayConfig config = new WxPayConfigImpl();
|
|
|
+ String sign = WXPayUtil.generateSignature(sortMap, config.getKey(), WXPayConstants.SignType.HMACSHA256);
|
|
|
+ sortMap.put("sign", sign);
|
|
|
+
|
|
|
+ WXPay pay = new WXPay(config);
|
|
|
+ String xmlStr = pay.requestWithoutCert(url, sortMap, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs());
|
|
|
+
|
|
|
+ Map<String, String> resMap = XmlUtil.xmlToMap(xmlStr);
|
|
|
+ if (!"SUCCESS".equals(resMap.get("return_code")) || !"SUCCESS".equals(resMap.get("result_code"))) {
|
|
|
+ throw new CustomException("微信添加分账出错");
|
|
|
+ }
|
|
|
+ System.out.println(xmlStr);
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
+ public String wxProfitsharing(WxOrder wxOrder) throws Exception {
|
|
|
+ String url = "https://api.mch.weixin.qq.com/secapi/pay/profitsharing";
|
|
|
+ String nonceStr = RandomStringUtils.randomAlphanumeric(32);
|
|
|
+ //用于签名
|
|
|
+ Map<String, String> sortMap = new TreeMap<String, String>();
|
|
|
+ sortMap.put("mch_id", mchId);
|
|
|
+ sortMap.put("appid", xcxAppid);
|
|
|
+ sortMap.put("nonce_str", nonceStr);
|
|
|
+ sortMap.put("sign_type", "HMAC-SHA256");
|
|
|
+ sortMap.put("transaction_id", wxOrder.getTransactionId());
|
|
|
+ String orderCode = getOrderCode(wxOrder.getUserId()); //商户分账单号
|
|
|
+ sortMap.put("out_order_no", orderCode);
|
|
|
+
|
|
|
+ //扣除手续费后
|
|
|
+ double commission = wxOrder.getTotal() * 0.01;
|
|
|
+ double total = wxOrder.getTotal() - commission;
|
|
|
+ int amount = (int) Math.floor(total * 0.3);
|
|
|
+
|
|
|
+ Map<String, Object> receiverMap = new TreeMap<String, Object>();
|
|
|
+ receiverMap.put("type", "PERSONAL_OPENID");
|
|
|
+ receiverMap.put("account", "o7N3j5XxUrgOKE4ulP-HseFpBCiM");
|
|
|
+ receiverMap.put("amount", amount);
|
|
|
+ receiverMap.put("description", "分到个人"); //合作合伙
|
|
|
+ ObjectMapper objectMapper = new ObjectMapper();
|
|
|
+ String receiverMapJson = objectMapper.writeValueAsString(receiverMap);
|
|
|
+ sortMap.put("receiver", receiverMapJson);
|
|
|
+
|
|
|
+ WXPayConfig config = new WxPayConfigImpl();
|
|
|
+ String sign = WXPayUtil.generateSignature(sortMap, config.getKey(), WXPayConstants.SignType.HMACSHA256);
|
|
|
+ sortMap.put("sign", sign);
|
|
|
+
|
|
|
+ WXPay pay = new WXPay(config);
|
|
|
+ String xmlStr = pay.requestWithoutCert(url, sortMap, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs());
|
|
|
+
|
|
|
+ //更新成交订单表
|
|
|
+ OrderInfo orderInfo = orderInfoService.getByOutTradeNo(wxOrder.getOutTradeNo());
|
|
|
+ orderInfo.setOutSplitNo(orderCode);
|
|
|
+ orderInfoService.updateById(orderInfo);
|
|
|
+
|
|
|
+ return null;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
@Override
|
|
@@ -106,14 +183,14 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
// }
|
|
|
|
|
|
Map<String, String> sortMap = new TreeMap<String, String>();
|
|
|
- sortMap.put("mch_appid",appid);
|
|
|
- sortMap.put("mchid",wxpayConfig.getMerchantId());
|
|
|
+ sortMap.put("mch_appid", mchId);
|
|
|
+ sortMap.put("mchid", wxpayConfig.getMerchantId());
|
|
|
sortMap.put("nonce_str", RandomStringUtils.randomAlphanumeric(32));
|
|
|
- sortMap.put("partner_trade_no",getOrderCode(null));
|
|
|
+ sortMap.put("partner_trade_no", getOrderCode(null));
|
|
|
//sortMap.put("openid",student.getGzhOpenid());
|
|
|
- sortMap.put("check_name","NO_CHECK");
|
|
|
- sortMap.put("amount",String.valueOf(amount));
|
|
|
- sortMap.put("desc","用户提现");
|
|
|
+ sortMap.put("check_name", "NO_CHECK");
|
|
|
+ sortMap.put("amount", String.valueOf(amount));
|
|
|
+ sortMap.put("desc", "用户提现");
|
|
|
|
|
|
WXPayConfig config = new WxPayConfigImpl();
|
|
|
String sign = WXPayUtil.generateSignature(sortMap, config.getKey(), WXPayConstants.SignType.MD5);
|
|
@@ -124,7 +201,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
Map<String, String> resMap;
|
|
|
String xmlStr = pay.requestWithCert(url, sortMap, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs());
|
|
|
resMap = XmlUtil.xmlToMap(xmlStr);
|
|
|
- if (!"SUCCESS".equals(resMap.get("return_code"))||!"SUCCESS".equals(resMap.get("result_code"))){
|
|
|
+ if (!"SUCCESS".equals(resMap.get("return_code")) || !"SUCCESS".equals(resMap.get("result_code"))) {
|
|
|
throw new CustomException(resMap.get("return_msg"));
|
|
|
}
|
|
|
//新增提现记录
|
|
@@ -152,20 +229,18 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
// }
|
|
|
|
|
|
Map<String, String> sortMap = new TreeMap<String, String>();
|
|
|
- sortMap.put("mch_id",wxpayConfig.getMerchantId());
|
|
|
+ sortMap.put("mch_id", wxpayConfig.getMerchantId());
|
|
|
sortMap.put("nonce_str", RandomStringUtils.randomAlphanumeric(32));
|
|
|
- sortMap.put("partner_trade_no",getOrderCode(null));
|
|
|
- sortMap.put("amount",String.valueOf(dto.getAmount()));
|
|
|
- sortMap.put("desc","用户银行卡提现");
|
|
|
-
|
|
|
-
|
|
|
+ sortMap.put("partner_trade_no", getOrderCode(null));
|
|
|
+ sortMap.put("amount", String.valueOf(dto.getAmount()));
|
|
|
+ sortMap.put("desc", "用户银行卡提现");
|
|
|
|
|
|
|
|
|
// 进行签名服务
|
|
|
|
|
|
- sortMap.put("enc_true_name",rsaUtils.encryptData(dto.getEncTrueName()) );
|
|
|
- sortMap.put("enc_bank_no",rsaUtils.encryptData(dto.getEncBankNo()));
|
|
|
- sortMap.put("bank_code",dto.getBankCode().toString());
|
|
|
+ sortMap.put("enc_true_name", rsaUtils.encryptData(dto.getEncTrueName()));
|
|
|
+ sortMap.put("enc_bank_no", rsaUtils.encryptData(dto.getEncBankNo()));
|
|
|
+ sortMap.put("bank_code", dto.getBankCode().toString());
|
|
|
|
|
|
|
|
|
WXPayConfig config = new WxPayConfigImpl();
|
|
@@ -177,7 +252,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
Map<String, String> resMap;
|
|
|
String xmlStr = pay.requestWithCert(url, sortMap, config.getHttpConnectTimeoutMs(), config.getHttpReadTimeoutMs());
|
|
|
resMap = XmlUtil.xmlToMap(xmlStr);
|
|
|
- if (!"SUCCESS".equals(resMap.get("return_code"))||!"SUCCESS".equals(resMap.get("result_code"))){
|
|
|
+ if (!"SUCCESS".equals(resMap.get("return_code")) || !"SUCCESS".equals(resMap.get("result_code"))) {
|
|
|
throw new CustomException(resMap.get("return_msg"));
|
|
|
}
|
|
|
//新增提现记录
|
|
@@ -190,7 +265,7 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
|
|
|
//如果此卡之前未存储,则加入到银行卡列表
|
|
|
List<WxExtractBank> bankList = wxExtractBankService.list(new QueryWrapper<WxExtractBank>().eq("enc_bank_no", dto.getEncBankNo()));
|
|
|
- if (CollectionUtils.isEmpty(bankList)){
|
|
|
+ if (CollectionUtils.isEmpty(bankList)) {
|
|
|
WxExtractBank wxExtractBank = new WxExtractBank();
|
|
|
wxExtractBank.setBankCode(dto.getBankCode());
|
|
|
wxExtractBank.setEncBankNo(dto.getEncBankNo());
|
|
@@ -208,45 +283,4 @@ public class WxOrderServiceImpl extends ServiceImpl<WxOrderMapper, WxOrder> impl
|
|
|
}
|
|
|
|
|
|
|
|
|
- @Override
|
|
|
- @Transactional
|
|
|
- public String wxfenZhang(Integer amount) throws Exception {
|
|
|
- HttpPost httpPost = initHttpPost("https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver");
|
|
|
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
|
- ObjectMapper objectMapper = new ObjectMapper();
|
|
|
-
|
|
|
- ObjectNode rootNode = objectMapper.createObjectNode();
|
|
|
- String nonceStr = RandomStringUtils.randomAlphanumeric(32);
|
|
|
- rootNode.put("mchid",wxpayConfig.getMerchantId());
|
|
|
- rootNode.put("appid",xcxAppid);
|
|
|
- rootNode.put("nonce_str", nonceStr);
|
|
|
-
|
|
|
- //用于签名
|
|
|
- Map<String,String> sortMap = new TreeMap<String,String>();
|
|
|
- sortMap.put("mchid",wxpayConfig.getMerchantId());
|
|
|
- sortMap.put("appid",xcxAppid);
|
|
|
- sortMap.put("nonce_str",nonceStr);
|
|
|
-
|
|
|
- WXPayConfig config = new WxPayConfigImpl();
|
|
|
- String sign = WXPayUtil.generateSignature(sortMap, config.getKey(), WXPayConstants.SignType.HMACSHA256);
|
|
|
- rootNode.put("sign", sign);
|
|
|
- rootNode.put("sign_type", "HMAC-SHA256");
|
|
|
-
|
|
|
- String url = "https://api.mch.weixin.qq.com/pay/profitsharingaddreceiver";
|
|
|
- httpPost.setEntity(new StringEntity(rootNode.toString(), "utf-8"));
|
|
|
- HttpResponse response = httpClient.execute(httpPost);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- private HttpPost initHttpPost(String url) {
|
|
|
- HttpPost httpPost = new HttpPost(url);
|
|
|
- httpPost.addHeader("Accept", "application/json");
|
|
|
- httpPost.addHeader("Content-type","application/json; charset=utf-8");
|
|
|
- return httpPost;
|
|
|
- }
|
|
|
-
|
|
|
}
|