|
|
@ -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; |
|
|
|
} |
|
|
|
} |
|
|
|