Browse Source

修改交行接口

master
zhaoyiran 5 months ago
parent
commit
b4cc876519
  1. 6
      src/main/java/com/win/bank/domain/BankDO.java
  2. 32
      src/main/java/com/win/bank/enums/BocomPayStatEnum.java
  3. 54
      src/main/java/com/win/bank/service/bocom/BocomServiceImpl.java

6
src/main/java/com/win/bank/domain/BankDO.java

@ -1,6 +1,7 @@
package com.win.bank.domain;
import java.math.BigDecimal;
import java.util.Date;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
@ -81,4 +82,9 @@ public class BankDO extends BaseDO {
* 流水号
*/
private String serialNumber;
/**
* 最后查询时间
*/
private Date lastQueryTime;
}

32
src/main/java/com/win/bank/enums/BocomPayStatEnum.java

@ -0,0 +1,32 @@
package com.win.bank.enums;
public enum BocomPayStatEnum {
INBANKPROCESSING("0", "银行处理中"), SUCCESS("1", "成功"), FAILED("2", "失败"), DOUBTFUL("3", "可疑"), RECORDNOTEXIST("4", "记录不存在"), TOBEAUTHORIZED("5", "待授权"), AUTHORIZATIONDENIAL("6", "授权拒绝");
private final String code;
private final String description;
BocomPayStatEnum(String code, String description) {
this.code = code;
this.description = description;
}
public String getCode() {
return code;
}
public String getDescription() {
return description;
}
public static BocomPayStatEnum getByCode(String code) {
for (BocomPayStatEnum status : BocomPayStatEnum.values()) {
if (status.getCode().equals(code)) {
return status;
}
}
throw new IllegalArgumentException("Invalid BocomPayStatEnum code: " + code);
}
}

54
src/main/java/com/win/bank/service/bocom/BocomServiceImpl.java

@ -18,6 +18,7 @@ import org.w3c.dom.Element;
import org.xml.sax.InputSource;
import com.win.bank.domain.BankDO;
import com.win.bank.enums.BocomPayStatEnum;
import com.win.bank.enums.PaymentStatusEnum;
import com.win.bank.service.BaseBankService;
import com.win.bank.service.bank.BankService;
@ -50,7 +51,7 @@ public class BocomServiceImpl implements BaseBankService {
@Override
public BankDO payment(BankDO bankDO) {
String trCode = "210201";
String trCode = "210205";
String bussinessCode = bankService.getBussinessCode(bankDO);
bankDO.setBusinessCode(bussinessCode);
String head = generateHeadMessage(trCode, bussinessCode);
@ -62,9 +63,6 @@ public class BocomServiceImpl implements BaseBankService {
body.append("<rcv_bank_name>").append(bankDO.getRcvBankName()).append("</rcv_bank_name>");
body.append("<rcv_acno>").append(bankDO.getRcvAccount().replaceAll("\\s+", "")).append("</rcv_acno>");
body.append("<rcv_acname>").append(bankDO.getRcvUserName()).append("</rcv_acname>");
if (StringUtils.isNotEmpty(bankDO.getRcvBankNumber())) {
body.append("<rcv_bank_no>").append(bankDO.getRcvBankNumber()).append("</rcv_bank_no>");
}
body.append("<cur_code>CNY</cur_code>");
body.append("<amt>").append(bankDO.getAmount()).append("</amt>");
body.append("<cert_no>").append(bussinessCode).append("</cert_no>");
@ -91,15 +89,15 @@ public class BocomServiceImpl implements BaseBankService {
Element headElement = (Element)document.getDocumentElement().getElementsByTagName("head").item(0);
String particularCode = headElement.getElementsByTagName("particular_code").item(0).getTextContent();
if (SUCCESS_CODE.equals(particularCode)) {
bankDO.setStatus(PaymentStatusEnum.SUCCESS.getCode());
bankDO.setStatus(PaymentStatusEnum.PAYING.getCode());
String serialNumber = headElement.getElementsByTagName("serial_no").item(0).getTextContent();
bankDO.setSerialNumber(serialNumber);
message = PaymentStatusEnum.PAYING.getDescription();
} else {
bankDO.setStatus(PaymentStatusEnum.FAILED.getCode());
}
message = headElement.getElementsByTagName("particular_info").item(0).getTextContent();
}
bankDO.setMessage(message);
} catch (Exception e) {
e.printStackTrace();
}
@ -109,6 +107,9 @@ public class BocomServiceImpl implements BaseBankService {
@Override
public BankDO queryPaymentResult(BankDO bankDO) {
if (!timeDifference(bankDO)) {
return null;
}
String trCode = "310204";
String bussinessCode = bankService.getBussinessCode(bankDO);
String head = generateHeadMessage(trCode, bussinessCode);
@ -130,19 +131,41 @@ public class BocomServiceImpl implements BaseBankService {
Element headElement = (Element)document.getDocumentElement().getElementsByTagName("head").item(0);
Element bodyElement = (Element)document.getDocumentElement().getElementsByTagName("body").item(0);
String particularCode = headElement.getElementsByTagName("particular_code").item(0).getTextContent();
if (SUCCESS_CODE.equals(particularCode)) {
bankDO.setStatus(PaymentStatusEnum.SUCCESS.getCode());
String description = "";
String stat = bodyElement.getElementsByTagName("stat").item(0).getTextContent();
String errMsg = bodyElement.getElementsByTagName("err_msg").item(0).getTextContent();
BocomPayStatEnum statEnum = BocomPayStatEnum.getByCode(stat);
String serialNumber = bodyElement.getElementsByTagName("ogl_serial_no").item(0).getTextContent();
switch (statEnum) {
case SUCCESS:
bankDO.setStatus(PaymentStatusEnum.SUCCESS.getCode());
break;
case INBANKPROCESSING:
case TOBEAUTHORIZED:
bankDO.setStatus(PaymentStatusEnum.PAYING.getCode());
description = statEnum.getDescription();
break;
default:
bankDO.setStatus(PaymentStatusEnum.FAILED.getCode());
description = statEnum.getDescription();
break;
}
bankDO.setSerialNumber(serialNumber);
if (StringUtils.isNotEmpty(errMsg)) {
description = description + errMsg;
}
bankDO.setMessage(description);
} else {
bankDO.setStatus(PaymentStatusEnum.FAILED.getCode());
}
message = headElement.getElementsByTagName("particular_info").item(0).getTextContent();
bankDO.setMessage(message);
}
bankDO.setLastQueryTime(new Date());
} catch (Exception e) {
e.printStackTrace();
}
return bankDO;
}
@ -156,4 +179,15 @@ public class BocomServiceImpl implements BaseBankService {
.append("</tr_time><atom_tr_count>1</atom_tr_count><channel>0</channel></head>");
return head.toString();
}
public boolean timeDifference(BankDO bankDO) {
if (bankDO.getLastQueryTime() == null) {
return true;
}
Date currentTime = new Date();
long timeDifference = currentTime.getTime() - bankDO.getLastQueryTime().getTime();
long minutesDifference = timeDifference / (60 * 1000);
return minutesDifference > 5;
}
}

Loading…
Cancel
Save