|
@ -0,0 +1,228 @@
|
|
|
package com.yihu.jw.order.pay.ylz;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO;
|
|
|
import com.yihu.jw.hospital.prescription.dao.OauthDzqmConfigDao;
|
|
|
import com.yihu.jw.hospital.prescription.dao.OauthYlzConfigDao;
|
|
|
import com.yihu.jw.order.pay.utils.PayLogService;
|
|
|
import com.yihu.jw.utils.StringUtil;
|
|
|
import com.ylzinfo.onepay.sdk.HisOnepayClient;
|
|
|
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
|
|
|
import com.ylzinfo.onepay.sdk.domain.ext.*;
|
|
|
import com.ylzinfo.onepay.sdk.utils.DateUtil;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
import java.io.StringWriter;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
|
* Created by wangzhinan on 2020/5/9.
|
|
|
*/
|
|
|
@Service
|
|
|
public class YlzPayService {
|
|
|
|
|
|
@Autowired
|
|
|
private OauthYlzConfigDao oauthYlzConfigDao;
|
|
|
|
|
|
@Autowired
|
|
|
private PayLogService logService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
private String termNo;
|
|
|
private String operatorId; 操作人员id
|
|
|
private String operatorName;操作人员型
|
|
|
private String cardType;卡类型 ---01 社保卡 06 临时卡
|
|
|
private String cardNo;---卡号
|
|
|
private String accountType;---帐户类型
|
|
|
private String idNo;--身份证号
|
|
|
private String depositType;---充值方式WX_MIN 微信小程序 WX_PUB 微信公众号 ALI_WAP 支付宝生活号
|
|
|
private String rechargeAmount;--单位:元充值金额(自费金额)
|
|
|
private String consumeAmount;---消费金额
|
|
|
private String outTradeNo;---商户扣费流水号
|
|
|
private String tradeKind;----消费种类门诊自费结算 长处方自费结算 互联网医院自费结算
|
|
|
private String hisCustId;---HIS 患者唯一 ID若无,请传卡号
|
|
|
private String rechargeHis;---是否往 HIS 充值0:不往 HIS 充值 1:往 HIS 充值 默认为 0
|
|
|
private String userName;----用户姓名
|
|
|
private String notes;---备注
|
|
|
openId---openid
|
|
|
* @return
|
|
|
*/
|
|
|
public String rechargeConsume(String operatorId,String operatorName,String cardType,String cardNo,String accountType,String idNo,String depositType,String rechargeAmount,
|
|
|
String consumeAmount,String outTradeNo,String hisCustId,String rechargeHis,String userName,String notes,String openid,String returnUrl,String notifyUrl,String wxMinId){
|
|
|
String object = null;
|
|
|
Boolean isSuccess = true;
|
|
|
String error = null;
|
|
|
OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("ylz_pay_config");
|
|
|
if(oauthYlzConfigDO==null){
|
|
|
return "未找到支付配置文件";
|
|
|
}
|
|
|
String appId = oauthYlzConfigDO.getAppId();
|
|
|
String appSecret = oauthYlzConfigDO.getAppKey();
|
|
|
String onepayUrl = oauthYlzConfigDO.getUrl();
|
|
|
String signType=oauthYlzConfigDO.getSignType();
|
|
|
String encryptType = oauthYlzConfigDO.getEncType();
|
|
|
HisOnepayClient onepayClient = new HisOnepayClient(onepayUrl, appId, appSecret, signType, encryptType);
|
|
|
RechargeConsumeParams param = new RechargeConsumeParams();
|
|
|
try {
|
|
|
param.setRechargeHis(rechargeHis);//HIS 充值
|
|
|
param.setAccountType(accountType);
|
|
|
param.setOutTradeNo(outTradeNo);
|
|
|
param.setCardNo(cardNo);
|
|
|
param.setCardType(cardType);
|
|
|
param.setAccountType(accountType);
|
|
|
param.setDepositType(depositType);
|
|
|
param.setRechargeAmount(rechargeAmount);
|
|
|
param.setConsumeAmount(consumeAmount);
|
|
|
param.setIdNo(idNo);
|
|
|
param.setHisCustId(hisCustId);
|
|
|
param.setUserName(userName);
|
|
|
param.setTermNo("123456");
|
|
|
param.setNotes(notes);
|
|
|
param.setOperatorId(operatorId);
|
|
|
param.setOperatorName(operatorName);
|
|
|
Map<String,String> extra = new HashMap<String,String>();
|
|
|
extra.put("openId", openid);
|
|
|
extra.put("returnUrl",returnUrl);
|
|
|
extra.put("notifyUrl",notifyUrl);
|
|
|
if (StringUtils.isNoneBlank(wxMinId)){
|
|
|
extra.put("wxMinId",wxMinId);
|
|
|
}
|
|
|
param.setExtra(extra);
|
|
|
ResponseParams<RechargeConsumeResult> respnse = onepayClient.rechargeConsume(param);
|
|
|
if (respnse.getRespCode().equals("000000")){
|
|
|
object = JSON.toJSONString(respnse);
|
|
|
}else {
|
|
|
isSuccess = false;
|
|
|
object = JSON.toJSONString(respnse);
|
|
|
error = "请求失败,返回结果:" + respnse.getRespCode() + "," + respnse.getRespMsg();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
isSuccess = false;
|
|
|
StringWriter sw = new StringWriter();
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
e.printStackTrace(pw);
|
|
|
error = sw.toString();
|
|
|
}
|
|
|
logService.saveHttpLog(isSuccess, "hop.trade.recharge", "互联网医院充值", "POST", null,JSON.toJSONString(param), object, error,logService.onepayType);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* termNo 终端编号 String(50) Y
|
|
|
* operatorId 操作员编号 String(30) N
|
|
|
* operatorName 操作员姓名 String(50) N
|
|
|
* cardType 卡类型 String(2) N
|
|
|
* cardNo 卡号 String(32) N
|
|
|
* accountType 帐户类型 String(2) N 01:门诊,02:住院
|
|
|
* amount 退款金额 String(12) N
|
|
|
* withdrawMode 退款方式 String(1) N 0 现金退回 1 原路退回 2 银企转账 3 医保自费退回
|
|
|
* outChargeNo 商户原充值订单号 String(30) N 二选一,两者同时存在 时,
|
|
|
* traceNo>outCharge No,两者不能同时为空
|
|
|
* traceNo 平台交易跟踪号(调 用平台充值接口后返 回的 traceNo) String(30)
|
|
|
* outRefundNo 商户退款订单号 String(30) N
|
|
|
* idNo 身份证号 String(32) Y
|
|
|
* hisCustId HIS 系统唯一性 患者 String(30) N 没有则传卡号
|
|
|
ID userName 用户姓名 String(30) Y extra 扩展参数 JSON Y checkCash String 当 withdrawMode=0 时,checkCash=1 校验 现金充值流水号及可退 金额是否合法,放空或 其他值不校验
|
|
|
|
|
|
* @return
|
|
|
*/
|
|
|
public String refund(String hisCustId,String operatorId,String operatorName,String cardType,String cardNo,String accountType,String amount,
|
|
|
String withdrawMode,String outChargeNo,String outRefundNo,String idNo){
|
|
|
String object = null;
|
|
|
Boolean isSuccess = true;
|
|
|
String error = null;
|
|
|
OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("ylz_pay_config");
|
|
|
if(oauthYlzConfigDO==null){
|
|
|
return "未找到支付配置文件";
|
|
|
}
|
|
|
String appId = oauthYlzConfigDO.getAppId();
|
|
|
String appSecret = oauthYlzConfigDO.getAppKey();
|
|
|
String onepayUrl = oauthYlzConfigDO.getUrl();
|
|
|
String signType=oauthYlzConfigDO.getSignType();
|
|
|
String encryptType = oauthYlzConfigDO.getEncType();
|
|
|
HisOnepayClient onepayClient = new HisOnepayClient(onepayUrl, appId, appSecret, signType, encryptType);
|
|
|
RefundParams param = new RefundParams();
|
|
|
try {
|
|
|
param.setTermNo("123456");
|
|
|
param.setHisCustId(hisCustId);
|
|
|
param.setOperatorId(operatorId);
|
|
|
param.setOperatorName(operatorName);
|
|
|
param.setCardType(cardType);
|
|
|
param.setCardNo(cardNo);
|
|
|
param.setAccountType(accountType);
|
|
|
param.setAmount(amount);
|
|
|
param.setWithdrawMode(withdrawMode);
|
|
|
param.setOutChargeNo(outChargeNo);
|
|
|
param.setOutRefundNo(outRefundNo);
|
|
|
param.setIdNo(idNo);
|
|
|
ResponseParams<RefundResult> response = onepayClient.refund(param);
|
|
|
if (response.getRespCode().equals("000000")){
|
|
|
object = JSON.toJSONString(response);
|
|
|
}else {
|
|
|
isSuccess = false;
|
|
|
object = JSON.toJSONString(response);
|
|
|
error = "请求失败,返回结果:" + response.getRespCode() + "," + response.getRespMsg();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
isSuccess = false;
|
|
|
StringWriter sw = new StringWriter();
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
e.printStackTrace(pw);
|
|
|
error = sw.toString();
|
|
|
}
|
|
|
logService.saveHttpLog(isSuccess, "hop.trade.refund", "互联网医院退款", "POST", null,JSON.toJSONString(param), object, error,logService.onepayType);
|
|
|
return object;
|
|
|
}
|
|
|
|
|
|
|
|
|
public String tradeQuery(String termNo,String operatorId,String operatorName,String outTradeNo,String tradeType,String notes){
|
|
|
String object = null;
|
|
|
Boolean isSuccess = true;
|
|
|
String error = null;
|
|
|
OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("ylz_pay_config");
|
|
|
if(oauthYlzConfigDO==null){
|
|
|
return "未找到支付配置文件";
|
|
|
}
|
|
|
String appId = oauthYlzConfigDO.getAppId();
|
|
|
String appSecret = oauthYlzConfigDO.getAppKey();
|
|
|
String onepayUrl = oauthYlzConfigDO.getUrl();
|
|
|
String signType=oauthYlzConfigDO.getSignType();
|
|
|
String encryptType = oauthYlzConfigDO.getEncType();
|
|
|
HisOnepayClient onepayClient = new HisOnepayClient(onepayUrl, appId, appSecret, signType, encryptType);
|
|
|
TradeQueryParams param = new TradeQueryParams();
|
|
|
try {
|
|
|
param.setTermNo("123456");
|
|
|
param.setOperatorId("123456");
|
|
|
param.setOperatorName(operatorName);
|
|
|
param.setTradeType(tradeType);
|
|
|
param.setOutTradeNo(outTradeNo);
|
|
|
param.setNotes(notes);
|
|
|
ResponseParams<TradeQueryResult> response = onepayClient.tradeQuery(param);
|
|
|
if (response.getRespCode().equals("000000")){
|
|
|
object = JSON.toJSONString(response);
|
|
|
}else {
|
|
|
isSuccess = false;
|
|
|
object = JSON.toJSONString(response);
|
|
|
error = "请求失败,返回结果:" + response.getRespCode() + "," + response.getRespMsg();
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
isSuccess = false;
|
|
|
StringWriter sw = new StringWriter();
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
e.printStackTrace(pw);
|
|
|
error = sw.toString();
|
|
|
}
|
|
|
logService.saveHttpLog(isSuccess, "hop.trade.tradeQuery", "互联网医院查询订单", "POST", null,JSON.toJSONString(param), object, error,logService.onepayType);
|
|
|
return object;
|
|
|
}
|
|
|
}
|