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;
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()
// 释放资源
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;
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
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)
@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>"
+ if (!tenantDetails.isPresent) {
+ return ResponseBodyBuilder.badRequest("请求租户<$tenant>不存在")
+ }
+ TenantContextHolder.getContext().tenant = tenantDetails.get()
val agent = agentPayServiceContext.findInAppPayService<Any>(sourcetype)
- ?: return "<xml><return_code><![CDATA[FAIL]]></return_code><return_msg><![CDATA[请求支付类型错误 <$sourcetype> 不存在]]></return_msg></xml>"
+ ?: 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