|
|
@@ -1,11 +1,16 @@
|
|
|
package com.izouma.zhumj.service;
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
import com.github.binarywang.wxpay.bean.entpay.EntPayRequest;
|
|
|
import com.github.binarywang.wxpay.bean.entpay.EntPayResult;
|
|
|
import com.github.binarywang.wxpay.exception.WxPayException;
|
|
|
import com.github.binarywang.wxpay.service.WxPayService;
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.google.gson.GsonBuilder;
|
|
|
+import com.ijpay.wxpay.model.v3.Amount;
|
|
|
import com.izouma.zhumj.domain.*;
|
|
|
+import com.izouma.zhumj.dto.client.TransferResponseEntity;
|
|
|
import com.izouma.zhumj.enums.WithdrawApplyStatus;
|
|
|
import com.izouma.zhumj.enums.WithdrawMethod;
|
|
|
import com.izouma.zhumj.exception.BusinessException;
|
|
|
@@ -13,28 +18,38 @@ import com.izouma.zhumj.repo.CheckinInfoRepo;
|
|
|
import com.izouma.zhumj.repo.MemberRepo;
|
|
|
import com.izouma.zhumj.repo.UserMoneyWithdrawApplyRepo;
|
|
|
import com.izouma.zhumj.repo.UserRepo;
|
|
|
+import com.izouma.zhumj.utils.HttpUtil;
|
|
|
import com.izouma.zhumj.utils.SecurityUtils;
|
|
|
+import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
|
|
|
+import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
|
|
|
import jodd.util.StringUtil;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.aspectj.apache.bcel.classfile.Module;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.security.PrivateKey;
|
|
|
import java.time.LocalDateTime;
|
|
|
-import java.util.Optional;
|
|
|
+import java.util.*;
|
|
|
|
|
|
@Service
|
|
|
@Slf4j
|
|
|
@AllArgsConstructor
|
|
|
public class UserMoneyWithdrawApplyService {
|
|
|
- private UserMoneyWithdrawApplyRepo userMoneyWithdrawApplyRepo;
|
|
|
- private UserRepo userRepo;
|
|
|
- private UserMoneyRecordService userMoneyRecordService;
|
|
|
- private WxPayService wxPayService;
|
|
|
- private CheckinInfoRepo checkinInfoRepo;
|
|
|
- private MemberRepo memberRepo;
|
|
|
+ private static final Gson GSON = new GsonBuilder().create();
|
|
|
+ private UserMoneyWithdrawApplyRepo userMoneyWithdrawApplyRepo;
|
|
|
+ private UserRepo userRepo;
|
|
|
+ private UserMoneyRecordService userMoneyRecordService;
|
|
|
+ private WxPayService wxPayService;
|
|
|
+ private CheckinInfoRepo checkinInfoRepo;
|
|
|
+ private MemberRepo memberRepo;
|
|
|
// private AlipayClient alipayClient;
|
|
|
|
|
|
public UserMoneyWithdrawApply apply(Long userId, WithdrawMethod method, String account, String name) {
|
|
|
@@ -70,6 +85,64 @@ public class UserMoneyWithdrawApplyService {
|
|
|
return userMoneyWithdrawApplyRepo.save(apply);
|
|
|
}
|
|
|
|
|
|
+ private void sendApply(String openId, BigDecimal money, String tradeNo) {
|
|
|
+ //商户号
|
|
|
+ String mchid = "1611300657";
|
|
|
+ //申请商户号的appid或商户号绑定的appid(企业号corpid即为此appid)
|
|
|
+ String appId = "wx80d1b03fccb22538";
|
|
|
+ //用户在直连商户应用下的用户标示
|
|
|
+// String openId = openId;
|
|
|
+ //商户证书编号
|
|
|
+ String wechatPayserialNo = "5F10587C55EE72BCAB5C3C286400FF8199D58137";
|
|
|
+ //商户证书路径(在你本机测试时放你本机路径中的就可以)
|
|
|
+ String privatekeypath = "src/main/resources/cert/apiclient_key.pem";
|
|
|
+
|
|
|
+
|
|
|
+ Map<String, Object> postMap = new HashMap<String, Object>();
|
|
|
+
|
|
|
+ //商家批次单号 长度 1~32
|
|
|
+// String outNo = IdUtil.getSnowflake(0, 0).nextIdStr();
|
|
|
+
|
|
|
+ postMap.put("appid", appId);
|
|
|
+ postMap.put("out_batch_no", tradeNo);
|
|
|
+ //该笔批量转账的名称
|
|
|
+ postMap.put("batch_name", "转账");
|
|
|
+ //转账说明,UTF8编码,最多允许32个字符
|
|
|
+ postMap.put("batch_remark", "转账");
|
|
|
+ //转账金额单位为“分”。 总金额
|
|
|
+ postMap.put("total_amount", money.multiply(BigDecimal.valueOf(100)));
|
|
|
+ //。转账总笔数
|
|
|
+ postMap.put("total_num", 1);
|
|
|
+
|
|
|
+
|
|
|
+ List<Map> list = new ArrayList<>();
|
|
|
+ Map<String, Object> subMap = new HashMap<>(4);
|
|
|
+ //商家明细单号
|
|
|
+ subMap.put("out_detail_no", tradeNo);
|
|
|
+ //转账金额
|
|
|
+ subMap.put("transfer_amount", money.multiply(BigDecimal.valueOf(100)));
|
|
|
+ //转账备注
|
|
|
+ subMap.put("transfer_remark", "提现");
|
|
|
+ //用户在直连商户应用下的用户标示
|
|
|
+ subMap.put("openid", openId);
|
|
|
+// subMap.put("user_name", RsaCryptoUtil.encryptOAEP(userName, x509Certificate));
|
|
|
+ list.add(subMap);
|
|
|
+ postMap.put("transfer_detail_list", list);
|
|
|
+
|
|
|
+ //发起转账操作
|
|
|
+ String resStr = HttpUtil.postTransBatRequest(
|
|
|
+ "https://api.mch.weixin.qq.com/v3/transfer/batches",
|
|
|
+ GSON.toJson(postMap),
|
|
|
+ wechatPayserialNo,
|
|
|
+ mchid,
|
|
|
+ privatekeypath);
|
|
|
+ TransferResponseEntity transferResponseEntity = GSON.fromJson(resStr, TransferResponseEntity.class);
|
|
|
+ if (StringUtils.isNotBlank(transferResponseEntity.getCode())) {
|
|
|
+ throw new BusinessException("转账失败:" + transferResponseEntity.getCode() + transferResponseEntity
|
|
|
+ .getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void pass(Long id) {
|
|
|
UserMoneyWithdrawApply apply = userMoneyWithdrawApplyRepo.findById(id)
|
|
|
.orElseThrow(new BusinessException("无记录"));
|
|
|
@@ -106,20 +179,7 @@ public class UserMoneyWithdrawApplyService {
|
|
|
}
|
|
|
break;
|
|
|
case WECHAT:
|
|
|
- try {
|
|
|
- EntPayRequest request = new EntPayRequest();
|
|
|
- request.setPartnerTradeNo(apply.getTradeNo());
|
|
|
- request.setAmount(apply.getAmount().multiply(BigDecimal.valueOf(100)).intValue());
|
|
|
- request.setOpenid(user.getOpenId());
|
|
|
- request.setCheckName("NO_CHECK");
|
|
|
- request.setDescription(body);
|
|
|
- request.setSpbillCreateIp("192.168.31.12");
|
|
|
- EntPayResult result = wxPayService.getEntPayService().entPay(request);
|
|
|
- result.checkResult(wxPayService, "MD5", true);
|
|
|
- } catch (WxPayException e) {
|
|
|
- log.error("余额提现失败", e);
|
|
|
- throw new BusinessException(e.getMessage());
|
|
|
- }
|
|
|
+ sendApply(user.getOpenId(), apply.getAmount(), apply.getTradeNo());
|
|
|
break;
|
|
|
// case ALIPAY:
|
|
|
// AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest();
|