From: Tang Cheng Date: Wed, 4 Mar 2020 05:36:00 +0000 (+0800) Subject: chore: 代码重构 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=d905e6665136ebe41a595b9bf7ca48dd1986b7a5;p=epayment%2Ffood_payapi.git chore: 代码重构 --- diff --git a/payapi/src/main/java/com/supwisdom/dlpay/agent/InAppPayService.java b/payapi/src/main/java/com/supwisdom/dlpay/agent/InAppPayService.java index 88aec260..c860bbfa 100644 --- a/payapi/src/main/java/com/supwisdom/dlpay/agent/InAppPayService.java +++ b/payapi/src/main/java/com/supwisdom/dlpay/agent/InAppPayService.java @@ -1,7 +1,6 @@ package com.supwisdom.dlpay.agent; import com.supwisdom.dlpay.api.domain.TTransactionMain; -import org.springframework.http.HttpRequest; import javax.servlet.http.HttpServletRequest; @@ -23,11 +22,10 @@ public interface InAppPayService { /** * 当用支付完成后,第三方支付平台会发起通知给服务端,由服务端处理后续业务 * - * @param transaction - 交易参数 * @param request - 第三方平台通知请求的 HttpRequest * @return */ - AgentResponse notify(TTransactionMain transaction, HttpServletRequest request); + AgentResponse notify(HttpServletRequest request); /** * 由服务端主动发起的查询第三方支付平交易情况 diff --git a/payapi/src/main/java/com/supwisdom/dlpay/api/service/impl/SourceTypeServiceImpl.java b/payapi/src/main/java/com/supwisdom/dlpay/api/service/impl/SourceTypeServiceImpl.java index a4d40413..1d618fa4 100644 --- a/payapi/src/main/java/com/supwisdom/dlpay/api/service/impl/SourceTypeServiceImpl.java +++ b/payapi/src/main/java/com/supwisdom/dlpay/api/service/impl/SourceTypeServiceImpl.java @@ -211,5 +211,4 @@ public class SourceTypeServiceImpl implements SourceTypeService { return sourceTypeCheckDao.save(s); } - } diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/inapp_alipay.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/inapp_alipay.kt index b1166751..0286f156 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/inapp_alipay.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/inapp_alipay.kt @@ -3,7 +3,6 @@ package com.supwisdom.dlpay.agent.service import com.supwisdom.dlpay.agent.AgentResponse import com.supwisdom.dlpay.agent.InAppPayService import com.supwisdom.dlpay.api.domain.TTransactionMain -import org.springframework.http.HttpRequest import org.springframework.stereotype.Component import javax.servlet.http.HttpServletRequest @@ -17,7 +16,7 @@ class AlipayInAppServcie : InAppPayService { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } - override fun notify(transaction: TTransactionMain?, request: HttpServletRequest?): AgentResponse { + override fun notify(request: HttpServletRequest): AgentResponse? { TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/inapp_wechatpay.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/inapp_wechatpay.kt index 97ab8e5d..10579ca5 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/inapp_wechatpay.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/inapp_wechatpay.kt @@ -3,33 +3,28 @@ package com.supwisdom.dlpay.agent.service import com.supwisdom.dlpay.agent.AgentCode import com.supwisdom.dlpay.agent.AgentResponse import com.supwisdom.dlpay.agent.InAppPayService -import com.supwisdom.dlpay.agent.domain.QrcodePayTrans import com.supwisdom.dlpay.api.domain.TShopdtl import com.supwisdom.dlpay.api.domain.TTransactionMain import com.supwisdom.dlpay.api.service.SourceTypeService import org.dom4j.Element import org.dom4j.io.SAXReader -import org.springframework.http.HttpRequest import org.springframework.stereotype.Component import java.util.HashMap import javax.servlet.http.HttpServletRequest -class WechatPayResponse { - var preId: String = ""; -} @Component("wechatInAppAgent") class WechatInAppService(private val sourceTypeService: SourceTypeService, private val wechatService: WechatService) - : InAppPayService { + : InAppPayService { val APIUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder" - override fun init(transation: TTransactionMain): AgentResponse { - val wechatPayResponse = AgentResponse(); + override fun init(transation: TTransactionMain): AgentResponse { + val wechatPayResponse = AgentResponse(); System.err.println("#########"); - val shopDtlTemp = TShopdtl(); + val shopDtlTemp = TShopdtl(); transation.shopDtl = shopDtlTemp; //transaction.shopDtl must not be null - val agentResponse = wechatService.dopayInit(transation); + val agentResponse = wechatService.dopayInit(transation); System.err.println(agentResponse); wechatPayResponse.agentBody = agentResponse.agentBody; wechatPayResponse.agentCode = agentResponse.agentCode; @@ -37,13 +32,14 @@ class WechatInAppService(private val sourceTypeService: SourceTypeService, wechatPayResponse.agentRefno = agentResponse.agentRefno; wechatPayResponse.code = agentResponse.code; wechatPayResponse.dtlStatus = agentResponse.dtlStatus; + wechatPayResponse.payload = transation return wechatPayResponse; } - override fun notify(transaction: TTransactionMain?, request: HttpServletRequest): AgentResponse { - val wechatPayResponse = AgentResponse(); + override fun notify(request: HttpServletRequest): AgentResponse? { + val wechatPayResponse = AgentResponse(); // 解析结果存储在HashMap - var map: MutableMap = HashMap() + val map = HashMap() val inputStream = request.inputStream // 读取输入流 val reader = SAXReader() @@ -59,16 +55,16 @@ class WechatInAppService(private val sourceTypeService: SourceTypeService, // 释放资源 inputStream.close() val resp = wechatService.doPayNotify(map) - if (resp.code == AgentCode.SUCCESS) { - wechatPayResponse.agentBody = "" + if (resp.code == AgentCode.SUCCESS) { + wechatPayResponse.agentBody = "" } else { - wechatPayResponse.agentBody = "" + wechatPayResponse.agentBody = "" } return wechatPayResponse; } - override fun query(transation: TTransactionMain): AgentResponse { - val wechatPayResponse = AgentResponse(); + override fun query(transation: TTransactionMain): AgentResponse { + val wechatPayResponse = AgentResponse(); val agentResponse = wechatService.doPayQuery(transation); wechatPayResponse.agentMsg = agentResponse.agentMsg; wechatPayResponse.agentCode = agentResponse.agentCode; diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/transaction_controller.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/transaction_controller.kt index 38feb1ab..95e6e034 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/transaction_controller.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/transaction_controller.kt @@ -23,13 +23,10 @@ import com.supwisdom.multitenant.storage.TenantDetailsRegistrar import org.springframework.context.annotation.Lazy import org.springframework.data.redis.connection.RedisConnectionFactory import org.springframework.data.redis.core.RedisTemplate -import org.springframework.http.HttpRequest -import org.springframework.http.HttpStatus import org.springframework.http.ResponseEntity import org.springframework.validation.annotation.Validated import org.springframework.web.bind.annotation.* import javax.servlet.http.HttpServletRequest -import javax.validation.ConstraintViolationException import javax.validation.Valid import kotlin.math.roundToInt @@ -180,7 +177,7 @@ class TransactionController(private val transactionServiceProxy: TransactionServ this.refno = transaction.refno this.status = transaction.status this.message = "初始化成功" - this.callbackUrl = agentResponse.agentBody + this.callbackUrl = agentResponse.agentBody this.externalRefno = agentResponse.agentRefno } return ResponseBodyBuilder.successEntity(response) @@ -227,14 +224,17 @@ class TransactionNotifyController(@Lazy private val tenantDetailsRegistrar: Tena @PostMapping("/inapp/{sourcetype}/{tenant}") fun inAppPayCallback(@PathVariable("sourcetype") sourcetype: String, @PathVariable("tenant") tenant: String, - request: HttpServletRequest): String { + request: HttpServletRequest): ResponseEntity<*> { val tenantDetails = tenantDetailsRegistrar.getTenantDetailsById(tenant) - ?: return "不存在]]>" + if (!tenantDetails.isPresent) { + return ResponseBodyBuilder.badRequest("请求租户<$tenant>不存在") + } + TenantContextHolder.getContext().tenant = tenantDetails.get() val agent = agentPayServiceContext.findInAppPayService(sourcetype) - ?: return " 不存在]]>" + ?: return ResponseBodyBuilder.badRequest("请求支付类型错误 <$sourcetype> 不存在") TenantContextHolder.getContext().tenant = tenantDetails.get() - val agentResponse = agent.notify(null,request) + val agentResponse = agent.notify(request) - return agentResponse.agentBody; + return ResponseBodyBuilder.ok(agentResponse.agentBody) } } \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt index 375c8916..ae4c7a72 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/controller/user_api_controller.kt @@ -374,5 +374,4 @@ class UserAPIController { return ResponseBodyBuilder.successEntity(result) } - -} \ No newline at end of file +} diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/framework/framework_util.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/framework/framework_util.kt index 54863ea1..8e6deb5c 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/framework/framework_util.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/framework/framework_util.kt @@ -35,6 +35,10 @@ class ResponseBodyBuilder private constructor() { return ResponseEntity.status(status).body(msg) } + fun ok(msg: String): ResponseEntity { + return ResponseEntity.ok().body(msg) + } + fun notFound(msg: String): ResponseEntity<*> { return fail(HttpStatus.NOT_FOUND, msg) }