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
class AlipayServiceImpl(val sourceTypeService: SourceTypeService,
val agentServiceProxy: AgentServiceProxy,
val consumePayService: ConsumePayService,
- val transactionService: TransactionServiceProxy) : AlipayService {
+ val transactionService: TransactionServiceProxy,
+ val restTemplateProxyProperties: RestTemplateConfig.RestTemplateProxyProperties)
+ : AlipayService {
val logger = KotlinLogging.logger { }
fun checkCfg(config: Map<String, String?>, resp: AgentResponse): Boolean {
return true
}
+ private fun createAlipayClient(config: Map<String, String?>): DefaultAlipayClient {
+ val payurl = config[PaytypeUtil.CFG_ALIPAY_PAYURL].let {
+ if (it.isNullOrEmpty()) {
+ "https://openapi.alipay.com/gateway.do"
+ } else {
+ it
+ }
+ }
+ return DefaultAlipayClient.builder(payurl, config[PaytypeUtil.CFG_ALIPAY_APPID],
+ config[PaytypeUtil.CFG_ALIPAY_PRIVATEKEY])
+ .charset("UTF-8")
+ .format("json")
+ .alipayPublicKey(config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY])
+ .signType("RSA2")
+ .also {
+ if (restTemplateProxyProperties.type == "http") {
+ it.proxyHost(restTemplateProxyProperties.host)
+ .proxyPort(restTemplateProxyProperties.port)
+ }
+ }.build()
+ }
+
override fun doQrcodepay(transaction: TTransactionMain): AgentResponse {
- var qrcodePayTrans = agentServiceProxy.qrcodePayTransFindByRefno(transaction.refno)
- val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, qrcodePayTrans.isAnonymous, false)
- var agentResponse = AgentResponse()
+ val qrcodePayTrans = agentServiceProxy.qrcodePayTransFindByRefno(transaction.refno)
+ val config = sourceTypeService.getConsumePaytypeConfig(
+ TradeDict.PAYTYPE_ALIPAY,
+ transaction.shopDtl.shopaccno,
+ qrcodePayTrans.isAnonymous, false)
+ val agentResponse = AgentResponse()
if (checkCfg(config, agentResponse)) {
- var payurl = config[PaytypeUtil.CFG_ALIPAY_PAYURL]
- if (payurl.isNullOrEmpty()) {
- payurl = "https://openapi.alipay.com/gateway.do"
- }
- val alipayClient = DefaultAlipayClient(payurl, config[PaytypeUtil.CFG_ALIPAY_APPID], config[PaytypeUtil.CFG_ALIPAY_PRIVATEKEY], "json", "UTF-8", config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY], "RSA2")
val request = AlipayTradePayRequest()
request.bizModel = AlipayTradePayModel().apply {
this.authCode = qrcodePayTrans.qrcode
this.totalAmount = transaction.shopDtl.amount.toString()
}
try {
+ val alipayClient = createAlipayClient(config)
val response = alipayClient.execute(request)
if ("10000" == response.code) {
if (response.isSuccess) {
}
override fun doPrepay(transaction: TTransactionMain): AgentResponse {
- val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false)
- var agentResponse = AgentResponse()
+ val config = sourceTypeService.getConsumePaytypeConfig(
+ TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno,
+ false, false)
+ val agentResponse = AgentResponse()
if (checkCfg(config, agentResponse)) {
if (config[PaytypeUtil.CFG_ALIPAY_NOTIFY].isNullOrEmpty()) {
agentResponse.code = AgentCode.CONFIG_ERROR
agentResponse.agentMsg = "支付宝相关配置为空"
logger.error { "支付宝异步通知地址未配置:${PaytypeUtil.CFG_ALIPAY_NOTIFY}" }
}
- var payurl = config[PaytypeUtil.CFG_ALIPAY_PAYURL]
- if (payurl.isNullOrEmpty()) {
- payurl = "https://openapi.alipay.com/gateway.do"
- }
- val alipayClient = DefaultAlipayClient(payurl, config[PaytypeUtil.CFG_ALIPAY_APPID], config[PaytypeUtil.CFG_ALIPAY_PRIVATEKEY], "json", "UTF-8", config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY], "RSA2")
+ val alipayClient = createAlipayClient(config)
val request = AlipayTradeAppPayRequest()
- var productCode = ""
+ val productCode = ""
//判断是否为H5
//productCode = "QUICK_WAP_WAY"
request.bizModel = AlipayTradePayModel().apply {
}
override fun doRefund(transaction: TTransactionMain): AgentResponse {
- var agentResponse = AgentResponse()
- val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false)
+ val agentResponse = AgentResponse()
+ val config = sourceTypeService.getConsumePaytypeConfig(
+ TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno,
+ false, false)
if (checkCfg(config, agentResponse)) {
- var payurl = config[PaytypeUtil.CFG_ALIPAY_PAYURL]
- if (payurl.isNullOrEmpty()) {
- payurl = "https://openapi.alipay.com/gateway.do"
- }
- val alipayClient = DefaultAlipayClient(payurl, config[PaytypeUtil.CFG_ALIPAY_APPID], config[PaytypeUtil.CFG_ALIPAY_PRIVATEKEY], "json", "UTF-8", config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY], "RSA2")
+ val alipayClient = createAlipayClient(config)
val request = AlipayTradeQueryRequest()
request.bizModel = AlipayTradeRefundModel().apply {
this.outTradeNo = transaction.refno
}
override fun doQuery(transaction: TTransactionMain): AgentResponse {
- var agentResponse = AgentResponse()
- val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false)
+ val agentResponse = AgentResponse()
+ val config = sourceTypeService.getConsumePaytypeConfig(
+ TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false)
if (checkCfg(config, agentResponse)) {
- var payurl = config[PaytypeUtil.CFG_ALIPAY_PAYURL]
- if (payurl.isNullOrEmpty()) {
- payurl = "https://openapi.alipay.com/gateway.do"
- }
- val alipayClient = DefaultAlipayClient(payurl, config[PaytypeUtil.CFG_ALIPAY_APPID], config[PaytypeUtil.CFG_ALIPAY_PRIVATEKEY], "json", "UTF-8", config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY], "RSA2")
+ val alipayClient = createAlipayClient(config)
val request = AlipayTradeQueryRequest()
request.bizModel = AlipayTradeQueryModel().apply {
this.outTradeNo = transaction.refno
}
override fun doNotify(param: Map<String, String>): AgentResponse {
- var refno = param["out_trade_no"]
- var agentResponse = AgentResponse()
+ val refno = param["out_trade_no"]
+ val agentResponse = AgentResponse()
if (refno.isNullOrEmpty()) {
agentResponse.code = AgentCode.FAIL
return agentResponse
}
- var transaction = consumePayService.getTransactionMainDtl(refno, null, null)
+ val transaction = consumePayService.getTransactionMainDtl(refno, null, null)
if (transaction == null) {
agentResponse.code = AgentCode.REFNO_NOT_EXISTS
return agentResponse
agentResponse.code = AgentCode.SUCCESS
return agentResponse
}
- val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false)
+ val config = sourceTypeService.getConsumePaytypeConfig(
+ TradeDict.PAYTYPE_ALIPAY, transaction.shopDtl.shopaccno, false, false)
if (config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY].isNullOrEmpty()) {
agentResponse.code = AgentCode.CONFIG_ERROR
return agentResponse
}
- var flag = AlipaySignature.rsaCheckV1(param, config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY], "UTF-8", "RSA2")
- return when (flag) {
+ return when (AlipaySignature.rsaCheckV1(param,
+ config[PaytypeUtil.CFG_ALIPAY_PUBLICKEY], "UTF-8", "RSA2")) {
true -> {
//total amt 校验 map["total_amount"]
- var tradeno = param["trade_no"]
+ val tradeno = param["trade_no"]
if (tradeno.isNullOrEmpty()) {
transactionService.success(transaction.refno)
} else {