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 88aec26..c860bbf 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 @@
/**
* 当用支付完成后,第三方支付平台会发起通知给服务端,由服务端处理后续业务
*
- * @param transaction - 交易参数
* @param request - 第三方平台通知请求的 HttpRequest
* @return
*/
- AgentResponse<T> notify(TTransactionMain transaction, HttpServletRequest request);
+ AgentResponse<T> 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 a4d4041..1d618fa 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 @@
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 b116675..0286f15 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 @@
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 @@
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
- override fun notify(transaction: TTransactionMain?, request: HttpServletRequest?): AgentResponse<AlipayInAppResponse> {
+ override fun notify(request: HttpServletRequest): AgentResponse<AlipayInAppResponse>? {
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 97ab8e5..10579ca 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 @@
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<WechatPayResponse> {
+ : InAppPayService<TTransactionMain> {
val APIUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder"
- override fun init(transation: TTransactionMain): AgentResponse<WechatPayResponse> {
- val wechatPayResponse = AgentResponse<WechatPayResponse>();
+ override fun init(transation: TTransactionMain): AgentResponse<TTransactionMain> {
+ val wechatPayResponse = AgentResponse<TTransactionMain>();
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 @@
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<WechatPayResponse> {
- val wechatPayResponse = AgentResponse<WechatPayResponse>();
+ override fun notify(request: HttpServletRequest): AgentResponse<TTransactionMain>? {
+ val wechatPayResponse = AgentResponse<TTransactionMain>();
// 解析结果存储在HashMap
- var map: MutableMap<String, String> = HashMap()
+ val map = HashMap<String, String>()
val inputStream = request.inputStream
// 读取输入流
val reader = SAXReader()
@@ -59,16 +55,16 @@
// 释放资源
inputStream.close()
val resp = wechatService.doPayNotify(map)
- if (resp.code == AgentCode.SUCCESS) {
- wechatPayResponse.agentBody = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"
+ if (resp.code == AgentCode.SUCCESS) {
+ wechatPayResponse.agentBody = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"
} else {
- wechatPayResponse.agentBody = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[" + resp.agentMsg + "]]></return_msg></xml>"
+ wechatPayResponse.agentBody = "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[" + resp.agentMsg + "]]></return_msg></xml>"
}
return wechatPayResponse;
}
- override fun query(transation: TTransactionMain): AgentResponse<WechatPayResponse> {
- val wechatPayResponse = AgentResponse<WechatPayResponse>();
+ override fun query(transation: TTransactionMain): AgentResponse<TTransactionMain> {
+ val wechatPayResponse = AgentResponse<TTransactionMain>();
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 38feb1a..95e6e03 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 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 @@
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 @@
@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 "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[请求租户<$tenant>不存在]]></return_msg></xml>"
- val agent = agentPayServiceContext.findInAppPayService<Any>(sourcetype)
- ?: return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[请求支付类型错误 <$sourcetype> 不存在]]></return_msg></xml>"
+ if (!tenantDetails.isPresent) {
+ return ResponseBodyBuilder.badRequest("请求租户<$tenant>不存在")
+ }
TenantContextHolder.getContext().tenant = tenantDetails.get()
- val agentResponse = agent.notify(null,request)
+ val agent = agentPayServiceContext.findInAppPayService<Any>(sourcetype)
+ ?: return ResponseBodyBuilder.badRequest("请求支付类型错误 <$sourcetype> 不存在")
+ TenantContextHolder.getContext().tenant = tenantDetails.get()
+ 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 375c891..ae4c7a7 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 @@
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 54863ea..8e6deb5 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 @@
return ResponseEntity.status(status).body(msg)
}
+ fun ok(msg: String): ResponseEntity<String> {
+ return ResponseEntity.ok().body(msg)
+ }
+
fun notFound(msg: String): ResponseEntity<*> {
return fail(HttpStatus.NOT_FOUND, msg)
}