|
|
@@ -7,15 +7,21 @@ import org.apache.commons.lang3.StringUtils;
|
|
|
import org.jeecg.common.zhutils.PayConst;
|
|
|
import org.jeecg.common.zhutils.PayRequest;
|
|
|
import org.jeecg.common.zhutils.RsaKeyProperties;
|
|
|
+import org.jeecg.modules.hlwpayaccount.entity.HlwPayAccount;
|
|
|
import org.jeecg.modules.hlwpayaccount.entity.HlwPayAccountCmb;
|
|
|
import org.jeecg.modules.hlwpayaccount.service.IHlwPayAccountCmbService;
|
|
|
+import org.jeecg.modules.hlwpayment.entity.HlwPaymentDetail;
|
|
|
import org.jeecg.modules.hlwsubcontractor.entity.HlwSubcontractor;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
import javax.annotation.PostConstruct;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+import java.util.Random;
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
|
* @Author: zwq
|
|
|
@@ -99,24 +105,15 @@ public class PayRsaCommon {
|
|
|
JSONObject obj_body = new JSONObject();
|
|
|
//funCode接口名称
|
|
|
String funCode = PayConst.NTAGTLS2;
|
|
|
- String accnbr = "";
|
|
|
- //获取支付账户信息
|
|
|
- QueryWrapper<HlwPayAccountCmb> queryWrapper = new QueryWrapper<>();
|
|
|
- queryWrapper.eq("subcontractor_id", hlgSubcontractor.getId());
|
|
|
- List<HlwPayAccountCmb> hlwPayAccountCmbList = iHlwPayAccountCmbService.list(queryWrapper);
|
|
|
- if (hlwPayAccountCmbList != null && hlwPayAccountCmbList.size() > 0) {
|
|
|
- accnbr = hlwPayAccountCmbList.get(0).getAccnbr();
|
|
|
- } else {
|
|
|
- //没有支付账户信息,则调用获取账户信息接口
|
|
|
- List<HlwPayAccountCmb> hlwPayAccountCmbList1 = DCLISACC(hlgSubcontractor);
|
|
|
- if (hlwPayAccountCmbList1 != null && hlwPayAccountCmbList1.size() > 0) {
|
|
|
- accnbr = hlwPayAccountCmbList1.get(0).getAccnbr();
|
|
|
- }
|
|
|
- }
|
|
|
+ //账户
|
|
|
+ HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlgSubcontractor);
|
|
|
+ /**
|
|
|
+ * 查询条件
|
|
|
+ */
|
|
|
JSONArray jsonArrayRequest = new JSONArray();
|
|
|
JSONObject jsonObjectRequest = new JSONObject();
|
|
|
jsonObjectRequest.put("buscod", hlgSubcontractor.getBuscod());
|
|
|
- jsonObjectRequest.put("accnbr", accnbr);
|
|
|
+ jsonObjectRequest.put("accnbr", hlwPayAccountCmb.getAccnbr());
|
|
|
jsonArrayRequest.add(jsonObjectRequest);
|
|
|
//查询条件
|
|
|
obj_body.put("ntagtls2x", jsonArrayRequest);
|
|
|
@@ -147,7 +144,174 @@ public class PayRsaCommon {
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
+ System.out.println("请求报错" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 代发经办
|
|
|
+ *
|
|
|
+ * @param hlgPaymentDetailList
|
|
|
+ * @param totalPayment
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static JSONObject DCAGPOPR(List<HlwPaymentDetail> hlgPaymentDetailList, String totalPayment, HlwSubcontractor hlgSubcontractor) {
|
|
|
+ JSONObject jsonObjectBody = null;
|
|
|
+ try {
|
|
|
+ // body
|
|
|
+ JSONObject obj_body = new JSONObject();
|
|
|
+ //支付总量
|
|
|
+ int payLength = hlgPaymentDetailList.size();
|
|
|
+ //funCode接口名称
|
|
|
+ String funCode = PayConst.NTAGCAPY;
|
|
|
+ //账户
|
|
|
+ HlwPayAccountCmb hlwPayAccountCmb = getAccnbr(hlgSubcontractor);
|
|
|
+ /**
|
|
|
+ * 模式信息
|
|
|
+ */
|
|
|
+ JSONArray jsonArrayRequest1 = new JSONArray();
|
|
|
+ JSONObject jsonObjectRequest1 = new JSONObject();
|
|
|
+ jsonObjectRequest1.put("busmod", hlgSubcontractor.getBusmod());
|
|
|
+ jsonArrayRequest1.add(jsonObjectRequest1);
|
|
|
+ /**
|
|
|
+ * 汇总信息
|
|
|
+ */
|
|
|
+ JSONArray jsonArrayRequest2 = new JSONArray();
|
|
|
+ JSONObject jsonObjectRequest2 = new JSONObject();
|
|
|
+ //批次开始标志,’Y’表示批次开始
|
|
|
+ jsonObjectRequest2.put("begtag", "Y");
|
|
|
+ //批次结束标志,’Y’表示批次结束
|
|
|
+ jsonObjectRequest2.put("endtag", "Y");
|
|
|
+ //总金额
|
|
|
+ jsonObjectRequest2.put("ttlamt", totalPayment);
|
|
|
+ //总笔数
|
|
|
+ jsonObjectRequest2.put("ttlcnt", String.valueOf(payLength));
|
|
|
+ //总次数(该批次数据计划分多少次上传完,代发代扣系统要求第一次就要必输)
|
|
|
+ jsonObjectRequest2.put("ttlnum", 1);
|
|
|
+ //本次金额
|
|
|
+ jsonObjectRequest2.put("curamt", totalPayment);
|
|
|
+ //本次笔数
|
|
|
+ jsonObjectRequest2.put("curcnt", String.valueOf(payLength));
|
|
|
+ //交易货币
|
|
|
+ jsonObjectRequest2.put("ccynbr", PayConst.ccynbr);
|
|
|
+ //分行号
|
|
|
+ jsonObjectRequest2.put("bbknbr", hlwPayAccountCmb.getBbknbr());
|
|
|
+ //账号
|
|
|
+ jsonObjectRequest2.put("accnbr", hlwPayAccountCmb.getAccnbr());
|
|
|
+ //货币市场
|
|
|
+ jsonObjectRequest2.put("ccymkt", "0");
|
|
|
+ //交易代码(代发类型),默认代发其他
|
|
|
+ jsonObjectRequest2.put("trstyp", hlgSubcontractor.getTrsTyp());
|
|
|
+ //用途
|
|
|
+ jsonObjectRequest2.put("nusage", PayConst.NUSAGE);
|
|
|
+ //对方参考号
|
|
|
+ //业务参考号采用时间戳+三位随机数
|
|
|
+ Random random = new Random();
|
|
|
+ String code = "";
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
|
+ code += random.nextInt(10);
|
|
|
+ }
|
|
|
+ String yurref = System.currentTimeMillis() + code;
|
|
|
+ jsonObjectRequest2.put("yurref", yurref);
|
|
|
+ jsonArrayRequest2.add(jsonObjectRequest2);
|
|
|
+ /**
|
|
|
+ * 明细信息
|
|
|
+ */
|
|
|
+ JSONArray jsonArrayRequest3 = new JSONArray();
|
|
|
+ for (int i = 0; i < payLength; i++) {
|
|
|
+ JSONObject trs = new JSONObject();
|
|
|
+ HlwPaymentDetail hlgPaymentDetail = hlgPaymentDetailList.get(i);
|
|
|
+ //交易序号
|
|
|
+ //为8位纯数字
|
|
|
+ int numLength = 8;
|
|
|
+ String trxseq = Stream.iterate(i + 1, item -> item + 1).limit(1)
|
|
|
+ .map(item -> String.valueOf(item))
|
|
|
+ .map(item -> {
|
|
|
+ while (item.length() < numLength) {
|
|
|
+ item = "0" + item;
|
|
|
+ }
|
|
|
+ return item;
|
|
|
+ }).iterator().next();
|
|
|
+ trs.put("trxseq", trxseq);
|
|
|
+ //账号
|
|
|
+ trs.put("accnbr", hlgPaymentDetail.getCardNumber());
|
|
|
+ //户名
|
|
|
+ trs.put("accnam", hlgPaymentDetail.getUserName());
|
|
|
+ //四舍五入,保留俩位小数
|
|
|
+ BigDecimal bg = BigDecimal.valueOf(hlgPaymentDetail.getNetPayment()).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ //金额
|
|
|
+ trs.put("trsamt", bg.toString());
|
|
|
+ //系统内标志(Y:开户行是招商银行;N:开户行是他行)
|
|
|
+ trs.put("bnkflg", hlgPaymentDetail.getBnkflg());
|
|
|
+ if ("N".equals(hlgPaymentDetail.getBnkflg())) {
|
|
|
+ //他行开户行
|
|
|
+ trs.put("eacbnk", hlgPaymentDetail.getEacbnk());
|
|
|
+ //他行开户地址
|
|
|
+ trs.put("eaccty", hlgPaymentDetail.getRcveaa());
|
|
|
+ } else {
|
|
|
+ //他行开户行
|
|
|
+ trs.put("eacbnk", "");
|
|
|
+ //他行开户地址
|
|
|
+ trs.put("eaccty", "");
|
|
|
+ }
|
|
|
+ jsonArrayRequest3.add(trs);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 请求报文
|
|
|
+ */
|
|
|
+ obj_body.put("ntbusmody", jsonArrayRequest1);
|
|
|
+ obj_body.put("ntagcagcx1", jsonArrayRequest2);
|
|
|
+ obj_body.put("ntagcdtly1", jsonArrayRequest3);
|
|
|
+ String result = PayRequest.doRequest(obj_body, funCode, hlgSubcontractor.getUserId(), hlgSubcontractor.getPaymentUrl(),
|
|
|
+ iRsaKeyProperties.getPublicKey(), iRsaKeyProperties.getPrivateKey(), iRsaKeyProperties.getAesKey());
|
|
|
+ if (StringUtils.isNotBlank(result)) {
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
|
+ JSONObject jsonObject1 = jsonObject.getJSONObject("response");
|
|
|
+ JSONObject jsonObjectHead = jsonObject1.getJSONObject("head");
|
|
|
+ String resultcode = jsonObjectHead.getString("resultcode");
|
|
|
+ //正常响应为SUC0000
|
|
|
+ if (PayConst.SUCCESS.equals(resultcode)) {
|
|
|
+ JSONObject jsonObject2 = jsonObject1.getJSONObject("body");
|
|
|
+ JSONArray jsonArrayBody = jsonObject2.getJSONArray("ntagcagcz1");
|
|
|
+ if (jsonArrayBody != null && jsonArrayBody.size() > 0) {
|
|
|
+ jsonObjectBody = jsonArrayBody.getJSONObject(0);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("resultcode========" + jsonObjectHead.getString("resultcode"));
|
|
|
+ System.out.println("resultmsg========" + jsonObjectHead.getString("resultmsg"));
|
|
|
+ }
|
|
|
+ return jsonObjectBody;
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return jsonObjectBody;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取支付账户信息
|
|
|
+ *
|
|
|
+ * @param hlwSubcontractor
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static HlwPayAccountCmb getAccnbr(HlwSubcontractor hlwSubcontractor) {
|
|
|
+ HlwPayAccountCmb hlwPayAccountCmb = new HlwPayAccountCmb();
|
|
|
+ //获取支付账户信息
|
|
|
+ QueryWrapper<HlwPayAccountCmb> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("subcontractor_id", hlwSubcontractor.getId());
|
|
|
+ List<HlwPayAccountCmb> hlwPayAccountCmbList = iHlwPayAccountCmbService.list(queryWrapper);
|
|
|
+ if (hlwPayAccountCmbList != null && hlwPayAccountCmbList.size() > 0) {
|
|
|
+ hlwPayAccountCmb = hlwPayAccountCmbList.get(0);
|
|
|
+ } else {
|
|
|
+ //没有支付账户信息,则调用获取账户信息接口
|
|
|
+ List<HlwPayAccountCmb> hlwPayAccountCmbList1 = DCLISACC(hlwSubcontractor);
|
|
|
+ if (hlwPayAccountCmbList1 != null && hlwPayAccountCmbList1.size() > 0) {
|
|
|
+ hlwPayAccountCmb = hlwPayAccountCmbList1.get(0);
|
|
|
+ }
|
|
|
}
|
|
|
+ return hlwPayAccountCmb;
|
|
|
}
|
|
|
|
|
|
|