From: Tang Cheng Date: Tue, 6 Aug 2019 12:07:35 +0000 (+0800) Subject: 重构前置接口 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=5fa34727e350dc3827527acc9f2e4f8f968495bd;p=epayment%2Ffood_payapi.git 重构前置接口 --- diff --git a/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentPayService.java b/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentPayService.java index 9b10dfc1..b681a940 100644 --- a/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentPayService.java +++ b/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentPayService.java @@ -2,14 +2,14 @@ package com.supwisdom.dlpay.agent; import com.supwisdom.dlpay.api.domain.TTransactionMain; -public interface AgentPayService { - AgentResponse auth(String agentid, String billno); +public interface AgentPayService { + AgentResponse auth(String agentid, String billno); - AgentResponse pay(TTransactionMain transaction); + AgentResponse pay(TTransactionMain transaction); - AgentResponse cancel(TTransactionMain transaction); + AgentResponse cancel(TTransactionMain transaction); - AgentResponse refund(TTransactionMain transaction); + AgentResponse refund(TTransactionMain transaction); - AgentResponse query(TTransactionMain transaction); + AgentResponse query(TTransactionMain transaction); } diff --git a/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentResponse.java b/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentResponse.java index d07cba56..a8dde971 100644 --- a/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentResponse.java +++ b/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentResponse.java @@ -1,62 +1,72 @@ package com.supwisdom.dlpay.agent; -public class AgentResponse { - public static final String AGENTCODE_SUCCESS = "0"; +public class AgentResponse { + public static final String AGENTCODE_SUCCESS = "0"; - public static final String AGENTCODE_FAIL = "1"; + public static final String AGENTCODE_FAIL = "1"; - private AgentCode code; - private String agentCode; - private String agentMsg; - private String agentBody; - private String agentRefno; - private DtlStatus dtlStatus; + private AgentCode code; + private String agentCode; + private String agentMsg; + private String agentBody; + private String agentRefno; + private DtlStatus dtlStatus; - public String getAgentBody() { - return agentBody; - } + private T payload; - public void setAgentBody(String agentBody) { - this.agentBody = agentBody; - } + public String getAgentBody() { + return agentBody; + } - public AgentCode getCode() { - return code; - } + public void setAgentBody(String agentBody) { + this.agentBody = agentBody; + } - public void setCode(AgentCode code) { - this.code = code; - } + public AgentCode getCode() { + return code; + } - public String getAgentCode() { - return agentCode; - } + public void setCode(AgentCode code) { + this.code = code; + } - public void setAgentCode(String agentCode) { - this.agentCode = agentCode; - } + public String getAgentCode() { + return agentCode; + } - public String getAgentMsg() { - return agentMsg; - } + public void setAgentCode(String agentCode) { + this.agentCode = agentCode; + } - public void setAgentMsg(String agentMsg) { - this.agentMsg = agentMsg; - } + public String getAgentMsg() { + return agentMsg; + } - public String getAgentRefno() { - return agentRefno; - } + public void setAgentMsg(String agentMsg) { + this.agentMsg = agentMsg; + } - public void setAgentRefno(String agentRefno) { - this.agentRefno = agentRefno; - } + public String getAgentRefno() { + return agentRefno; + } - public DtlStatus getDtlStatus() { - return dtlStatus; - } + public void setAgentRefno(String agentRefno) { + this.agentRefno = agentRefno; + } - public void setDtlStatus(DtlStatus dtlStatus) { - this.dtlStatus = dtlStatus; - } + public DtlStatus getDtlStatus() { + return dtlStatus; + } + + public void setDtlStatus(DtlStatus dtlStatus) { + this.dtlStatus = dtlStatus; + } + + public T getPayload() { + return payload; + } + + public void setPayload(T payload) { + this.payload = payload; + } } diff --git a/payapi/src/main/java/com/supwisdom/dlpay/agent/CheckFileProvider.java b/payapi/src/main/java/com/supwisdom/dlpay/agent/CheckFileProvider.java index 964b460d..88c7f80b 100644 --- a/payapi/src/main/java/com/supwisdom/dlpay/agent/CheckFileProvider.java +++ b/payapi/src/main/java/com/supwisdom/dlpay/agent/CheckFileProvider.java @@ -1,9 +1,11 @@ package com.supwisdom.dlpay.agent; +import com.supwisdom.dlpay.api.domain.TSourceTypeCheckStatus; + public interface CheckFileProvider { - AgentResponse acquireCheckFile(String checkDate); + AgentResponse acquireCheckFile(String checkDate); - AgentResponse queryCheckFile(String checkDate); + AgentResponse queryCheckFile(String checkDate); - AgentResponse downloadCheckFile(String checkDate); + AgentResponse downloadCheckFile(String checkDate); } diff --git a/payapi/src/main/java/com/supwisdom/dlpay/framework/util/ApplicationUtil.java b/payapi/src/main/java/com/supwisdom/dlpay/framework/util/ApplicationUtil.java index 35236893..7e51071a 100644 --- a/payapi/src/main/java/com/supwisdom/dlpay/framework/util/ApplicationUtil.java +++ b/payapi/src/main/java/com/supwisdom/dlpay/framework/util/ApplicationUtil.java @@ -10,11 +10,11 @@ import org.springframework.context.ApplicationContext; public class ApplicationUtil { private static final Logger logger = LoggerFactory.getLogger(ApplicationUtil.class); - public static AgentPayService findAgentPayService(ApplicationContext context, String service) { + public static AgentPayService findAgentPayService(ApplicationContext context, String service) { try { Object bean = context.getBean(service); if (bean instanceof AgentPayService) { - return (AgentPayService) bean; + return (AgentPayService) bean; } else { return null; } diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/alipay_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/alipay_service.kt index 0174c653..553f157c 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/alipay_service.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/alipay_service.kt @@ -3,6 +3,7 @@ package com.supwisdom.dlpay.agent.service import com.supwisdom.dlpay.agent.AgentCode import com.supwisdom.dlpay.agent.AgentPayService import com.supwisdom.dlpay.agent.AgentResponse +import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.api.bean.BaseResp import com.supwisdom.dlpay.api.domain.TTransactionMain import com.supwisdom.dlpay.api.service.ConsumePayService @@ -11,51 +12,47 @@ import com.supwisdom.dlpay.framework.util.TradeDict import org.springframework.stereotype.Component interface AlipayService { - fun doQrcodepay(transaction: TTransactionMain): AgentResponse + fun doQrcodepay(transaction: TTransactionMain): AgentResponse - fun doPrepay(transaction: TTransactionMain): AgentResponse + fun doPrepay(transaction: TTransactionMain): AgentResponse - fun doRefund(transaction: TTransactionMain): AgentResponse + fun doRefund(transaction: TTransactionMain): AgentResponse - fun doQuery(transaction: TTransactionMain): AgentResponse + fun doQuery(transaction: TTransactionMain): AgentResponse - fun doNotify(param: Map): AgentResponse + fun doNotify(param: Map): AgentResponse - /** - * 下载对账单 - * */ - fun downloadBill(shopacc:String,accdate:String): BaseResp } @Component("alipayAgent") class AlipayAgentService(val consumePayService: ConsumePayService, - val aipayService: AlipayService) : AgentPayService { + val aipayService: AlipayService) : AgentPayService { - override fun auth(shopaccno: String?, billno: String?): AgentResponse { + override fun auth(shopaccno: String?, billno: String?): AgentResponse { if (consumePayService.checkShopPaytype(shopaccno!!, TradeDict.PAYTYPE_ALIPAY, true)) { //TODO 支付宝实名认证逻辑 } - return AgentResponse().apply { + return AgentResponse().apply { this.code = AgentCode.NOT_SUPPORT } } - override fun pay(transaction: TTransactionMain): AgentResponse { + override fun pay(transaction: TTransactionMain): AgentResponse { return when (transaction.transCode) { TradeCode.TRANSCODE_QRCODE -> aipayService.doQrcodepay(transaction) else -> aipayService.doPrepay(transaction) } } - override fun cancel(transaction: TTransactionMain): AgentResponse { + override fun cancel(transaction: TTransactionMain): AgentResponse { return refund(transaction) } - override fun refund(transaction: TTransactionMain): AgentResponse { + override fun refund(transaction: TTransactionMain): AgentResponse { return aipayService.doRefund(transaction) } - override fun query(transaction: TTransactionMain): AgentResponse { + override fun query(transaction: TTransactionMain): AgentResponse { return aipayService.doQuery(transaction) } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/balance_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/balance_service.kt index 6852f9b2..3966cff0 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/balance_service.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/balance_service.kt @@ -3,37 +3,38 @@ package com.supwisdom.dlpay.agent.service import com.supwisdom.dlpay.agent.AgentCode import com.supwisdom.dlpay.agent.AgentPayService import com.supwisdom.dlpay.agent.AgentResponse +import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.api.domain.TTransactionMain import org.springframework.stereotype.Component @Component("balanceAgent") -class BalanceAgentService : AgentPayService { - private val responseCode = AgentResponse().apply { +class BalanceAgentService : AgentPayService { + private val responseCode = AgentResponse().apply { code = AgentCode.SUCCESS agentCode = "0" agentMsg = "成功" agentRefno = "" } - override fun auth(shopaccno: String?, billno: String?): AgentResponse { - return AgentResponse().apply { + override fun auth(shopaccno: String?, billno: String?): AgentResponse { + return AgentResponse().apply { this.code = AgentCode.NOT_SUPPORT } } - override fun pay(transaction: TTransactionMain): AgentResponse { + override fun pay(transaction: TTransactionMain): AgentResponse { return responseCode } - override fun cancel(transaction: TTransactionMain): AgentResponse { + override fun cancel(transaction: TTransactionMain): AgentResponse { return responseCode } - override fun refund(transaction: TTransactionMain): AgentResponse { + override fun refund(transaction: TTransactionMain): AgentResponse { return responseCode } - override fun query(transaction: TTransactionMain): AgentResponse { + override fun query(transaction: TTransactionMain): AgentResponse { return responseCode } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/citizencard_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/citizencard_service.kt index 5136d37b..586d819b 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/citizencard_service.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/citizencard_service.kt @@ -7,6 +7,7 @@ import com.supwisdom.dlpay.agent.DtlStatus import com.supwisdom.dlpay.agent.citizencard.DlpayResp import com.supwisdom.dlpay.agent.citizencard.YnrccRespCode import com.supwisdom.dlpay.agent.citizencard.YnrccUtil +import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.api.domain.TTransactionMain import com.supwisdom.dlpay.framework.util.MoneyUtil import org.springframework.beans.factory.annotation.Autowired @@ -28,7 +29,7 @@ interface CitizencardPayService { } @Component("citizenCardAgent") -class CitizenCardPayAgent : AgentPayService { +class CitizenCardPayAgent : AgentPayService { @Autowired private lateinit var citizencardPayService: CitizencardPayService @@ -43,17 +44,17 @@ class CitizenCardPayAgent : AgentPayService { YnrccRespCode(code, msg ?: "未知")) } - override fun auth(shopaccno: String?, billno: String?): AgentResponse { - return AgentResponse().apply { + override fun auth(shopaccno: String?, billno: String?): AgentResponse { + return AgentResponse().apply { this.code = AgentCode.NOT_SUPPORT } } - override fun pay(transaction: TTransactionMain): AgentResponse { + override fun pay(transaction: TTransactionMain): AgentResponse { val resp = citizencardPayService.cardPay(transaction.shopDtl.shopaccno, transaction.personDtl.userid, transaction.accdate, MoneyUtil.YuanToFen(transaction.personDtl.amount), transaction.refno) - return AgentResponse().also { + return AgentResponse().also { val code = agentCode(resp.code, resp.message) it.code = code.first it.agentCode = code.second.code @@ -62,15 +63,15 @@ class CitizenCardPayAgent : AgentPayService { } } - override fun cancel(transaction: TTransactionMain): AgentResponse { + override fun cancel(transaction: TTransactionMain): AgentResponse { return refund(transaction) } - override fun refund(transaction: TTransactionMain): AgentResponse { + override fun refund(transaction: TTransactionMain): AgentResponse { val resp = citizencardPayService.cardPayRefund(transaction.refno, transaction.accdate, transaction.reverseRefno, MoneyUtil.YuanToFen(transaction.personDtl.amount)) - return AgentResponse().also { + return AgentResponse().also { val code = agentCode(resp.code, resp.message) it.code = code.first it.agentCode = code.second.code @@ -79,10 +80,10 @@ class CitizenCardPayAgent : AgentPayService { } } - override fun query(transaction: TTransactionMain): AgentResponse { + override fun query(transaction: TTransactionMain): AgentResponse { val resp = citizencardPayService.queryResult(transaction.refno) - return AgentResponse().also { + return AgentResponse().also { val code = agentCode(resp.code, resp.message) it.code = code.first it.agentCode = code.second.code diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/alipay_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/alipay_service_impl.kt index 2f075ef1..0bcb1bf4 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/alipay_service_impl.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/alipay_service_impl.kt @@ -1,31 +1,31 @@ package com.supwisdom.dlpay.agent.service.impl -import com.supwisdom.dlpay.agent.AgentCode -import com.supwisdom.dlpay.agent.AgentResponse -import com.supwisdom.dlpay.agent.service.AlipayService -import com.supwisdom.dlpay.api.service.SourceTypeService -import com.supwisdom.dlpay.framework.util.TradeDict -import com.supwisdom.dlpay.util.PaytypeUtil -import mu.KotlinLogging -import org.springframework.stereotype.Service -import com.alipay.api.request.AlipayTradePayRequest +import com.alipay.api.AlipayApiException import com.alipay.api.DefaultAlipayClient import com.alipay.api.domain.AlipayTradePayModel -import com.supwisdom.dlpay.agent.service.AgentServiceProxy -import com.supwisdom.dlpay.api.domain.TTransactionMain -import com.alipay.api.AlipayApiException +import com.alipay.api.domain.AlipayTradeQueryModel +import com.alipay.api.domain.AlipayTradeRefundModel import com.alipay.api.internal.util.AlipaySignature import com.alipay.api.request.AlipayTradeAppPayRequest -import com.supwisdom.dlpay.api.service.ConsumePayService -import com.supwisdom.dlpay.api.service.TransactionServiceProxy +import com.alipay.api.request.AlipayTradePayRequest import com.alipay.api.request.AlipayTradeQueryRequest -import com.supwisdom.dlpay.agent.DtlStatus -import com.alipay.api.domain.AlipayTradeQueryModel -import com.alipay.api.domain.AlipayTradeRefundModel import com.supwisdom.dlpay.RestTemplateConfig -import com.supwisdom.dlpay.api.bean.BaseResp +import com.supwisdom.dlpay.agent.AgentCode +import com.supwisdom.dlpay.agent.AgentResponse +import com.supwisdom.dlpay.agent.DtlStatus +import com.supwisdom.dlpay.agent.domain.QrcodePayTrans +import com.supwisdom.dlpay.agent.service.AgentServiceProxy +import com.supwisdom.dlpay.agent.service.AlipayService +import com.supwisdom.dlpay.api.domain.TTransactionMain +import com.supwisdom.dlpay.api.service.ConsumePayService +import com.supwisdom.dlpay.api.service.SourceTypeService +import com.supwisdom.dlpay.api.service.TransactionServiceProxy import com.supwisdom.dlpay.framework.util.StringUtil import com.supwisdom.dlpay.framework.util.TradeCode +import com.supwisdom.dlpay.framework.util.TradeDict +import com.supwisdom.dlpay.util.PaytypeUtil +import mu.KotlinLogging +import org.springframework.stereotype.Service @Service @@ -37,7 +37,7 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, : AlipayService { val logger = KotlinLogging.logger { } - fun checkCfg(config: Map, resp: AgentResponse): Boolean { + fun checkCfg(config: Map, resp: AgentResponse): Boolean { if (config[PaytypeUtil.CFG_ALIPAY_APPID].isNullOrEmpty() || config[PaytypeUtil.CFG_ALIPAY_PRIVATEKEY].isNullOrEmpty() || config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY].isNullOrEmpty()) { @@ -72,13 +72,13 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, }.build() } - override fun doQrcodepay(transaction: TTransactionMain): AgentResponse { + override fun doQrcodepay(transaction: TTransactionMain): AgentResponse { val qrcodePayTrans = agentServiceProxy.qrcodePayTransFindByRefno(transaction.refno) val config = sourceTypeService.getConsumePaytypeConfig( TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, qrcodePayTrans.isAnonymous, false) - val agentResponse = AgentResponse() + val agentResponse = AgentResponse() if (checkCfg(config, agentResponse)) { val request = AlipayTradePayRequest() request.bizModel = AlipayTradePayModel().apply { @@ -125,11 +125,11 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun doPrepay(transaction: TTransactionMain): AgentResponse { + override fun doPrepay(transaction: TTransactionMain): AgentResponse { val config = sourceTypeService.getConsumePaytypeConfig( TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false) - val agentResponse = AgentResponse() + val agentResponse = AgentResponse() if (checkCfg(config, agentResponse)) { if (config[PaytypeUtil.CFG_ALIPAY_NOTIFY].isNullOrEmpty()) { agentResponse.code = AgentCode.CONFIG_ERROR @@ -182,8 +182,8 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun doRefund(transaction: TTransactionMain): AgentResponse { - val agentResponse = AgentResponse() + override fun doRefund(transaction: TTransactionMain): AgentResponse { + val agentResponse = AgentResponse() val config = sourceTypeService.getConsumePaytypeConfig( TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false) @@ -209,8 +209,8 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun doQuery(transaction: TTransactionMain): AgentResponse { - val agentResponse = AgentResponse() + override fun doQuery(transaction: TTransactionMain): AgentResponse { + val agentResponse = AgentResponse() val config = sourceTypeService.getConsumePaytypeConfig( TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false) if (checkCfg(config, agentResponse)) { @@ -239,9 +239,9 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun doNotify(param: Map): AgentResponse { + override fun doNotify(param: Map): AgentResponse { val refno = param["out_trade_no"] - val agentResponse = AgentResponse() + val agentResponse = AgentResponse() if (refno.isNullOrEmpty()) { agentResponse.code = AgentCode.FAIL return agentResponse @@ -281,8 +281,4 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, } } } - - override fun downloadBill(shopacc: String, accdate: String): BaseResp { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/wechat_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/wechat_service_impl.kt index 1e0f5f23..61fa7347 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/wechat_service_impl.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/wechat_service_impl.kt @@ -3,6 +3,7 @@ package com.supwisdom.dlpay.agent.service.impl import com.supwisdom.dlpay.agent.AgentCode import com.supwisdom.dlpay.agent.AgentResponse import com.supwisdom.dlpay.agent.DtlStatus +import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.agent.service.AgentServiceProxy import com.supwisdom.dlpay.agent.service.WechatService import com.supwisdom.dlpay.api.bean.BaseResp @@ -33,7 +34,7 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, val logger = KotlinLogging.logger { } - fun checkCfg(config: Map, resp: AgentResponse): Boolean { + fun checkCfg(config: Map, resp: AgentResponse): Boolean { if (config[PaytypeUtil.CFG_WECHAT_APPID].isNullOrEmpty() || config[PaytypeUtil.CFG_WECHAT_MECHKEY].isNullOrEmpty() || config[PaytypeUtil.CFG_WECHAT_MECHID].isNullOrEmpty()) { @@ -46,14 +47,15 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, return true } - override fun doAuth(shopaccno: String?, billno: String?): AgentResponse { - var qrcodeTrans = agentServiceProxy.qrcodePayTransFindByMerchIdAndBillno(shopaccno, billno) - var agentResponse = AgentResponse() + override fun doAuth(shopaccno: String?, billno: String?): AgentResponse { + val qrcodeTrans = agentServiceProxy.qrcodePayTransFindByMerchIdAndBillno(shopaccno, billno) + val agentResponse = AgentResponse() if (qrcodeTrans == null) { agentResponse.code = AgentCode.REFNO_NOT_EXISTS agentResponse.agentCode = AgentResponse.AGENTCODE_FAIL return agentResponse } + agentResponse.payload = qrcodeTrans val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_WECHAT, shopaccno, qrcodeTrans.isAnonymous, false) if (checkCfg(config, agentResponse)) { val bean = WechatReqResp().apply { @@ -63,21 +65,21 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, this.key = config[PaytypeUtil.CFG_WECHAT_MECHKEY] } bean.generalCheckSign() - var xml = bean.generalCheckXML() + val xml = bean.generalCheckXML() restTemplate.messageConverters[1] = StringHttpMessageConverter(StandardCharsets.UTF_8) - var res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_OAUTHCODE, xml, String::class.java) - var eleMap = XmlUtils.parseXml(res.body) - var retcode = eleMap["return_code"] - var resultCode = eleMap["result_code"] - var openid = eleMap["openid"] + val res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_OAUTHCODE, xml, String::class.java) + val eleMap = XmlUtils.parseXml(res.body) + val retcode = eleMap["return_code"] + val resultCode = eleMap["result_code"] + val openid = eleMap["openid"] if (!retcode.isNullOrEmpty() && "SUCCESS" == retcode && !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode && !openid.isNullOrEmpty()) { qrcodeTrans.agentUserId = openid - var ip = personIdentityDao.getByThirdUid(openid) + val ip = personIdentityDao.getByThirdUid(openid) if (ip != null) { qrcodeTrans.userid = ip.person.userid } - agentServiceProxy.qrcodePayTransSaveOrUpdate(qrcodeTrans) + agentResponse.payload = agentServiceProxy.qrcodePayTransSaveOrUpdate(qrcodeTrans) agentResponse.code = AgentCode.SUCCESS agentResponse.agentCode = retcode agentResponse.agentMsg = eleMap["return_msg"] @@ -91,14 +93,15 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun doQrcodepay(transaction: TTransactionMain): AgentResponse { - var qrcodeTrans = agentServiceProxy.qrcodePayTransFindByRefno(transaction.refno) - var agentResponse = AgentResponse() + override fun doQrcodepay(transaction: TTransactionMain): AgentResponse { + val qrcodeTrans = agentServiceProxy.qrcodePayTransFindByRefno(transaction.refno) + val agentResponse = AgentResponse() if (qrcodeTrans == null) { agentResponse.code = AgentCode.REFNO_NOT_EXISTS agentResponse.agentCode = AgentResponse.AGENTCODE_FAIL return agentResponse } + agentResponse.payload = qrcodeTrans val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_WECHAT, transaction.shopDtl.shopaccno, qrcodeTrans.isAnonymous, false) if (checkCfg(config, agentResponse)) { val bean = WechatReqResp().apply { @@ -113,14 +116,14 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, } bean.generalPaySign() - var xml = bean.generaPayXML() + val xml = bean.generaPayXML() restTemplate.messageConverters[1] = StringHttpMessageConverter(StandardCharsets.UTF_8) - var res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_QRCODEPAY, xml, String::class.java) - var eleMap = XmlUtils.parseXml(res.body) - var retcode = eleMap["return_code"] - var resultCode = eleMap["result_code"] - var openid = eleMap["openid"] - var errorCode = eleMap["err_code"] + val res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_QRCODEPAY, xml, String::class.java) + val eleMap = XmlUtils.parseXml(res.body) + val retcode = eleMap["return_code"] + val resultCode = eleMap["result_code"] + val openid = eleMap["openid"] + val errorCode = eleMap["err_code"] if (!retcode.isNullOrEmpty() && "SUCCESS" == retcode && !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode && !openid.isNullOrEmpty()) { agentResponse.code = AgentCode.SUCCESS @@ -128,32 +131,33 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, agentResponse.dtlStatus = DtlStatus.SUCCESS agentResponse.agentMsg = eleMap["return_msg"] agentResponse.agentRefno = eleMap["transaction_id"] - qrcodeTrans.agentRefno = eleMap["transaction_id"] - agentServiceProxy.qrcodePayTransSaveOrUpdate(qrcodeTrans) - } else if("SYSTEMERROR"==errorCode||"BANKERROR"==errorCode||"USERPAYING"==errorCode){ - logger.error { "code=${errorCode},des=${eleMap["err_code_des"]}" } + qrcodeTrans.agentRefno = eleMap["transaction_id"] + agentResponse.payload = agentServiceProxy.qrcodePayTransSaveOrUpdate(qrcodeTrans) + } else if ("SYSTEMERROR" == errorCode || "BANKERROR" == errorCode || "USERPAYING" == errorCode) { + logger.error { "code=$errorCode,des=${eleMap["err_code_des"]}" } agentResponse.code = AgentCode.REQUIRE_QUERY agentResponse.agentCode = eleMap["err_code"] agentResponse.agentMsg = eleMap["err_code_des"] agentResponse.agentRefno = eleMap["transaction_id"] - qrcodeTrans.agentRefno = eleMap["transaction_id"] - agentServiceProxy.qrcodePayTransSaveOrUpdate(qrcodeTrans) - }else{ + qrcodeTrans.agentRefno = eleMap["transaction_id"] + agentResponse.payload = agentServiceProxy.qrcodePayTransSaveOrUpdate(qrcodeTrans) + } else { agentResponse.code = AgentCode.FAIL agentResponse.agentCode = eleMap["err_code"] agentResponse.agentMsg = eleMap["err_code_des"] - logger.error { "code=${errorCode},des=${eleMap["err_code_des"]}" } + logger.error { "code=$errorCode,des=${eleMap["err_code_des"]}" } } } return agentResponse } - override fun doPrepay(transaction: TTransactionMain): AgentResponse { - var agentResponse = AgentResponse() + override fun doPrepay(transaction: TTransactionMain): AgentResponse { + val agentResponse = AgentResponse() val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_WECHAT, transaction.shopDtl.shopaccno, false, false) if (checkCfg(config, agentResponse)) { //H5 支付 val trans = agentServiceProxy.qrcodePayTransFindByRefno(transaction.refno) + agentResponse.payload = trans val bean = WechatReqResp().apply { this.appid = config[PaytypeUtil.CFG_WECHAT_APPID] this.mch_id = config[PaytypeUtil.CFG_WECHAT_MECHID] @@ -162,35 +166,37 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, this.total_fee = MoneyUtil.YuanToFen(transaction.shopDtl.amount) this.spbill_create_ip = trans.spip this.body = transaction.shopDtl.payInfo - this.notify_url = StringUtil.urlAppend(config[PaytypeUtil.CFG_WECHAT_NOTIFY],transaction.tenantid) - this.trade_type = when(transaction.transCode){TradeCode.TRANSCODE_H5PAY->"MWEB" - TradeCode.TRANSCODE_JSPAY->"JSAPI" - TradeCode.TRANSCODE_APPPAY->"APP" - else->"JSAPI"} + this.notify_url = StringUtil.urlAppend(config[PaytypeUtil.CFG_WECHAT_NOTIFY], transaction.tenantid) + this.trade_type = when (transaction.transCode) { + TradeCode.TRANSCODE_H5PAY -> "MWEB" + TradeCode.TRANSCODE_JSPAY -> "JSAPI" + TradeCode.TRANSCODE_APPPAY -> "APP" + else -> "JSAPI" + } this.scene_info = "{\"h5_info\": {\"type\":\"Wap\",\"wap_url\": \"" + config[PaytypeUtil.CFG_WECHAT_NOTIFY] + "\",\"wap_name\": \"微信支付\"}}" } - if( transaction.transCode==TradeCode.TRANSCODE_JSPAY || transaction.transCode==TradeCode.TRANSCODE_SMPAY){ - var p = personIdentityDao.getBySourcetype(transaction.personDtl.userid,transaction.sourceType) - if(p!=null){ + if (transaction.transCode == TradeCode.TRANSCODE_JSPAY || transaction.transCode == TradeCode.TRANSCODE_SMPAY) { + val p = personIdentityDao.getBySourcetype(transaction.personDtl.userid, transaction.sourceType) + if (p != null) { bean.openid = p.thirdUid } } bean.generaSign() val xml = bean.generaXML() restTemplate.messageConverters[1] = StringHttpMessageConverter(StandardCharsets.UTF_8) - var res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_UNIONPAY, xml, String::class.java) - var eleMap = XmlUtils.parseXml(res.body) - var retcode = eleMap["return_code"] - var resultCode = eleMap["result_code"] + val res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_UNIONPAY, xml, String::class.java) + val eleMap = XmlUtils.parseXml(res.body) + val retcode = eleMap["return_code"] + val resultCode = eleMap["result_code"] if (!retcode.isNullOrEmpty() && "SUCCESS" == retcode - && !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode ) { + && !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode) { agentResponse.code = AgentCode.REQUIRE_QUERY - agentResponse.agentCode =resultCode + agentResponse.agentCode = resultCode agentResponse.agentMsg = eleMap["return_msg"] when { - transaction.transCode==TradeCode.TRANSCODE_H5PAY -> agentResponse.agentBody = eleMap["mweb_url"] - transaction.transCode==TradeCode.TRANSCODE_APPPAY -> { + transaction.transCode == TradeCode.TRANSCODE_H5PAY -> agentResponse.agentBody = eleMap["mweb_url"] + transaction.transCode == TradeCode.TRANSCODE_APPPAY -> { bean.prepay_id = eleMap["prepay_id"] bean.timestamp = DateUtil.getNowSecond().toString() bean.nonce_str = getRandomString(30) @@ -198,7 +204,7 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, bean.generaAPPSign() agentResponse.agentBody = bean.generaAPPParamters() } - transaction.transCode==TradeCode.TRANSCODE_JSPAY || transaction.transCode==TradeCode.TRANSCODE_SMPAY -> { + transaction.transCode == TradeCode.TRANSCODE_JSPAY || transaction.transCode == TradeCode.TRANSCODE_SMPAY -> { bean.prepay_id = eleMap["prepay_id"] bean.timestamp = DateUtil.getNowSecond().toString() bean.nonce_str = getRandomString(30) @@ -217,8 +223,8 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun doQuery(transaction: TTransactionMain): AgentResponse { - var agentResponse = AgentResponse() + override fun doQuery(transaction: TTransactionMain): AgentResponse { + val agentResponse = AgentResponse() val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_WECHAT, transaction.shopDtl.shopaccno, false, false) if (checkCfg(config, agentResponse)) { //H5 支付 @@ -231,10 +237,10 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, bean.generalQuerySign() val xml = bean.generalQueryXML() restTemplate.messageConverters[1] = StringHttpMessageConverter(StandardCharsets.UTF_8) - var res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_QUERY, xml, String::class.java) - var eleMap = XmlUtils.parseXml(res.body) - var retcode = eleMap["return_code"] - var resultCode = eleMap["result_code"] + val res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_QUERY, xml, String::class.java) + val eleMap = XmlUtils.parseXml(res.body) + val retcode = eleMap["return_code"] + val resultCode = eleMap["result_code"] val tradeState = eleMap["trade_state"] if (!retcode.isNullOrEmpty() && "SUCCESS" == retcode && !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode) { @@ -257,8 +263,8 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun doRefund(transaction: TTransactionMain): AgentResponse { - var agentResponse = AgentResponse() + override fun doRefund(transaction: TTransactionMain): AgentResponse { + val agentResponse = AgentResponse() val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_WECHAT, transaction.shopDtl.shopaccno, false, false) if (checkCfg(config, agentResponse)) { val bean = WechatReqResp().apply { @@ -269,18 +275,18 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, this.total_fee = MoneyUtil.YuanToFen(transaction.shopDtl.amount) this.refund_fee = MoneyUtil.YuanToFen(transaction.refundAmount) this.out_refund_no = transaction.reverseRefno - this.notify_url = StringUtil.urlAppend(config[PaytypeUtil.CFG_WECHAT_NOTIFY],transaction.tenantid) + this.notify_url = StringUtil.urlAppend(config[PaytypeUtil.CFG_WECHAT_NOTIFY], transaction.tenantid) } bean.generaReverseSign() val xml = bean.generaReverseXML() - var res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_REFUND, xml, String::class.java) - var eleMap = XmlUtils.parseXml(res.body) - var retcode = eleMap["return_code"] - var resultCode = eleMap["result_code"] + val res = restTemplate.postForEntity(PaytypeUtil.CFG_WECHAT_REFUND, xml, String::class.java) + val eleMap = XmlUtils.parseXml(res.body) + val retcode = eleMap["return_code"] + val resultCode = eleMap["result_code"] if (!retcode.isNullOrEmpty() && "SUCCESS" == retcode - && !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode ) { + && !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode) { agentResponse.code = AgentCode.REQUIRE_QUERY - agentResponse.agentCode =resultCode + agentResponse.agentCode = resultCode agentResponse.agentRefno = eleMap["refund_id"] agentResponse.agentMsg = eleMap["return_msg"] } else { @@ -293,9 +299,9 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun doNotify(param: Map): AgentResponse { - var agentResponse = AgentResponse() - var transaction = consumePayService.getTransactionMainDtl(param["out_trade_no"], null, null) + override fun doNotify(param: Map): AgentResponse { + val agentResponse = AgentResponse() + val transaction = consumePayService.getTransactionMainDtl(param["out_trade_no"], null, null) if (transaction == null) { agentResponse.code = AgentCode.REFNO_NOT_EXISTS agentResponse.agentCode = AgentResponse.AGENTCODE_FAIL @@ -314,10 +320,10 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, agentResponse.agentCode = AgentResponse.AGENTCODE_FAIL agentResponse.agentMsg = "签名错误" } - var temp = StringUtil.paraFilter(param) + val temp = StringUtil.paraFilter(param) var signStr = StringUtil.createLinkString(temp) val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_WECHAT, transaction.shopDtl.shopaccno, false, false) - var key = config[PaytypeUtil.CFG_WECHAT_MECHKEY] + val key = config[PaytypeUtil.CFG_WECHAT_MECHKEY] signStr += "&key=$key" val signRet = MD5.encodeByMD5(signStr) logger.error("*******signStr=$signStr") @@ -332,10 +338,10 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, if (!returnCode.isNullOrEmpty() && "SUCCESS" == returnCode && !resultCode.isNullOrEmpty() && "SUCCESS" == resultCode) { val transid = param["transaction_id"] - if(transid.isNullOrEmpty()){ + if (transid.isNullOrEmpty()) { transactionService.success(transaction.refno) - }else{ - transactionService.success(transaction.refno,transid, true) + } else { + transactionService.success(transaction.refno, transid, true) } agentResponse.code = AgentCode.SUCCESS agentResponse.agentCode = resultCode @@ -348,7 +354,4 @@ class WechatServiceImpl(val sourceTypeService: SourceTypeService, return agentResponse } - override fun downloadBill(shopacc:String,accdate:String): BaseResp { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. - } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/swykt_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/swykt_service.kt index 165c4c78..efd0c29c 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/swykt_service.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/swykt_service.kt @@ -3,6 +3,7 @@ package com.supwisdom.dlpay.agent.service import com.supwisdom.dlpay.agent.AgentCode import com.supwisdom.dlpay.agent.AgentPayService import com.supwisdom.dlpay.agent.AgentResponse +import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.api.bean.BaseResp import com.supwisdom.dlpay.api.domain.TPersondtl import com.supwisdom.dlpay.api.domain.TTransactionMain @@ -33,26 +34,26 @@ interface SWYKTV5Service{ } @Component("swyktv5Agent") -class SWYktV5AgentService : AgentPayService { - override fun auth(shopaccno: String?, billno: String?): AgentResponse { - return AgentResponse().apply { +class SWYktV5AgentService : AgentPayService { + override fun auth(shopaccno: String?, billno: String?): AgentResponse { + return AgentResponse().apply { this.code = AgentCode.NOT_SUPPORT } } - override fun pay(transaction: TTransactionMain?): AgentResponse { + override fun pay(transaction: TTransactionMain?): AgentResponse { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun cancel(transaction: TTransactionMain?): AgentResponse { + override fun cancel(transaction: TTransactionMain?): AgentResponse { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun refund(transaction: TTransactionMain?): AgentResponse { + override fun refund(transaction: TTransactionMain?): AgentResponse { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun query(transaction: TTransactionMain?): AgentResponse { + override fun query(transaction: TTransactionMain?): AgentResponse { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/wanxiao_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/wanxiao_service.kt index eb778754..1fd1eb77 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/wanxiao_service.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/wanxiao_service.kt @@ -3,30 +3,31 @@ package com.supwisdom.dlpay.agent.service import com.supwisdom.dlpay.agent.AgentCode import com.supwisdom.dlpay.agent.AgentPayService import com.supwisdom.dlpay.agent.AgentResponse +import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.api.domain.TTransactionMain import org.springframework.stereotype.Component @Component("wanxiaoAgent") -class WanxiaoAgentService : AgentPayService { - override fun auth(shopaccno: String?, billno: String?): AgentResponse { - return AgentResponse().apply { +class WanxiaoAgentService : AgentPayService { + override fun auth(shopaccno: String?, billno: String?): AgentResponse { + return AgentResponse().apply { this.code = AgentCode.NOT_SUPPORT } } - override fun pay(transaction: TTransactionMain?): AgentResponse { + override fun pay(transaction: TTransactionMain?): AgentResponse { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun cancel(transaction: TTransactionMain?): AgentResponse { + override fun cancel(transaction: TTransactionMain?): AgentResponse { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun refund(transaction: TTransactionMain?): AgentResponse { + override fun refund(transaction: TTransactionMain?): AgentResponse { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun query(transaction: TTransactionMain?): AgentResponse { + override fun query(transaction: TTransactionMain?): AgentResponse { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/wechat_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/wechat_service.kt index 7fe78de5..8f082418 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/wechat_service.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/wechat_service.kt @@ -3,6 +3,7 @@ package com.supwisdom.dlpay.agent.service import com.supwisdom.dlpay.agent.AgentCode import com.supwisdom.dlpay.agent.AgentPayService import com.supwisdom.dlpay.agent.AgentResponse +import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.api.bean.BaseResp import com.supwisdom.dlpay.api.domain.TTransactionMain import com.supwisdom.dlpay.api.service.ConsumePayService @@ -11,52 +12,48 @@ import com.supwisdom.dlpay.framework.util.TradeDict import org.springframework.stereotype.Component interface WechatService { - fun doAuth(shopaccno: String?, billno: String?): AgentResponse + fun doAuth(shopaccno: String?, billno: String?): AgentResponse - fun doQrcodepay(transaction: TTransactionMain): AgentResponse + fun doQrcodepay(transaction: TTransactionMain): AgentResponse - fun doPrepay(transaction: TTransactionMain): AgentResponse + fun doPrepay(transaction: TTransactionMain): AgentResponse - fun doQuery(transaction: TTransactionMain): AgentResponse + fun doQuery(transaction: TTransactionMain): AgentResponse - fun doRefund(transaction: TTransactionMain): AgentResponse + fun doRefund(transaction: TTransactionMain): AgentResponse - fun doNotify(param: Map): AgentResponse + fun doNotify(param: Map): AgentResponse - /** - * 下载对账单 - * */ - fun downloadBill(shopacc:String,accdate:String):BaseResp } @Component("wechatAgent") class WeChatPayAgentService(val consumePayService: ConsumePayService, - val wechatService: WechatService) : AgentPayService { - override fun auth(shopaccno: String?, billno: String?): AgentResponse { + val wechatService: WechatService) : AgentPayService { + override fun auth(shopaccno: String?, billno: String?): AgentResponse { if (consumePayService.checkShopPaytype(shopaccno!!, TradeDict.PAYTYPE_WECHAT, true)) { return wechatService.doAuth(shopaccno, billno) } - return AgentResponse().apply { + return AgentResponse().apply { this.code = AgentCode.NOT_SUPPORT } } - override fun pay(transaction: TTransactionMain?): AgentResponse { + override fun pay(transaction: TTransactionMain?): AgentResponse { return when (transaction!!.transCode) { TradeCode.TRANSCODE_QRCODE -> wechatService.doQrcodepay(transaction) else -> wechatService.doPrepay(transaction) } } - override fun cancel(transaction: TTransactionMain?): AgentResponse { + override fun cancel(transaction: TTransactionMain?): AgentResponse { return refund(transaction) } - override fun refund(transaction: TTransactionMain?): AgentResponse { + override fun refund(transaction: TTransactionMain?): AgentResponse { return wechatService.doRefund(transaction!!) } - override fun query(transaction: TTransactionMain?): AgentResponse { + override fun query(transaction: TTransactionMain?): AgentResponse { return wechatService.doQuery(transaction!!) } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/async_tasks.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/async_tasks.kt index 65f41d89..ff9510d0 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/async_tasks.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/async_tasks.kt @@ -111,7 +111,7 @@ class AgentQueryResultTask { return } - val service = ApplicationUtil.findAgentPayService(applicationContext, + val service = ApplicationUtil.findAgentPayService(applicationContext, transaction.sourceType + "Agent") logger.info("refno=[${transaction.refno}]开始第" + (qcnt + 1) + "次查询支付结果:") diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/consume_api_controller.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/consume_api_controller.kt index cfdd7ec3..b62c9900 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/consume_api_controller.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/consume_api_controller.kt @@ -2,6 +2,7 @@ package com.supwisdom.dlpay.api.controller import com.supwisdom.dlpay.agent.AgentCode import com.supwisdom.dlpay.agent.AgentPayService +import com.supwisdom.dlpay.agent.DtlStatus import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.agent.service.AgentServiceProxy import com.supwisdom.dlpay.api.* @@ -217,8 +218,8 @@ class ConsumeAPIController { .fail(TradeErrorCode.BUSINESS_PAYTYPE_NOSUPPORT, "不支持支付方式<市民卡代扣>")) } - fun createAgentService(sourceType: String): AgentPayService { - return ApplicationUtil.findAgentPayService(applicationContext, sourceType + "Agent") + fun createAgentService(sourceType: String): AgentPayService { + return ApplicationUtil.findAgentPayService(applicationContext, sourceType + "Agent") ?: throw TransactionCheckException(TradeErrorCode.BUSINESS_DEAL_ERROR, "支付类型<$sourceType>未定义") } @@ -231,7 +232,7 @@ class ConsumeAPIController { @PostMapping("/citizencard/payfinish") fun citizencardPayinit(@Valid @RequestBody param: CitizenCardPayfinishParam): ResponseEntity { val dtl = transactionService.wip(param.refno) - val service = createAgentService(TradeDict.PAYTYPE_CITIZEN_CARD) + val service = createAgentService(TradeDict.PAYTYPE_CITIZEN_CARD) val resp = service.pay(dtl) when (resp.code) { AgentCode.SUCCESS -> @@ -287,7 +288,7 @@ class ConsumeAPIController { val cancelTrans = builder.cancelInit(mainDtl.refno, transactionService) transactionService.wip(cancelTrans.refno) - val service = createAgentService(mainDtl.sourceType) + val service = createAgentService(mainDtl.sourceType) val resp = service.cancel(cancelTrans) when (resp.code) { AgentCode.SUCCESS -> { @@ -341,7 +342,7 @@ class ConsumeAPIController { } val refundTrans = builder.refundInit(mainDtl.refno, param.refundAmount / 100.0, transactionService) transactionService.wip(refundTrans.refno) - val service = createAgentService(mainDtl.sourceType) + val service = createAgentService(mainDtl.sourceType) val resp = service.refund(refundTrans) when (resp.code) { @@ -472,7 +473,7 @@ class ConsumeAPIController { .fail(apiResp, TradeErrorCode.BUSINESS_DEAL_ERROR, "支付方式<${qrcode.sourceType}>未配置科目号")) } - var systime = systemUtilService.sysdatetime + val systime = systemUtilService.sysdatetime // 2. 记录 qrcode 交易明细表 val qrcodeTrans = agentServiceProxy.qrcodePayTransSaveOrUpdate( QrcodePayTrans().apply { @@ -487,17 +488,19 @@ class ConsumeAPIController { }) // 3. 查询用户身份 - val service = createAgentService(qrcode.sourceType) + val service = createAgentService(qrcode.sourceType) val agentResp = service.auth(qrcodeTrans.agentMerchId, qrcodeTrans.billno) // 4. 重新读取 qrcode 交易明细表,以获取 service.auth 查询后的结果数据 - val qrcodeTransResp = agentServiceProxy.qrcodePayTransFindByMerchIdAndBillno(qrcodeTrans.agentMerchId, - qrcodeTrans.billno) + // 修改, 通过返回值来判断 +// val qrcodeTransResp = agentServiceProxy.qrcodePayTransFindByMerchIdAndBillno(qrcodeTrans.agentMerchId, +// qrcodeTrans.billno) apiResp.also { it.sourceType = sourceType.sourceType it.paydesc = qrcodeSummary(sourceType) } return when (agentResp.code) { AgentCode.SUCCESS -> { + val qrcodeTransResp = agentResp.payload if (!sourceType.anonymousEnable && qrcodeTransResp.isAnonymous) { ResponseEntity.ok(ResponseBodyBuilder.create() .fail(apiResp, TradeErrorCode.BUSINESS_DEAL_ERROR, @@ -511,6 +514,7 @@ class ConsumeAPIController { } } AgentCode.NOT_SUPPORT -> { + val qrcodeTransResp = agentResp.payload if (!sourceType.anonymousEnable) { ResponseEntity.ok(ResponseBodyBuilder.create() .fail(apiResp, TradeErrorCode.BUSINESS_DEAL_ERROR, @@ -614,7 +618,7 @@ class ConsumeAPIController { //3. 调用第三方支付 transactionService.wip(transaction.refno) - val service = createAgentService(qrcodeTrans.sourceType) + val service = createAgentService(qrcodeTrans.sourceType) apiResponse.apply { refno = transaction.refno accdate = transaction.accdate @@ -650,7 +654,7 @@ class ConsumeAPIController { * ============================================================================ * */ @PostMapping("/thirdpay/init") - fun thirdpayInit(@RequestBody param: ThirdPayinitParam,request:HttpServletRequest): ResponseEntity { + fun thirdpayInit(@RequestBody param: ThirdPayinitParam, request: HttpServletRequest): ResponseEntity { val dtlType = consumePayService.getDtltypeDictionary(param.dtltype, Dictionary.DTLTYPES) val sourceType = sourceTypeService.getBySourceType(param.sourceType) ?: return ResponseEntity.ok(ResponseBodyBuilder.create() @@ -664,17 +668,25 @@ class ConsumeAPIController { var transcode = 0 var des = "" when (param.subType) { - TradeDict.PAYTYPE_APP ->{transcode = TradeCode.TRANSCODE_APPPAY;des="APP内支付"} - TradeDict.PAYTYPE_JS -> {transcode = TradeCode.TRANSCODE_JSPAY;des="JS支付"} - TradeDict.PAYTYPE_H5 -> {transcode = TradeCode.TRANSCODE_H5PAY;des="H5支付"} - TradeDict.PAYTYPE_SM -> {transcode = TradeCode.TRANSCODE_SMPAY;des="小程序支付"} + TradeDict.PAYTYPE_APP -> { + transcode = TradeCode.TRANSCODE_APPPAY;des = "APP内支付" + } + TradeDict.PAYTYPE_JS -> { + transcode = TradeCode.TRANSCODE_JSPAY;des = "JS支付" + } + TradeDict.PAYTYPE_H5 -> { + transcode = TradeCode.TRANSCODE_H5PAY;des = "H5支付" + } + TradeDict.PAYTYPE_SM -> { + transcode = TradeCode.TRANSCODE_SMPAY;des = "小程序支付" + } } val transaction = TransactionBuilder().apply { setTransInfo(param.transdate, param.transtime, transcode, sourceType.sourceType) setOutTransInfo(shopacc.shopaccno, param.billno) operator(param.shopaccno, TradeDict.OPERTYPE_SHOP) - payinfo=sourceType.paydesc+des + payinfo = sourceType.paydesc + des }.person(account).apply { setAmount(param.amount / 100.0, TradeDict.TRADE_FLAG_OUT) @@ -692,8 +704,8 @@ class ConsumeAPIController { } }.init(transactionService) - var systime = systemUtilService.sysdatetime - if(param.spip.isNullOrEmpty()){ + val systime = systemUtilService.sysdatetime + if (param.spip.isNullOrEmpty()) { param.spip = request.remoteAddr } // 2. 记录 qrcode 交易明细表 @@ -735,7 +747,7 @@ class ConsumeAPIController { } else if (dtl.transCode == TradeCode.TRANSCODE_WECHAT) { type = TradeDict.PAYTYPE_WECHAT } - val service = createAgentService(type) + val service = createAgentService(type) val resp = service.pay(dtl) when (resp.code) { AgentCode.SUCCESS -> @@ -769,16 +781,16 @@ class ConsumeAPIController { * */ @PostMapping("/qrcodequery") fun qrcodeQuery(@RequestBody param: DoorQRCodeParam): ResponseEntity { - var token = redisTemplate.opsForValue().get(param.qrcode) - if(token.isNullOrEmpty()){ + val token = redisTemplate.opsForValue().get(param.qrcode) + if (token.isNullOrEmpty()) { return ResponseEntity.ok(ResponseBodyBuilder.create() .fail(1, "二维码不存在或已失效")) } val ret = qrCodeService.decodeCode(token) - return if(ret.retcode==0){ + return if (ret.retcode == 0) { ResponseEntity.ok(ResponseBodyBuilder.create() .success(ret, "成功")) - }else{ + } else { ResponseEntity.ok(ResponseBodyBuilder.create() .fail(ret.retcode, ret.retmsg)) } diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt index 5e72e705..2bee46c8 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_sourcetype_chk.kt @@ -37,7 +37,9 @@ class SourceTypeCheck { return TSourceTypeCheckStatus().also { it.sourceType = sourceType.sourceType it.tenantId = sourceType.tenantid + // 没有对账文件状态时创建一条以当前系统记账日期为起始时间的对账明细 it.startAccdate = systemUtilService.accdate + it.checkAccdate = it.startAccdate it.forceRecheck = false it.checkFileDate = it.startAccdate it.checkFileOk = false @@ -61,10 +63,11 @@ class SourceTypeCheck { return if (interval >= sourcetype.tplusN) { status.checkAccdate = DateUtil.getNewDay(status.checkAccdate, 1) status.checkStatus = false - status.checkFileOk = false status.checkFileDate = DateUtil.getNewDay(status.checkFileDate, 1) + status.checkFileOk = false sourceTypeService.saveOrUpdateSourceTypeCheckStatus(status) } else { + // 未到对账时间,跳过 null } } @@ -88,18 +91,18 @@ class SourceTypeCheck { sourceTypeCheckExecutor.reconciliation(it) } else { // 开始下载对账文件 - sourceTypeCheckExecutor.checkSourceType(it) + sourceTypeCheckExecutor.checkAndDownloadChkfile(it) } }.toMutableList() + val finishResult: MutableList> = mutableListOf() + val newPrcResult: MutableList> = mutableListOf() while (checkProcessResult.isNotEmpty()) { - val finishResult: MutableList> = mutableListOf() - val newPrcResult: MutableList> = mutableListOf() checkProcessResult.forEach { try { val result = it.get(10, TimeUnit.SECONDS) if (result.code == SourceTypeCheckExecutor.SUCCESS) { - // 完成对账问价下载 但 还未对账 + // 完成对账文件下载 但 还未对账 if (result.status.checkFileOk && !result.status.checkStatus) { newPrcResult.add(sourceTypeCheckExecutor.reconciliation(result.status)) } else if (!result.status.checkFileOk) { @@ -113,6 +116,8 @@ class SourceTypeCheck { "date <${result.status.checkAccdate}> 对账成功" } } + } else if (result.code == SourceTypeCheckExecutor.WAIT) { + newPrcResult.add(sourceTypeCheckExecutor.checkAndDownloadChkfile(result.status)) } else { logger.error { "sourcetype <${result.status.sourceType}> 对账状任务错误, error=" + @@ -127,6 +132,7 @@ class SourceTypeCheck { checkProcessResult.removeIf { finishResult.contains(it) } finishResult.clear() checkProcessResult.addAll(newPrcResult) + newPrcResult.clear() } } } @@ -167,7 +173,7 @@ class SourceTypeCheckExecutor { } @Async("sourcetypeCheckTaskExecutor") - fun checkSourceType(checkStatus: TSourceTypeCheckStatus): Future { + fun checkAndDownloadChkfile(checkStatus: TSourceTypeCheckStatus): Future { // 2. 根据对账日期下载对账文件 val result = getProvider(checkStatus.sourceType)?.let { provider -> val acResp = provider.acquireCheckFile(checkStatus.checkFileDate) @@ -184,8 +190,10 @@ class SourceTypeCheckExecutor { } else { ExecutorResult(checkStatus, FAIL, "下载失败,未能查到对账文件") } - } else { + } else if (acResp.code == AgentCode.SUCCESS) { downloadFile(provider, checkStatus) + } else { + ExecutorResult(checkStatus, FAIL, acResp.agentMsg) } } ?: ExecutorResult(checkStatus, FAIL, "未定义 CheckFileProvider") return AsyncResult(result) @@ -194,6 +202,7 @@ class SourceTypeCheckExecutor { @Async("sourcetypeCheckTaskExecutor") fun reconciliation(checkStatus: TSourceTypeCheckStatus): Future { // 3. 完成对账 - return AsyncResult(ExecutorResult(checkStatus, SUCCESS, "成功")) + TODO("实现对账逻辑") +// return AsyncResult(ExecutorResult(checkStatus, SUCCESS, "成功")) } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt index 35136c51..1d8e2fc6 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/scheduler_task.kt @@ -101,7 +101,7 @@ class DtlQueryResultSchedulerTask { return } - val service = ApplicationUtil.findAgentPayService(applicationContext, dtl.sourceType + "Agent") + val service = ApplicationUtil.findAgentPayService(applicationContext, dtl.sourceType + "Agent") val resp = service.query(dtl) when (resp.code) { AgentCode.SUCCESS -> {