From: qiaowei Date: Fri, 19 Jul 2019 06:16:24 +0000 (+0800) Subject: 一卡通支付代码迁移 X-Git-Tag: 1.0.0^2~15 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=df0447a02df6fef97f315700e35ef8700c7aaaed;p=epayment%2Ffood_payapi.git 一卡通支付代码迁移 --- diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/swykt_service_impl.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/swykt_service_impl.kt new file mode 100644 index 00000000..6b647272 --- /dev/null +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/impl/swykt_service_impl.kt @@ -0,0 +1,131 @@ +package com.supwisdom.dlpay.agent.service.impl + +import com.google.gson.Gson +import com.sun.jersey.api.client.Client +import com.sun.jersey.api.client.ClientResponse +import com.supwisdom.dlpay.agent.service.SWYKTV5Service +import com.supwisdom.dlpay.api.bean.BaseResp +import com.supwisdom.dlpay.api.bean.SupStatusRevResp +import com.supwisdom.dlpay.api.bean.SupYktResp +import com.supwisdom.dlpay.api.service.SourceTypeService +import com.supwisdom.dlpay.api.service.UserService +import com.supwisdom.dlpay.framework.service.SystemUtilService +import com.supwisdom.dlpay.framework.util.* +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.stereotype.Service + +@Service +class SWYKTV5ServiceImpl :SWYKTV5Service { + @Autowired + lateinit var sourceTypeService: SourceTypeService + @Autowired + lateinit var systemUtilService: SystemUtilService + @Autowired + lateinit var userService: UserService + + override fun onLineThirdPay(shopaccno: String, userid: String, accdate: String, amount: Int, refno: String): BaseResp { + val code = BaseResp() + val config = sourceTypeService.getConsumePaytypeConfig(TradeDict.PAYTYPE_YKT_CARD, shopaccno, false, false) + val appid = config["appid"] + if (appid.isNullOrEmpty()) { + code.retcode = "1" + code.retmsg = "一卡通支付方式未启用或未配置[appid]" + return code + } + val appkey = config["appkey"] + if (appkey.isNullOrEmpty()) { + code.retcode = "1" + code.retmsg = "一卡通支付方式未启用或未配置[appkey]" + return code + } + val orderurl = config["orderurl"] + if (orderurl.isNullOrEmpty()) { + code.retcode = "1" + code.retmsg = "一卡通支付方式未启用或未配置[orderurl]" + return code + } + val person = userService.findOnePersonByUserid(userid) + + val params = hashMapOf() + params.put("partner_id", appid) + params.put("stuempno", person.idno) + params.put("tradeno",refno) + params.put("tradename", "校园卡支付") + params.put("amount", amount.toString()) + //TODO 解决一卡通商户号问题 + //params.put("shopid", yktshopid) + //params.put("devphyid", devphyid) + params.put("calcmanagefee", "T") //是否计算费率 + params.put("timestamp", DateUtil.getNow()) + params.put("sign_method", "HMAC"); + params.put("limitflag", "off") //是否判断消费限额,on-判断;off-不判断。默认on(判断限额)。为空或不为off都是on; + var signstr = StringUtil.createLinkString(HmacUtil.paraFilter(params)) + val sign = HmacUtil.HMACSHA1(signstr, appkey) + signstr = "$signstr&sign=$sign&sourcetype=food" + val c = Client.create() + c.setConnectTimeout(20000) + val r = c.resource(orderurl) + val respClient = r.post(ClientResponse::class.java, signstr) + if (200 == respClient.status) { + val ret = respClient.getEntity(String::class.java) + if (ret != null) { + try { + val gson = Gson() + val result = gson.fromJson(ret, SupYktResp::class.java) + if (result == null) { + code.retcode = "1" + code.retmsg = "返回内容为空" + return code + } + if ("0" != result.retcode) { + if ("30" == result.retcode) { + if (result.other != null) { + try { + val supStatusRevResp = gson.fromJson(result.other, + SupStatusRevResp::class.java) + if (supStatusRevResp != null) { + //同流水号,同一笔已经支付完成的,不重复支付。 + if (3 == supStatusRevResp.status + && supStatusRevResp.revflag != null + && !supStatusRevResp.revflag) { + code.retcode = "0" + code.retmsg = "成功" + return code + } + } + } catch (e: Exception) { + e.printStackTrace() + } + } + } + code.retcode = "1" + code.retmsg = "交易失败:" + result.retmsg + return code + } + code.retcode = "0" + code.retmsg = "成功" + return code + } catch (e: Exception) { + e.printStackTrace() + } + } + } + code.retcode = "1" + code.retmsg = "请求失败" + return code + } + + override fun onLineCardPay(): BaseResp { + TODO("not implemented") + } + + override fun onLineCardPayConfirm(): BaseResp { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + override fun offLineCardTransdtl(): BaseResp { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + +} \ No newline at end of file diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/swykt_service.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/swykt_service.kt index ed323c37..7f96f224 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/swykt_service.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/agent/service/swykt_service.kt @@ -2,9 +2,35 @@ package com.supwisdom.dlpay.agent.service import com.supwisdom.dlpay.agent.AgentPayService import com.supwisdom.dlpay.agent.AgentResponse +import com.supwisdom.dlpay.api.bean.BaseResp +import com.supwisdom.dlpay.api.domain.TPersondtl import com.supwisdom.dlpay.api.domain.TTransactionMain import org.springframework.stereotype.Component +interface SWYKTV5Service{ + + /** + * 调用一卡通V5第三方支付接口 + * */ + fun onLineThirdPay(shopaccno: String, userid: String, accdate: String, amount: Int, refno: String):BaseResp + + /** + * 调用一卡通V5卡片联机支付接口 + * */ + fun onLineCardPay():BaseResp + + /** + * 调用一卡通V5卡片联机密码确认支付接口 + * */ + fun onLineCardPayConfirm():BaseResp + + /** + * 调用一卡通V5卡片脱机上传授信流水接口 + * */ + fun offLineCardTransdtl():BaseResp + +} + @Component("swyktv5Agent") class SWYktV5AgentService : AgentPayService { override fun pay(transaction: TTransactionMain?): AgentResponse { diff --git a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/ThirdPayCall.kt b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/ThirdPayCall.kt index 2397e3b1..3d3cbae4 100644 --- a/payapi/src/main/kotlin/com/supwisdom/dlpay/api/ThirdPayCall.kt +++ b/payapi/src/main/kotlin/com/supwisdom/dlpay/api/ThirdPayCall.kt @@ -10,99 +10,13 @@ import com.supwisdom.dlpay.framework.util.* import com.supwisdom.dlpay.util.Code import mu.KotlinLogging -class CallBackResp { - var retcode: String = "99" - var retmsg: String? = null - val data = mutableMapOf() - fun add(key: String, value: String) { - this.data.plus(mapOf(key to value)) - } -} + class CallService { companion object { private val logger = KotlinLogging.logger { } - fun callYktPay(config: Map, paydtl: TPersondtl, time: String, stuempno: String, yktshopid: String, devphyid: String?): CallBackResp { - val code = CallBackResp() - val appid = config["appid"] - if (appid.isNullOrEmpty()) { - code.retcode = "1" - code.retmsg = "一卡通支付方式未启用或未配置" - return code - } - - val appkey = config["appkey"] - val orderurl = config["orderurl"] - - val params = hashMapOf() - params.put("partner_id", appid) - params.put("stuempno", stuempno) - params.put("tradeno", paydtl.refno) - params.put("tradename", paydtl.payinfo) - params.put("amount", MoneyUtil.YuanToFen(paydtl.amount).toString()) - params.put("shopid", yktshopid) - params.put("devphyid", devphyid) - params.put("calcmanagefee", "T") //是否计算费率 - params.put("timestamp", time) - params.put("sign_method", "HMAC"); - params.put("limitflag", "off") //是否判断消费限额,on-判断;off-不判断。默认on(判断限额)。为空或不为off都是on; - var signstr = StringUtil.createLinkString(HmacUtil.paraFilter(params)) - val sign = HmacUtil.HMACSHA1(signstr, appkey) - signstr = "$signstr&sign=$sign&sourcetype=food" - val c = Client.create() - c.setConnectTimeout(20000) - val r = c.resource(orderurl) - val respClient = r.post(ClientResponse::class.java, signstr) - if (200 == respClient.status) { - val ret = respClient.getEntity(String::class.java) - if (ret != null) { - try { - val gson = Gson() - val result = gson.fromJson(ret, SupYktResp::class.java) - if (result == null) { - code.retcode = "1" - code.retmsg = "返回内容为空" - return code - } - if ("0" != result.retcode) { - if ("30" == result.retcode) { - if (result.other != null) { - try { - val supStatusRevResp = gson.fromJson(result.other, - SupStatusRevResp::class.java) - if (supStatusRevResp != null) { - //同流水号,同一笔已经支付完成的,不重复支付。 - if (3 == supStatusRevResp.status - && supStatusRevResp.revflag != null - && !supStatusRevResp.revflag) { - code.retcode = "0" - code.retmsg = "成功" - return code - } - } - } catch (e: Exception) { - e.printStackTrace() - } - } - } - code.retcode = "1" - code.retmsg = "交易失败:" + result.retmsg - return code - } - code.retcode = "0" - code.retmsg = "成功" - return code - } catch (e: Exception) { - e.printStackTrace() - } - } - } - code.retcode = "1" - code.retmsg = "请求失败" - return code - } fun callWechatPay(config: Map, paydtl: TPersondtl, time: String, wechattype: String, realip: String?, qrcode: String?, openid: String?): BaseResp { @@ -614,12 +528,5 @@ class CallService { } */ - - fun CallCitizenCardPay(config: Map, paydtl: TShopdtl): CallBackResp { - val resp = CallBackResp() - resp.retcode = "0" - // TODO: 代扣逻辑 - return resp - } } } \ No newline at end of file