|
|
@@ -1,10 +1,14 @@
|
|
|
package com.yc.ship.module.ota.service.distributorselfrecharge;
|
|
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.XML;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
|
|
|
+import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|
|
import com.yc.ship.framework.common.pojo.PageResult;
|
|
|
import com.yc.ship.framework.common.util.object.BeanUtils;
|
|
|
import com.yc.ship.framework.security.core.LoginUser;
|
|
|
import com.yc.ship.framework.tenant.core.util.TenantUtils;
|
|
|
+import com.yc.ship.module.infra.api.config.ConfigApi;
|
|
|
import com.yc.ship.module.ota.controller.admin.distributor.vo.LoginTypeRespVO;
|
|
|
import com.yc.ship.module.ota.controller.admin.distributorselfrecharge.vo.DistributorSelfRechargePageReqVO;
|
|
|
import com.yc.ship.module.ota.controller.admin.distributorselfrecharge.vo.DistributorSelfRechargeSaveReqVO;
|
|
|
@@ -26,6 +30,13 @@ import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
+import java.net.Socket;
|
|
|
+import java.net.SocketTimeoutException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.Random;
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
|
|
|
|
import static com.yc.ship.framework.common.exception.util.ServiceExceptionUtil.exception0;
|
|
|
@@ -59,6 +70,9 @@ public class DistributorSelfRechargeServiceImpl implements DistributorSelfRechar
|
|
|
@Resource
|
|
|
private TradeApi tradeApi;
|
|
|
|
|
|
+ @Resource
|
|
|
+ private ConfigApi configApi;
|
|
|
+
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -238,4 +252,129 @@ public class DistributorSelfRechargeServiceImpl implements DistributorSelfRechar
|
|
|
return tradeLogId.get();
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public void abcRemittance() {
|
|
|
+ log.info("abc对公转账充值");
|
|
|
+ String host = configApi.getPlatformConfigValueByKey("dgConfig_ip");
|
|
|
+ String portStr = configApi.getPlatformConfigValueByKey("dgConfig_port");
|
|
|
+ String name = configApi.getPlatformConfigValueByKey("dgConfig_name");
|
|
|
+ String yqtNo = configApi.getPlatformConfigValueByKey("dgConfig_no");
|
|
|
+ String yqtPro = configApi.getPlatformConfigValueByKey("dgConfig_pro");
|
|
|
+ String yqtCard = configApi.getPlatformConfigValueByKey("dgConfig_card");
|
|
|
+
|
|
|
+// String host = "10.1.10.105";
|
|
|
+ int port = 15999;
|
|
|
+ if(StringUtils.isNotBlank(portStr)){
|
|
|
+ try {
|
|
|
+ port = Integer.parseInt(portStr);
|
|
|
+ }catch (Exception ignored){
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ // 1. 获取当前时间,用于组装公共包头流水与日期
|
|
|
+ Date now = new Date();
|
|
|
+ String reqDate = new SimpleDateFormat("yyyyMMdd").format(now);
|
|
|
+ String reqTime = new SimpleDateFormat("HHmmss").format(now);
|
|
|
+ // 构造请求方流水号 (保证唯一性)
|
|
|
+ Random random = new Random();
|
|
|
+ int randomNumber2 = random.nextInt(1000) + 1000;
|
|
|
+ String reqSeqNo = new SimpleDateFormat("yyyyMMddHHmmss").format(now) + ""+randomNumber2+"";
|
|
|
+ // 2. 构造 CMLT40 增加多级账簿 XML 请求报文
|
|
|
+ String xmlData = "<ap>\n" +
|
|
|
+ " <CCTransCode>CQRA10</CCTransCode>\n" +
|
|
|
+ " <ProductID>ICC</ProductID>\n" +
|
|
|
+ " <ChannelType>ERP</ChannelType>\n" +
|
|
|
+ " <CorpNo>"+yqtNo+"</CorpNo>\n" +
|
|
|
+ " <OpNo></OpNo>\n" +
|
|
|
+ " <AuthNo></AuthNo>\n" +
|
|
|
+ " <ReqSeqNo>" + reqSeqNo + "</ReqSeqNo>\n" +
|
|
|
+ " <ReqDate>" + reqDate + "</ReqDate>\n" +
|
|
|
+ " <ReqTime>" + reqTime + "</ReqTime>\n" +
|
|
|
+ " <Sign></Sign>\n" +
|
|
|
+ " <Corp>\n" +
|
|
|
+ " <StartDate>0</StartDate>\n" +
|
|
|
+ " <EndDate>F</EndDate>\n" +
|
|
|
+ " </Corp>\n" +
|
|
|
+ " <Cmp>\n" +
|
|
|
+ " <DbProv>"+yqtPro+"</DbProv>\n" +
|
|
|
+ " <DbAccNo>"+yqtCard+"</DbAccNo>\n" +
|
|
|
+ " <DbCur>01</DbCur>\n" +
|
|
|
+ " <StartTime></StartTime>\n" +
|
|
|
+ " </Cmp>\n" +
|
|
|
+ "</ap>";
|
|
|
+
|
|
|
+ // 3. 按照约定编码报文 (ERP上送报文必须为GBK字符集)
|
|
|
+ byte[] xmlBytes = xmlData.getBytes("GBK");
|
|
|
+
|
|
|
+ // 4. 构造7字节包头
|
|
|
+ // 第1字节为加密标志(0-不加密),后6字节为数据包长度(包含加密标志位),不足6位在右边用空格补足
|
|
|
+// int packetLen = xmlBytes.length + 1;
|
|
|
+ int packetLen = xmlBytes.length;
|
|
|
+ String lengthStr = String.format("%-6s", packetLen);
|
|
|
+ String headerStr = "0" + lengthStr;
|
|
|
+ byte[] headerBytes = headerStr.getBytes("GBK");
|
|
|
+
|
|
|
+ // 拼接完整的待发送字节数组
|
|
|
+ byte[] fullPacket = new byte[headerBytes.length + xmlBytes.length];
|
|
|
+ System.arraycopy(headerBytes, 0, fullPacket, 0, headerBytes.length);
|
|
|
+ System.arraycopy(xmlBytes, 0, fullPacket, headerBytes.length, xmlBytes.length);
|
|
|
+
|
|
|
+ // 5. 发送 TCP/IP Socket 同步短连接请求
|
|
|
+ System.out.println("正在连接到前置机 " + host + ":" + port + "...");
|
|
|
+ Socket socket = new Socket(host, port);
|
|
|
+ // 设置读取超时时间为 30 秒
|
|
|
+// socket.setSoTimeout(30000);
|
|
|
+
|
|
|
+ OutputStream out = socket.getOutputStream();
|
|
|
+ out.write(fullPacket);
|
|
|
+ out.flush();
|
|
|
+ System.out.println("请求报文发送成功,等待响应...\n");
|
|
|
+ System.out.println("请求报文发送成功,等待响应...\n"+new String(fullPacket, "GBK"));
|
|
|
+
|
|
|
+ // 6. 接收并解析前置机返回的报文
|
|
|
+ InputStream in = socket.getInputStream();
|
|
|
+ byte[] buffer = new byte[1024];
|
|
|
+ int bytesRead;
|
|
|
+ // 使用 StringBuilder 拼接读取到的报文内容,必须以 GBK 解码
|
|
|
+ StringBuilder responseBuilder = new StringBuilder();
|
|
|
+
|
|
|
+ while ((bytesRead = in.read(buffer)) != -1) {
|
|
|
+ responseBuilder.append(new String(buffer, 0, bytesRead, "GBK"));
|
|
|
+ }
|
|
|
+
|
|
|
+ socket.close();
|
|
|
+ in.close();
|
|
|
+ out.close();
|
|
|
+
|
|
|
+ String recvData = responseBuilder.toString();
|
|
|
+ if (recvData.length() >= 7) {
|
|
|
+ String respHeader = recvData.substring(0, 7);
|
|
|
+ String respXml = recvData.substring(7);
|
|
|
+ System.out.println("收到前置机响应头: '" + respHeader + "'");
|
|
|
+ System.out.println("收到前置机响应报文:\n" + respXml);
|
|
|
+ JSONObject jsonObject = XML.toJSONObject(respXml);
|
|
|
+ System.out.println(jsonObject);
|
|
|
+
|
|
|
+ JSONObject ap = jsonObject.getJSONObject("ap");
|
|
|
+ String respCode = ap.getStr("RespCode");
|
|
|
+ if(!"0000".equals(respCode)){
|
|
|
+ System.err.println("交易发送异常,异常信息:"+ap.getStr("RespInfo"));
|
|
|
+ }else {
|
|
|
+ String resultCode = ap.getJSONObject("Cmp").getStr("DbLogAccNo");
|
|
|
+ System.err.println("卡号:" + resultCode);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ System.out.println("响应报文异常或为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (SocketTimeoutException e) {
|
|
|
+ System.err.println("交易发送超时,请检查ICT前置机通讯状态。");
|
|
|
+ } catch (Exception e) {
|
|
|
+ System.err.println("交易发送异常: " + e.getMessage());
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|