From: Tang Cheng Date: Wed, 7 Aug 2019 04:38:59 +0000 (+0800) Subject: 优化 AgentResponse X-Git-Tag: 1.0.1^2~31 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=31cdc0a7a9297ed20163c133f8ec6230c35e1b8b;p=epayment%2Ffood_payapi.git 优化 AgentResponse --- 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 a8dde971..4c0ff3d0 100644 --- a/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentResponse.java +++ b/payapi/src/main/java/com/supwisdom/dlpay/agent/AgentResponse.java @@ -1,5 +1,7 @@ package com.supwisdom.dlpay.agent; +import java.lang.reflect.ParameterizedType; + public class AgentResponse { public static final String AGENTCODE_SUCCESS = "0"; @@ -69,4 +71,24 @@ public class AgentResponse { public void setPayload(T payload) { this.payload = payload; } + + private T newNullPayload(Class clazz) { + try { + return clazz.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + throw new IllegalArgumentException("can't instance " + clazz.getName()); + } + } + + @SuppressWarnings("unchecked") + private Class getPayloadBeanType() { + Class cls = (Class) ((ParameterizedType) getClass() + .getGenericSuperclass()) + .getActualTypeArguments()[0]; + return cls; + } + + public AgentResponse() { + this.payload = newNullPayload(getPayloadBeanType()); + } } 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 0bcb1bf4..9dadacd3 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 @@ -79,6 +79,7 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, transaction.shopDtl.shopaccno, qrcodePayTrans.isAnonymous, false) val agentResponse = AgentResponse() + agentResponse.payload = qrcodePayTrans if (checkCfg(config, agentResponse)) { val request = AlipayTradePayRequest() request.bizModel = AlipayTradePayModel().apply { @@ -97,7 +98,7 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, agentResponse.agentMsg = response.msg agentResponse.agentCode = response.code qrcodePayTrans.agentRefno = response.tradeNo - agentServiceProxy.qrcodePayTransSaveOrUpdate(qrcodePayTrans) + agentResponse.payload = agentServiceProxy.qrcodePayTransSaveOrUpdate(qrcodePayTrans) } else { agentResponse.code = AgentCode.FAIL agentResponse.agentMsg = response.msg @@ -148,14 +149,14 @@ class AlipayServiceImpl(val sourceTypeService: SourceTypeService, this.totalAmount = transaction.shopDtl.amount.toString() this.productCode = productCode } - request.notifyUrl = StringUtil.urlAppend(config[PaytypeUtil.CFG_ALIPAY_NOTIFY],transaction.tenantid) - request.returnUrl = StringUtil.urlAppend(config[PaytypeUtil.CFG_ALIPAY_RETURNURL],transaction.tenantid) + request.notifyUrl = StringUtil.urlAppend(config[PaytypeUtil.CFG_ALIPAY_NOTIFY], transaction.tenantid) + request.returnUrl = StringUtil.urlAppend(config[PaytypeUtil.CFG_ALIPAY_RETURNURL], transaction.tenantid) try { /** * h5 支付方式 * */ if (transaction.transCode == TradeCode.TRANSCODE_H5PAY) { - var form = alipayClient.pageExecute(request).body + val form = alipayClient.pageExecute(request).body //body 为Html agentResponse.agentBody = form agentResponse.code = AgentCode.REQUIRE_QUERY