|
@ -2,12 +2,18 @@ package com.yihu.wlyy.service.weixin.wxpay.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.yihu.wlyy.entity.charge.WlyyCharge;
|
|
|
import com.yihu.wlyy.entity.organization.HospitalMapping;
|
|
|
import com.yihu.wlyy.entity.patient.Patient;
|
|
|
import com.yihu.wlyy.repository.charge.ChargeDao;
|
|
|
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
|
|
|
import com.yihu.wlyy.repository.patient.PatientDao;
|
|
|
import com.yihu.wlyy.service.third.httplog.LogService;
|
|
|
import com.yihu.wlyy.service.weixin.wxpay.common.Configure;
|
|
|
import com.yihu.wlyy.service.weixin.wxpay.model.BindCard;
|
|
|
import com.yihu.wlyy.service.weixin.wxpay.model.Charge;
|
|
|
import com.yihu.wlyy.util.SystemConf;
|
|
|
import com.ylzinfo.onepay.sdk.OnepayDefaultClient;
|
|
|
import com.ylzinfo.onepay.sdk.domain.RequestParams;
|
|
|
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
|
|
@ -17,6 +23,11 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.PrintWriter;
|
|
|
import java.io.StringWriter;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
import java.util.UUID;
|
|
|
|
|
|
/**
|
|
|
* 易联众统一支付服务类
|
|
@ -37,10 +48,42 @@ public class OnePayService {
|
|
|
@Autowired
|
|
|
private HospitalMappingDao hospitalMappingDao;
|
|
|
|
|
|
@Autowired
|
|
|
ObjectMapper objectMapper;
|
|
|
|
|
|
@Autowired
|
|
|
ChargeDao chargeDao;
|
|
|
@Autowired
|
|
|
PatientDao patientDao;
|
|
|
|
|
|
/**
|
|
|
* 查询绑卡信息
|
|
|
*/
|
|
|
public BindCard bindCard(String patient,String openid) throws Exception
|
|
|
{
|
|
|
BindCard card = bindCard(openid);
|
|
|
|
|
|
//更新患者信息
|
|
|
if(card!=null)
|
|
|
{
|
|
|
Patient p = patientDao.findByCode(patient);
|
|
|
p.setOpenid(openid);
|
|
|
p.setSsc(card.getCardNo());
|
|
|
if(card.getIdType()=="01") //身份证
|
|
|
{
|
|
|
p.setIdcard(card.getIdNo());
|
|
|
}
|
|
|
p.setName(card.getUserName());
|
|
|
patientDao.save(p);
|
|
|
}
|
|
|
|
|
|
return card;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询绑卡信息
|
|
|
*/
|
|
|
public BindCard bindCard(String openid) throws Exception
|
|
|
private BindCard bindCard(String openid) throws Exception
|
|
|
{
|
|
|
Boolean isSuccess = true;
|
|
|
String msgBody = "";
|
|
@ -64,11 +107,12 @@ public class OnePayService {
|
|
|
// 如医保绑卡信息请求参数
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("userId", openid);
|
|
|
params.put("accId", SystemConf.getInstance().getAppId()); //微信公众号开发者ID
|
|
|
requestParams.setParam(params);
|
|
|
requestParams.setTransType(config.getBindCardType());
|
|
|
ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
|
|
|
|
|
|
msgBody = JSON.toJSONString(requestParams);
|
|
|
ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
|
|
|
response = JSON.toJSONString(res);
|
|
|
|
|
|
// 如医保卡绑卡信息返回参数
|
|
@ -106,7 +150,7 @@ public class OnePayService {
|
|
|
/**
|
|
|
* 家庭医生签约支付
|
|
|
*/
|
|
|
public String charge(String orgCode,String code,String date,String cardNo,String openid) throws Exception
|
|
|
public String charge(String orgCode,String signCode,String patient,String openid) throws Exception
|
|
|
{
|
|
|
//获取机构映射
|
|
|
HospitalMapping hos = hospitalMappingDao.findByCode(orgCode);
|
|
@ -115,60 +159,106 @@ public class OnePayService {
|
|
|
throw new Exception("no hospital mapping!");
|
|
|
}
|
|
|
|
|
|
return charge(hos.getAppId(), hos.getAppSecret(), code, date, cardNo, openid);
|
|
|
return charge(orgCode,hos.getName(),hos.getAppId(), hos.getAppSecret(), signCode,patient,openid);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 家庭医生签约支付
|
|
|
* 家庭医生签约支付,成功则返回支付路径
|
|
|
*/
|
|
|
public String charge(String appId,String appSecret,String code,String date,String cardNo,String openid) throws Exception
|
|
|
private String charge(String orgCode,String orgName,String appId,String appSecret,String signCode,String patient,String openid) throws Exception
|
|
|
{
|
|
|
Boolean isSuccess = true;
|
|
|
String msgBody = "";
|
|
|
String response = "";
|
|
|
String error = "";
|
|
|
String result = "";
|
|
|
String channel = "WX_MMP"; // 医保支付渠道
|
|
|
String subject = "家庭医生签约支付"; // 订单名称
|
|
|
|
|
|
OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(),appId, appSecret, signType, encryptType);
|
|
|
|
|
|
WlyyCharge charge = new WlyyCharge();
|
|
|
String uuid = UUID.randomUUID().toString().replaceAll("-", "");
|
|
|
charge.setSignCode(signCode); //签约代码
|
|
|
charge.setCode(uuid); // 接入应用支付业务流水号
|
|
|
Date now = new Date();
|
|
|
charge.setCreateTime(now);
|
|
|
charge.setPatient(patient); // 用户
|
|
|
charge.setOpenid(openid); // 用戶微信openid
|
|
|
try {
|
|
|
BindCard card= bindCard(openid);
|
|
|
String name = card.getUserName();
|
|
|
String ssc = card.getCardNo();
|
|
|
String idType = card.getIdType();
|
|
|
String idNo = card.getIdNo();
|
|
|
charge.setName(name);
|
|
|
charge.setIdType(idType);
|
|
|
charge.setIdNo(idNo);
|
|
|
charge.setHospital(orgCode);
|
|
|
charge.setHospitalName(orgName);
|
|
|
charge.setChannel(channel);
|
|
|
charge.setMerchName(orgName);
|
|
|
charge.setSubject(subject);
|
|
|
|
|
|
/*private Integer totalAmount; // 交易总金额
|
|
|
private Integer selfpayAmount; // 自费金额
|
|
|
private Integer insuranceAmount; // 医保支付金额
|
|
|
private Integer feeDetail; // 费用明细*/
|
|
|
|
|
|
|
|
|
|
|
|
SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
|
String currentDateTime = formatter.format(now);
|
|
|
RequestParams requestParams = new RequestParams();
|
|
|
requestParams.setAppId(appId);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
requestParams.setTimestamp(currentDateTime);
|
|
|
requestParams.setSignType(signType);
|
|
|
requestParams.setEncryptType(encryptType);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
requestParams.setTransType(config.getChargeType());
|
|
|
|
|
|
//业务参数
|
|
|
JSONObject params = new JSONObject();
|
|
|
|
|
|
params.put("outSettleNo",code); //接入应用结算业务流水号
|
|
|
params.put("outSettleTime",date); //接入应用内结算时间
|
|
|
params.put("outChargeNo",uuid); //接入应用结算业务流水号
|
|
|
params.put("outChargeTime",currentDateTime); //接入应用内结算时间
|
|
|
params.put("userId",openid); //用户 ID
|
|
|
params.put("cardNo",cardNo); //医保卡号"D64775061"
|
|
|
params.put("cardNo",ssc); //医保卡号"D64775061"
|
|
|
|
|
|
//获取绑卡信息
|
|
|
params.put("userName",name);
|
|
|
params.put("idType",idType);
|
|
|
params.put("idNo",idNo);
|
|
|
params.put("totalAmount","1"); //交易总金额
|
|
|
params.put("selfpayAmount","0"); //自费金额
|
|
|
params.put("insuranceAmount","1"); //医保支付金额
|
|
|
params.put("returnUrl","http://"); //页面跳转地址
|
|
|
params.put("feeDetail","{\"itemName\":\"家庭医生签约支付\",\"itemDesc\":\"家庭医生签约支付\",\"itemOrigPrice\":\"120\",\"itemNowPrice\":\"120\",\"itemNum\":\"1\",\"itemTotalAmt\":\"120\"}"); //费用明细
|
|
|
params.put("channel","WX_MMP"); //微信医保支付
|
|
|
//extendParams 扩展入参
|
|
|
//requestContent 请求结构体
|
|
|
params.put("returnUrl","https://mp.weixin.qq.com/insurance/pay/detail"); //页面跳转地址
|
|
|
params.put("feeDetail","[{\"itemName\":\"家庭医生签约支付\",\"itemDesc\":\"家庭医生签约支付\",\"itemOrigPrice\":\"1\",\"itemNowPrice\":\"1\",\"itemNum\":\"1\",\"itemTotalAmt\":\"1\"}]"); //费用明细
|
|
|
params.put("channel",channel); //微信医保支付
|
|
|
params.put("merchName",orgName); //收款单位名称
|
|
|
params.put("subject",subject); //订单名称
|
|
|
//params.put("wxToken","");
|
|
|
|
|
|
|
|
|
//extendParams 扩展入参
|
|
|
Map<String,String> map = new HashMap<>();
|
|
|
map.put("feeType","04");//家庭医生签约
|
|
|
map.put("settleType","02"); //健康账户支付
|
|
|
params.put("requestContent",objectMapper.writeValueAsString(map));// 请求结构体
|
|
|
requestParams.setParam(params);
|
|
|
msgBody = JSON.toJSONString(requestParams);
|
|
|
//执行支付
|
|
|
ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
|
|
|
msgBody = JSON.toJSONString(requestParams);
|
|
|
response = JSON.toJSONString(res);
|
|
|
|
|
|
if (OnepayDefaultClient.isSuccessful(res)) {
|
|
|
JSONObject json = res.getParam();
|
|
|
result = String.valueOf(json.get("settleNo")); //医保结算业务流水号
|
|
|
String payUrl = String.valueOf(json.get("payUrl"));
|
|
|
|
|
|
//业务处理***********
|
|
|
String chargeNo = String.valueOf(json.get("chargeNo")); //医保结算业务流水号
|
|
|
result = String.valueOf(json.get("payUrl"));
|
|
|
charge.setTradeStatus("0");//交易状态0 成功 1 失败 2 已退款
|
|
|
charge.setChargeNo(chargeNo);
|
|
|
|
|
|
} else {
|
|
|
charge.setTradeStatus("1");
|
|
|
isSuccess = false;
|
|
|
error = "请求失败,返回结果:" + res.getRespCode() + "," + res.getRespMsg();
|
|
|
}
|
|
@ -180,6 +270,8 @@ public class OnePayService {
|
|
|
error = sw.toString();
|
|
|
}
|
|
|
|
|
|
//保存交易记录
|
|
|
chargeDao.save(charge);
|
|
|
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,config.getChargeType(),"家庭医生签约支付","POST",null,msgBody,response,error,logService.onepayType);
|
|
@ -217,12 +309,12 @@ public class OnePayService {
|
|
|
|
|
|
//业务参数
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("outSettleNo",code); //接入应用结算业务流水号
|
|
|
params.put("settleNo","");
|
|
|
params.put("outChargeNo",code); //接入应用结算业务流水号
|
|
|
|
|
|
requestParams.setParam(params);
|
|
|
msgBody = JSON.toJSONString(requestParams);
|
|
|
//执行支付
|
|
|
ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
|
|
|
msgBody = JSON.toJSONString(requestParams);
|
|
|
response = JSON.toJSONString(res);
|
|
|
|
|
|
if (OnepayDefaultClient.isSuccessful(res)) {
|
|
@ -244,7 +336,71 @@ public class OnePayService {
|
|
|
}
|
|
|
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,config.getChargeType(),"家庭医生签约支付","POST",null,msgBody,response,error,logService.onepayType);
|
|
|
logService.saveHttpLog(isSuccess,config.getChargeType(),"家庭医生签约支付查询","POST",null,msgBody,response,error,logService.onepayType);
|
|
|
|
|
|
if(!isSuccess)
|
|
|
{
|
|
|
throw new Exception(error);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 生成电子社保卡
|
|
|
*/
|
|
|
public String createSicard(String patient,String openid) throws Exception
|
|
|
{
|
|
|
Boolean isSuccess = true;
|
|
|
String msgBody = "";
|
|
|
String response = "";
|
|
|
String error = "";
|
|
|
String result = "";
|
|
|
|
|
|
String appId = config.getOnepayAppId();
|
|
|
String appSecret = config.getOnepayAppSecret();
|
|
|
OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(),appId, appSecret, signType, encryptType);
|
|
|
|
|
|
try {
|
|
|
RequestParams requestParams = new RequestParams();
|
|
|
requestParams.setAppId(appId);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
requestParams.setSignType(signType);
|
|
|
requestParams.setEncryptType(encryptType);
|
|
|
requestParams.setTimestamp(DateUtil.getCurrentDateTime());
|
|
|
|
|
|
// 请求报文体参数,详见接口文档各接口——请求参数定义
|
|
|
// 如医保绑卡信息请求参数
|
|
|
JSONObject params = new JSONObject();
|
|
|
params.put("userId", openid);
|
|
|
params.put("accId", SystemConf.getInstance().getAppId()); //微信公众号开发者ID
|
|
|
requestParams.setParam(params);
|
|
|
requestParams.setTransType(config.getCreateSicardType());
|
|
|
|
|
|
msgBody = JSON.toJSONString(requestParams);
|
|
|
ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
|
|
|
response = JSON.toJSONString(res);
|
|
|
|
|
|
// 如医保卡绑卡信息返回参数
|
|
|
if (OnepayDefaultClient.isSuccessful(res)) {
|
|
|
JSONObject json = res.getParam();
|
|
|
result = String.valueOf(json.get("sicardUrl")); //电子社保卡连接
|
|
|
}
|
|
|
else {
|
|
|
isSuccess = false;
|
|
|
error = "请求失败,返回结果:" + res.getRespCode() + "," + res.getRespMsg();
|
|
|
}
|
|
|
}
|
|
|
catch (Exception ex) {
|
|
|
isSuccess = false;
|
|
|
StringWriter sw = new StringWriter();
|
|
|
PrintWriter pw = new PrintWriter(sw);
|
|
|
ex.printStackTrace(pw);
|
|
|
error = sw.toString();
|
|
|
}
|
|
|
|
|
|
//保存http日志
|
|
|
logService.saveHttpLog(isSuccess,config.getBindCardType(),"生成电子社保卡","POST",null,msgBody,response,error,logService.onepayType);
|
|
|
|
|
|
if(!isSuccess)
|
|
|
{
|