소스 검색

在线缴费 异步回调

wujunjie 7 년 전
부모
커밋
36585805d2

+ 25 - 4
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/charge/ChargeDao.java

@ -12,6 +12,8 @@ import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.Date;
import java.util.List;
public interface ChargeDao extends PagingAndSortingRepository<WlyyCharge, Long>, JpaSpecificationExecutor<WlyyCharge> {
@ -28,14 +30,33 @@ public interface ChargeDao extends PagingAndSortingRepository<WlyyCharge, Long>,
    WlyyCharge findByChargeRelation(String chargeRelation);
    /**
     * 根据流水号更新wlyy_charge数据
     * 根据code查询支付情况
     *
     * @param chargeCode
     * @return
     */
    @Query("select a from WlyyCharge a where a.code = ?1 ")
    WlyyCharge findByCode(String chargeCode);
    /**
     * 根据code查询上传状态 为0不需要更改数据
     *
     * @param code
     * @return
     */
    @Query("select a from WlyyCharge a where a.code = ?1 ")
    WlyyCharge getUploadStatus(String code);
    /**
     * 根据code更新wlyy_charge数据
     *
     * @param chargeNo
     * @param chargeCode
     * @return
     */
    @Modifying
    @Query("update WlyyCharge a set a.tradeStatus = '0' where a.chargeNo = ?1 ")
    WlyyCharge updateByChargeNo(String chargeNo);
    @Query("update WlyyCharge a set a.tradeStatus = ?9,a.chargeTime = ?2, a.updateTime = ?3, a.totalAmount = ?4, " +
            " a.insuranceAmount = ?5, a.selfpayAmount =?6 ,a.billNo = ?7, a.miRegisterNo = ?8 where a.code = ?1 ")
    WlyyCharge updateByChargeCode(String chargeCode, String chargeTime, Date updateTime, Integer totalAmount, Integer insuranceAmount, Integer selfPayAmount, String billNo, String miRegisterNo,String tradeStatus);
    List<WlyyCharge> findByPatient(String patient, Pageable pageRequest);
}

+ 3 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/patient/SignFamilyDao.java

@ -403,10 +403,10 @@ public interface SignFamilyDao extends PagingAndSortingRepository<SignFamily, Lo
    @Query(value = " select a.*  from wlyy_sign_family a where a.patient = ?1  and a.status = -4 and a.team_code = ?2 order by a.apply_date desc limit 0,1", nativeQuery = true)
    SignFamily findOutTimeSigningByPatientAndTeamCode(String patient,String teamCode);
    //      完成缴费后更新签约开始时间 缴费状态 medical_insurance_num 医保流水号
    //      完成缴费后更新签约开始时间begin 缴费状态expensesStatus 医保流水号medical_insurance_num  扣费时间expenses_time
    @Modifying
    @Query("update SignFamily a set a.begin = ?2 ,a.medicalInsuranceNum=?3,a.expensesStatus = ?4  where a.patient = ?1 ")
    int updatePatientBegin(String patient, Date begin,String medicalInsuranceNum,String expensesStatus );
    @Query("update SignFamily a set a.begin = ?2 ,a.medicalInsuranceNum=?3,a.expensesStatus = ?4,a.expensesTime = ?2 where a.code = ?1 ")
    int updatePatientBegin(String code, Date begin,String medicalInsuranceNum,String expensesStatus );
    //查询居民的扣费状态
    @Query( " select a from SignFamily a where a.patient = ?1 ")

+ 6 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/FamilyContractService.java

@ -892,9 +892,10 @@ public class FamilyContractService extends BaseService {
        }
        SignFamily sf = new SignFamily();
        String signCode = getCode();
        sf.setSignYear(DateUtil.getSignYear()+"");//设置签约年度
        sf.setBegin(DateUtil.getNowDateShort());
        sf.setCode(getCode());
        sf.setCode(signCode);
        sf.setCzrq(new Date());
        //设置全科医生的行政团队
@ -1095,6 +1096,8 @@ public class FamilyContractService extends BaseService {
            json.put("date", DateUtil.dateToStrShort(sf.getBegin()));
            json.put("content", content);
            json.put("remark", ""); //您好,您成功签约家庭医生
//            添加签约code by wjj  2017.7.18
            json.put("signCode", signCode);
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                // 添加到发送队列
                PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);
@ -1430,6 +1433,8 @@ public class FamilyContractService extends BaseService {
            json.put("date", DateUtil.dateToStrShort(new Date()));
            json.put("content", content);
            json.put("remark", ""); //您好,您成功签约家庭医生
//            添加签约code by wjj 2017.7.18
            json.put("signCode",sf.getCode()); //签约code
            // 添加到发送队列
            if (StringUtils.isNotBlank(sf.getOpenid())) {
                PushMsgTask.getInstance().putWxMsg(access_token, 1, sf.getOpenid(), sf.getName(), json);

+ 3 - 3
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/SignWebService.java

@ -529,7 +529,7 @@ public class SignWebService extends BaseService {
            //            新增缴费流水号
            WlyyCharge charge = chargeDao.findByChargeRelation(signCode);
            if (charge != null) {
                jsonObject.put("chargeNo", charge.getChargeNo());
                jsonObject.put("chargeCode", charge.getCode());
            }
            if (StringUtils.isNotBlank(signFamily.getRenewFlag())) {
                jsonObject.put("isRenew", "1");
@ -657,8 +657,8 @@ public class SignWebService extends BaseService {
        jsonObject.put("statusName", statusName);
//            增加支付流水号
        if (charge!=null) {
            String chargeNo = charge.getChargeNo();
            jsonObject.put("chargeNo", chargeNo);
            String chargeCode = charge.getCode();
            jsonObject.put("chargeCode", chargeCode);
        }
        jsonArray.add(jsonObject);

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/survey/ManagerQuestionnaireService.java

@ -1411,7 +1411,7 @@ public class ManagerQuestionnaireService extends BaseService {
                    break;
            }
            String sql = "SELECT t.value,t.`name` " +
                    " FROM wlyy_survey_dimension_option t\n" +
                    " FROM wlyy_survey_dimension_option t " +
                    " WHERE t.`dimension_value`= " + value;
            List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);
            List subLabel = new ArrayList();

+ 10 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/common/Configure.java

@ -19,6 +19,16 @@ public class Configure {
	private String chargeType = "onepay.trade.medical.charge";
	private String chargeQueryType = "onepay.trade.medical.charge.query";
	private String createSicardType = "onepay.sicard.createurl";
//	易联众异步回调
	private String receiveNotify = "wlyy.onepay.receiveNotify";
	public String getReceiveNotify() {
		return receiveNotify;
	}
	public void setReceiveNotify(String receiveNotify) {
		this.receiveNotify = receiveNotify;
	}
	public String getOnepayApi() {
		return onepayApi;

+ 80 - 43
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/service/OnePayService.java

@ -5,10 +5,12 @@ import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.wlyy.entity.charge.WlyyCharge;
import com.yihu.wlyy.entity.doctor.profile.Doctor;
import com.yihu.wlyy.entity.organization.HospitalMapping;
import com.yihu.wlyy.entity.patient.Patient;
import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.charge.ChargeDao;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
@ -61,6 +63,8 @@ public class OnePayService {
    PatientDao patientDao;
    @Autowired
    SignFamilyDao signFamilyDao;
    @Autowired
    DoctorDao doctorDao;
    /**
     * 查询绑卡信息(本人)
@ -122,11 +126,16 @@ public class OnePayService {
        try {
            RequestParams requestParams = new RequestParams();
//            requestParams.setTransType();
//            requestParams.setVersion();
//            requestParams.setSign();
//            requestParams.setEncryptData();
            requestParams.setAppId(appId);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setSignType(signType);
            requestParams.setEncryptType(encryptType);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            // 请求报文体参数,详见接口文档各接口——请求参数定义
            // 如医保绑卡信息请求参数
@ -143,6 +152,7 @@ public class OnePayService {
            // 如医保卡绑卡信息返回参数
            if (OnepayDefaultClient.isSuccessful(res)) {
                JavaType javaType = objectMapper.getTypeFactory().constructParametricType(List.class, BindCard.class);
//                只返回了业务出参的附属绑卡情况 res.getRespCode()级别获取所有返回参数
                result = objectMapper.readValue(objectMapper.writeValueAsString(res.getParam().get("attachList")), javaType);
            } else {
                isSuccess = false;
@ -156,7 +166,7 @@ public class OnePayService {
            error = sw.toString();
        }
        //保存http日志
        //type=3易联众接口 保存http日志
        logService.saveHttpLog(isSuccess, config.getBindCardType(), "查询绑卡信息", "POST", null, msgBody, response, error, logService.onepayType);
        if (!isSuccess) {
@ -169,20 +179,20 @@ public class OnePayService {
    /**
     * 家庭医生签约支付
     */
    public String charge(String orgCode, String chargeType, String chargeRelation, Integer totalAmount, String feeDetail, String patient, String openid) throws Exception {
    public String charge(String orgCode, String chargeType, String chargeRelation, Integer totalAmount, String feeDetail, String patient, String openid,String accessToken) throws Exception {
        //获取机构映射
        HospitalMapping hos = hospitalMappingDao.findByCode(orgCode);
        if (hos == null) {
            throw new Exception("no hospital mapping!");
        }
        return charge(orgCode, hos.getName(), hos.getAppId(), hos.getAppSecret(), chargeType, chargeRelation, totalAmount, feeDetail, patient, openid);
        return charge(orgCode, hos.getName(), hos.getAppId(), hos.getAppSecret(), chargeType, chargeRelation, totalAmount, feeDetail, patient, openid,accessToken);
    }
    /**
     * 家庭医生签约支付,成功则返回支付路径
     */
    private String charge(String orgCode, String orgName, String appId, String appSecret, String chargeType, String chargeRelation, Integer totalAmount, String feeDetail, String patient, String openid) throws Exception {
    private String charge(String orgCode, String orgName, String appId, String appSecret, String chargeType, String chargeRelation, Integer totalAmount, String feeDetail, String patient, String openid,String accessToken) throws Exception {
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
@ -192,12 +202,12 @@ public class OnePayService {
        String subject = "家庭医生签约支付";   //  订单名称
        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), appId, appSecret, signType, encryptType);
//     未真正完成支付以前预存储支付信息到wlyy_charge表
        WlyyCharge charge = new WlyyCharge();
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        charge.setChargeType(chargeType);   //交易类型
        charge.setChargeRelation(chargeRelation);  //交易关联代码
        charge.setChargeRelation(chargeRelation);  //交易关联代码 wlyy_sign_family字段code
        charge.setCode(uuid);  //  接入应用支付业务流水号
        Date now = new Date();
        charge.setCreateTime(now);
@ -228,6 +238,9 @@ public class OnePayService {
            SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
            String currentDateTime = formatter.format(now);
            RequestParams requestParams = new RequestParams();
//            requestParams.setVersion();
//            requestParams.setSign();
//            requestParams.setEncryptData();
            requestParams.setAppId(appId);
            requestParams.setTimestamp(currentDateTime);
            requestParams.setSignType(signType);
@ -251,36 +264,49 @@ public class OnePayService {
//            params.put("insuranceAmount",insuranceAmount);   //医保支付金额
//            params.put("financialAmount",financialAmount);   //财政补贴金额
//            params.put("returnUrl","https://mp.weixin.qq.com/insurance/pay/detail");   //页面跳转地址
            params.put("returnUrl", "/html/qygl/html/pay-result.html");   //页面跳转地址
            Properties systemConf = SystemConf.getInstance().getSystemProperties();
            String returnUrl = systemConf.getProperty("return_url");
            params.put("returnUrl",returnUrl);   //页面跳转地址
            params.put("feeDetail", feeDetail);   //费用明细
            params.put("channel", channel);  //微信医保支付
            params.put("merchName", orgName);  //收款单位名称
            params.put("subject", subject);  //订单名称
            //params.put("wxToken","");
            params.put("wxToken",accessToken);
            //extendParams 扩展入参
            //家庭医生签约信息
            Map<String, String> familyContent = new HashMap<>();
            familyContent.put("moRegNo", "04");//医院签约号
            familyContent.put("moRegName", "02"); //签约人姓名
            familyContent.put("moRegAddr", "02"); //签约人地址
            familyContent.put("moRegTelephone", "04");//签约人联系电话
            familyContent.put("moRegOrgNo", "02"); //签约机构
            familyContent.put("moRegDocNo", "04");//签约医生编号
            familyContent.put("moRegDocName", "02"); //签约医生姓名
            familyContent.put("moRegTime", "02"); //签约时间
            familyContent.put("moRegEndTime", "02"); //签约截止时间
            //      根据签约code查询签约信息
            SignFamily signFamily = signFamilyDao.findByCode(chargeRelation);
            if (signFamily!=null){
//                //签约人Code
                String signDoctorCode = signFamily.getSignDoctorCode();
                String people = signFamily.getPatient();
//                Doctor doctor = doctorDao.findByCode(signDoctorCode);
                Patient user = patientDao.findByCode(people);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
                Map<String, String> familyContent = new HashMap<>();
                familyContent.put("moRegNo", chargeRelation);//医院签约号
                familyContent.put("moRegName",signFamily.getName()); //签约人姓名
                familyContent.put("moRegAddr",user.getAddress() ); //签约人地址
                familyContent.put("moRegTelephone", signFamily.getMobile());//签约人联系电话
                familyContent.put("moRegOrgNo", signFamily.getHospital()); //签约机构
                familyContent.put("moRegDocNo", signFamily.getSignDoctorCode());//签约医生编号
                familyContent.put("moRegDocName", signFamily.getSignDoctorName()); //签约医生姓名
                familyContent.put("moRegTime", sdf.format(signFamily.getBegin())); //签约时间
                familyContent.put("moRegEndTime", sdf.format(signFamily.getEnd())); //签约截止时间
//            familyContent.put("moRegYear", "04");//签约年度
            familyContent.put("moRegTear", "04");//签约年度
            familyContent.put("moRegSource", "02"); //签约来源
            familyContent.put("moCollectOrgNo", "02"); //扣费机构
            familyContent.put("moCollectorNo", "04");//扣费人
            familyContent.put("benefitType", "02"); //补贴类型
            familyContent.put("moBookOrgNo", "04");//登记机构
            familyContent.put("moBookerNo", "02"); //登记人
            familyContent.put("moBookTime", "02"); //登记时间
            params.put("familyContent", objectMapper.writeValueAsString(familyContent));// 请求结构体
                familyContent.put("moRegTear", signFamily.getSignYear());//签约年度
                familyContent.put("moRegSource", signFamily.getSignSource()); //签约来源
                familyContent.put("moCollectOrgNo", "03"); //扣费机构
                familyContent.put("moCollectorNo", "04");//扣费人
                familyContent.put("benefitType", signFamily.getExpensesType()); //补贴类型
                familyContent.put("moBookOrgNo", "05");//登记机构
                familyContent.put("moBookerNo", "06"); //登记人
                familyContent.put("moBookTime", "07"); //登记时间
                params.put("familyContent", objectMapper.writeValueAsString(familyContent));// 家庭医生签约信息
            }
            //请求结构体
            Map<String, String> map = new HashMap<>();
            map.put("feeType", "04");//家庭医生签约
@ -288,7 +314,7 @@ public class OnePayService {
            params.put("requestContent", objectMapper.writeValueAsString(map));// 请求结构体
            requestParams.setParam(params);
            msgBody = JSON.toJSONString(requestParams);
            //执行支付
            //执行支付  获取预支付原生返回值
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            response = JSON.toJSONString(res);
@ -300,7 +326,7 @@ public class OnePayService {
                charge.setChargeNo(chargeNo);
            } else {
                charge.setTradeStatus("1");
//                charge.setTradeStatus("1");
                isSuccess = false;
                error = "请求失败,返回结果:" + res.getRespCode() + "," + res.getRespMsg();
            }
@ -328,7 +354,7 @@ public class OnePayService {
    /**
     * 家庭医生签约支付查询
     */
    public Charge chargeQuery(String code) throws Exception {
    public Charge chargeQuery(String code,String accessToken) throws Exception {
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
@ -340,24 +366,29 @@ public class OnePayService {
        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), appId, appSecret, signType, encryptType);
        try {
            RequestParams requestParams = new RequestParams();
//            requestParams.setVersion();
//            requestParams.setSign();
//            requestParams.setEncryptData();
            requestParams.setAppId(appId);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setSignType(signType);
            requestParams.setEncryptType(encryptType);
            requestParams.setTimestamp(DateUtil.getCurrentDateTime());
            requestParams.setTransType(config.getChargeQueryType());
            //业务参数
            JSONObject params = new JSONObject();
            params.put("outChargeNo", code);  //接入应用结算业务流水号
            params.put("wxToken", accessToken);
            requestParams.setParam(params);
            msgBody = JSON.toJSONString(requestParams);
            //执行支付
            //执行支付 返回原生返回值
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            response = JSON.toJSONString(res);
            if (OnepayDefaultClient.isSuccessful(res)) {
//                只返回业务出参  res.getResponseContent()返回医保机构体
                result = JSON.toJavaObject(res.getParam(), Charge.class);
                //业务处理*******************
@ -374,7 +405,7 @@ public class OnePayService {
            error = sw.toString();
        }
        //保存http日志
        //type = 3易联众接口保存http日志
        logService.saveHttpLog(isSuccess, config.getChargeType(), "家庭医生签约支付查询", "POST", null, msgBody, response, error, logService.onepayType);
        if (!isSuccess) {
@ -450,12 +481,12 @@ public class OnePayService {
    /**
     * 更新所有记录的交易状态
     */
    private List<WlyyCharge> updateTradeStatus(List<WlyyCharge> list) {
    private List<WlyyCharge> updateTradeStatus(List<WlyyCharge> list,String accessToken) {
        //更新交易状态
        if (list != null && list.size() > 0) {
            for (WlyyCharge item : list) {
                try {
                    Charge charge = chargeQuery(item.getCode());
                    Charge charge = chargeQuery(item.getCode(),accessToken);
                    if (charge != null) {
                        item.setTradeStatus(charge.getTradeStatus());            //  交易状态0 成功 1 失败 2 已退款
                        item.setChargeNo(charge.getChargeNo());       //  流水号
@ -479,29 +510,35 @@ public class OnePayService {
    /**
     * 通过交易关联代码获取交易列表
     */
    public List<WlyyCharge> chargeList(String chargeType, String chargeRelation) throws Exception {
    public List<WlyyCharge> chargeList(String chargeType, String chargeRelation,String accessToken) throws Exception {
        List<WlyyCharge> list = chargeDao.findByChargeTypeAndChargeRelation(chargeType, chargeRelation);
        return updateTradeStatus(list);
        return updateTradeStatus(list,accessToken);
    }
    /**
     * 通过患者代码获取交易列表
     */
    public List<WlyyCharge> chargeListByPatient(String patient, Integer page, Integer size) throws Exception {
    public List<WlyyCharge> chargeListByPatient(String patient, String accessToken,Integer page, Integer size) throws Exception {
        PageRequest pageRequest = new PageRequest(page - 1, size);
        List<WlyyCharge> list = chargeDao.findByPatient(patient, pageRequest);
        return updateTradeStatus(list);
        return updateTradeStatus(list,accessToken);
    }
    /**
     * 更改数据 wlyy_sign_family wlyy_charge
     */
    public void updateData(String patient, String chargeNo) throws Exception {
        chargeDao.updateByChargeNo(chargeNo);
        signFamilyDao.updatePatientBegin(patient, new Date(), chargeNo, "1");
    public void updateData(String chargeCode,String chargeNo,String chargeTime,String totalAmount,String insuranceAmount,String selfPayAmount,String billNo,String miRegisterNo) throws Exception {
        SimpleDateFormat sdf = new SimpleDateFormat();
        Date chargeSuccess = sdf.parse(chargeTime);
        Date updateTime = new Date();
        chargeDao.updateByChargeCode(chargeCode,chargeTime,updateTime,Integer.parseInt(totalAmount),Integer.parseInt(insuranceAmount),Integer.parseInt(selfPayAmount),
                billNo,miRegisterNo,"0");
//        根据wlyy_charge的code 去查找关联代码signCode在更新签约表
        WlyyCharge charge = chargeDao.findByCode(chargeCode);
        signFamilyDao.updatePatientBegin(charge.getChargeRelation(), chargeSuccess, chargeNo, "1");
    }
}

+ 1 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/task/PushMsgTask.java

@ -285,7 +285,7 @@ public class PushMsgTask {
                if(json.has("isRenew")&&type==2){
                    //如果续签失败,不发送详情
                }else{
                    temp.setUrl(url + "ssgg/html/doctor-homepage-new.html?openid=" + openid + "&state=" + json.getString("doctor") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&isRenew="+isRenew+"&signState="+signState+"&represented="+json.getString("represented"));
                    temp.setUrl(url + "ssgg/html/doctor-homepage-new.html?openid=" + openid + "&state=" + json.getString("doctor") + "&toUser=" + json.getString("toUser") + "&toName=" + name+"&isRenew="+isRenew+"&signState="+signState+"&represented="+json.getString("represented")+"&signCode"+json.getString("signCode"));
                }
                temp.setTouser(openid);
                temp.setTopcolor("#000000");

+ 135 - 67
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/OnePayController.java

@ -7,11 +7,15 @@ import com.yihu.wlyy.entity.patient.SignFamily;
import com.yihu.wlyy.repository.charge.ChargeDao;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.patient.SignFamilyDao;
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.service.weixin.wxpay.service.OnePayService;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.WeixinBaseController;
import com.ylzinfo.onepay.sdk.OnepayDefaultClient;
import com.ylzinfo.onepay.sdk.domain.RequestParams;
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
import com.ylzinfo.onepay.sdk.exception.PayException;
import com.ylzinfo.onepay.sdk.utils.StringUtil;
@ -35,6 +39,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.Date;
@ -61,6 +67,10 @@ public class OnePayController extends WeixinBaseController {
    private SignFamilyDao signFamilyDao;
    @Autowired
    private ChargeDao chargeDao;
    @Autowired
    LogService logService;
    @Autowired
    private Configure config;
    @RequestMapping(value = "expensesStatus", method = RequestMethod.GET)
@ -70,9 +80,8 @@ public class OnePayController extends WeixinBaseController {
        try {
            //            获取居民个人信息  要根据签约code去查找签约扣费状态
            String patient = getUID();
            String singCode = "044701ea-5b23-11e6-8344-fa163e8aee56";
            SignFamily sign = signFamilyDao.findByCode(singCode);
//            String singCode = "044701ea-5b23-11e6-8344-fa163e8aee56";
//            SignFamily sign = signFamilyDao.findByCode(singCode);
//            String patient = "915cc456-5b1d-11e6-8344-fa163e8aee56";
            SignFamily signFamily = signFamilyDao.findPatientExpensesStatus(patient);
@ -158,10 +167,10 @@ public class OnePayController extends WeixinBaseController {
    @ResponseBody
    public String bindCard() throws Exception {
        try {
            //           String patient = getUID();
//            String openid = getOpenid();
            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
            String openid = "oULM4xAj9sOsHJ95ttKYd_Fjh6Hc";
            String patient = getUID();
            String openid = getOpenid();
//            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
//            String openid = "oULM4xAj9sOsHJ95ttKYd_Fjh6Hc";
            BindCard bindCard = pay.bindCard(patient, openid);//getUID(), getOpenid());      oULM4xAj9sOsHJ95ttKYd_Fjh6Hc
            String sicardUrl = pay.createSicard(patient, openid);//getUID(), getOpenid());
            if (bindCard != null) {
@ -205,12 +214,12 @@ public class OnePayController extends WeixinBaseController {
            @RequestParam String feeDetail) throws Exception {
        try {
            //            获取居民个人信息
//            String patient = getUID();
//            String openId = getOpenid();
            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
            String openId = "oULM4xAj9sOsHJ95ttKYd_Fjh6Hc";
            String patient = getUID();
            String openId = getOpenid();
//            String patient = "0cc6e4562de2437ab2dbbf51a9fc3b49";
//            String openId = "oULM4xAj9sOsHJ95ttKYd_Fjh6Hc";
            if (StringUtils.isNotEmpty(openId)) {
                String settleNo = pay.charge(orgCode, chargeType, chargeRelation, totalAmount, feeDetail, patient, openId);  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
                String settleNo = pay.charge(orgCode, chargeType, chargeRelation, totalAmount, feeDetail, patient, openId,getAccessToken());  //ohNH9sh4uwuJCxIwcLJtGTX-BaSk    getUID(),getOpenid()
                return write(200, "家庭医生签约支付成功!", "data", settleNo);
            } else {
                return write(-1, "openId为空!");
@ -226,10 +235,10 @@ public class OnePayController extends WeixinBaseController {
    @RequestMapping(value = "chargeQuery", method = RequestMethod.POST)
    @ApiOperation("家庭医生签约支付查询")
    @ResponseBody
    public String chargeQuery(@ApiParam(name = "code", value = "支付流水号", defaultValue = "")
    public String chargeQuery(@ApiParam(name = "code", value = "接入应用业务流水号", defaultValue = "")
                              @RequestParam String code) throws Exception {
        try {
            Charge charge = pay.chargeQuery(code);
            Charge charge = pay.chargeQuery(code,getAccessToken());
            return write(200, "家庭医生签约支付查询成功!", "data", charge);
        } catch (Exception e) {
            return error(-1, e.getMessage());
@ -245,7 +254,7 @@ public class OnePayController extends WeixinBaseController {
                             @ApiParam(name = "chargeRelation", value = "支付关联代码", defaultValue = "044701ea5b2311e68344fa163e8aee56")
                             @RequestParam String chargeRelation) throws Exception {
        try {
            List<WlyyCharge> charge = pay.chargeList(chargeType, chargeRelation);
            List<WlyyCharge> charge = pay.chargeList(chargeType, chargeRelation,getAccessToken());
            return write(200, "获取某次签约的支付记录成功!", "data", charge);
        } catch (Exception e) {
            return error(-1, e.getMessage());
@ -263,7 +272,7 @@ public class OnePayController extends WeixinBaseController {
                                      @ApiParam(name = "size", value = "每页几行", defaultValue = "10")
                                      @RequestParam Integer size) throws Exception {
        try {
            List<WlyyCharge> charge = pay.chargeListByPatient(patient, page, size);
            List<WlyyCharge> charge = pay.chargeListByPatient(patient,getAccessToken(), page, size);
            return write(200, "获取患者的支付记录成功!", "data", charge);
        } catch (Exception e) {
            return error(-1, e.getMessage());
@ -320,39 +329,56 @@ public class OnePayController extends WeixinBaseController {
    }
    /**
     * @param request
     * @param response
     * @throws IOException
     * @throws PayException
     * 页面回调更新数据
     */
    @RequestMapping(value = "/returnUrl", method = RequestMethod.GET)
    @ApiOperation("商户页面跳转(模拟测试)")
    public void testReturnUrl(HttpServletRequest request, HttpServletResponse response) throws IOException, PayException {
        response.setContentType("text/html;charset=utf-8");
        response.getWriter().write("返回结果:\n" + request.getQueryString() + "\n");
        String onepayUrl = request.getParameter("onepayUrl");
        String appId = "1BHEOI11C00J7B2CA8C0000071FA53E1";
        String appSecret = "1BHEOH8HB0006E0A0A0A00002DB28BC5";
        String signType = "MD5";
        String encryptType = "DES";
    @ApiOperation("商户页面跳转")
    public String testReturnUrl(@RequestParam String jsonData) throws IOException, PayException {
        try {
            OnepayDefaultClient client = new OnepayDefaultClient(onepayUrl, appId, appSecret, signType, encryptType);
            Map<String, String> returnParams = getRequestMap(request.getQueryString());
           /* boolean isVerify = client.verifyReturnSign(returnParams, returnParams.get("sign"));
            if (isVerify) {
                response.getWriter().write("签名结果:\nSIGN SUCCESS.\n");
                // TODO 继续处理业务
//                更改数据 wlyy_sign_family wlyy_charge
            } else {
                response.getWriter().write("签名结果:\nSIGN ERROR !!!\n");
            }*/
           String patient = request.getParameter("userId");
           String chargNo = request.getParameter("chargeNo");
            pay.updateData(patient,chargNo);
            JSONObject json = new JSONObject(jsonData);
            JSONObject requestParam = json.getJSONObject("param");//业务出参
            String chargeNo = requestParam.getString("chargeNo"); //支付平台流水号
            String chargeTime = requestParam.getString("chargeTime");//支付平台交易成功时间
            String outChargeNo = requestParam.getString("outChargeNo");//接入应用业务流水号
            String outChargeTime = requestParam.getString("outChargeTime");//接入应用时间
            String channel = requestParam.getString("channel");//支付方式
            String billNo = requestParam.getString("billNo");//待结算费用单据号
            String cardNo = requestParam.getString("cardNo");//医保卡号
            String totalAmount = requestParam.getString("totalAmount");//交易总金额
            String insuranceAmount = requestParam.getString("insuranceAmount");//医保支付金额
            String selfPayAmount = requestParam.getString("selfPayAmount");//自付金额
            String userId = requestParam.getString("userId");//用户openID
            String userName = requestParam.getString("userName");//用户名字
            String idType = requestParam.getString("idType");//证件类型
            String idNo = requestParam.getString("idNo");//证件号码
            String tradeStatus = requestParam.getString("tradeStatus");//交易状态
            JSONObject responseContents = json.getJSONObject("responseContent");//医保结构体
            String miRegisterNo = responseContents.getString("miRegisterNo");//医保签约号
            String miCollectDate = responseContents.getString("miCollectDate");//扣费日期
            String miCollectTime = responseContents.getString("miCollectTime");//扣费时间
            String miSettleNo = responseContents.getString("miSettleNo");//扣费单据号
            String miCollectStatus = responseContents.getString("miCollectStatus");//扣费状态
            String miRegisterStatus = responseContents.getString("miRegisterStatus");//登记状态
            String cadresPay = responseContents.getString("cadresPay");//政府补贴支付
            String miTotalFee = responseContents.getString("miTotalFee");//扣费总额
            String healthCarePay = responseContents.getString("healthCarePay");//医保统筹支付
//                responseContents.getString("healthPay");
            String heathPay = responseContents.getString("heathPay");//健康账户支付
            String accountPay = responseContents.getString("accountPay");//医保账户支付
            String selfPay = responseContents.getString("selfPay");//个人现金支付
//                判断是否需要更新数据 needUpload为0不需要更新
            WlyyCharge charge = chargeDao.getUploadStatus(outChargeNo);
            if (charge!=null&&!("0".equals(charge.getNeedUpload()))){
                pay.updateData(outChargeNo, chargeNo,chargeTime,totalAmount,insuranceAmount,selfPayAmount,billNo,miRegisterNo);
            }
            return write(200, "请求成功!");
        } catch (Exception e) {
            response.getWriter().write(e.getMessage());
            return error(-1, e.getMessage());
        }
    }
@ -367,6 +393,9 @@ public class OnePayController extends WeixinBaseController {
    @RequestMapping(value = "/receiveNotify", method = RequestMethod.POST)
    @ApiOperation("异步回调数据更改")
    public void receiveNotify(HttpServletRequest request, HttpServletResponse response) throws IOException, PayException {
        Boolean isSuccess = false;
        String error= "";
        String responses = "";
        response.setContentType("text/html;charset=utf-8");
        String appId = "1BHEOI11C00J7B2CA8C0000071FA53E1";
        String appSecret = "1BHEOH8HB0006E0A0A0A00002DB28BC5";
@ -382,30 +411,69 @@ public class OnePayController extends WeixinBaseController {
        OnepayDefaultClient client = new OnepayDefaultClient("", appId, appSecret, encryptRes.getSignType(), encryptRes.getEncryptType());
        try {
           /* client.execute(encryptRes);
            LOGGER.info("解密前:{}", JSON.toJSONString(encryptRes));
            ResponseParams<?> decryptRes = client.decryptNotifyResponse(encryptRes);
            LOGGER.info("解密后:{}", JSON.toJSONString(decryptRes));
            boolean isDecrypt = ("-1".equals(decryptRes.getRespCode()) ? false : true); // 是否解密失败
            if (!isDecrypt) {
                response.getWriter().write("DECRYPT FAILURE");
            } else {
                boolean isVerify = client.verifyResponseSign(decryptRes);
                LOGGER.info("验签结果:{}", isVerify);
                if (!isVerify) {
                    response.getWriter().write("FAILURE");
                } else {
//                    更改数据 wlyy_sign_family wlyy_charge
                    response.getWriter().write("SUCCESS");
//            已经封装的加解密及签名验证
            RequestParams requestParams = JSON.parseObject(params, RequestParams.class);
            ResponseParams<com.alibaba.fastjson.JSONObject> res =  client.execute(requestParams);
            responses = JSON.toJSONString(res);
            if (OnepayDefaultClient.isSuccessful(res)) {
                isSuccess = true;
                String param = request.getParameter("param");//业务出参
                JSONObject requestParam = new JSONObject(param);
                String chargeNo = requestParam.getString("chargeNo"); //支付平台流水号
                String chargeTime = requestParam.getString("chargeTime");//支付平台交易成功时间
                String outChargeNo = requestParam.getString("outChargeNo");//接入应用业务流水号
                String outChargeTime = requestParam.getString("outChargeTime");//接入应用时间
                String channel = requestParam.getString("channel");//支付方式
                String billNo = requestParam.getString("billNo");//待结算费用单据号
                String cardNo = requestParam.getString("cardNo");//医保卡号
                String totalAmount = requestParam.getString("totalAmount");//交易总金额
                String insuranceAmount = requestParam.getString("insuranceAmount");//医保支付金额
                String selfPayAmount = requestParam.getString("selfPayAmount");//自付金额
                String userId = requestParam.getString("userId");//用户openID
                String userName = requestParam.getString("userName");//用户名字
                String idType = requestParam.getString("idType");//证件类型
                String idNo = requestParam.getString("idNo");//证件号码
                String tradeStatus = requestParam.getString("tradeStatus");//交易状态
                String responseContent = request.getParameter("responseContent");//医保结构体
                JSONObject responseContents = new JSONObject(responseContent);
                String miRegisterNo = responseContents.getString("miRegisterNo");//医保签约号
                String miCollectDate = responseContents.getString("miCollectDate");//扣费日期
                String miCollectTime = responseContents.getString("miCollectTime");//扣费时间
                String miSettleNo = responseContents.getString("miSettleNo");//扣费单据号
                String miCollectStatus = responseContents.getString("miCollectStatus");//扣费状态
                String miRegisterStatus = responseContents.getString("miRegisterStatus");//登记状态
                String cadresPay = responseContents.getString("cadresPay");//政府补贴支付
                String miTotalFee = responseContents.getString("miTotalFee");//扣费总额
                String healthCarePay = responseContents.getString("healthCarePay");//医保统筹支付
//                responseContents.getString("healthPay");
                String heathPay = responseContents.getString("heathPay");//健康账户支付
                String accountPay = responseContents.getString("accountPay");//医保账户支付
                String selfPay = responseContents.getString("selfPay");//个人现金支付
//                判断是否需要更新数据 needUpload为0不需要更新
                WlyyCharge charge = chargeDao.getUploadStatus(outChargeNo);
                if (charge!=null&&!("0".equals(charge.getNeedUpload()))){
                    pay.updateData(outChargeNo, chargeNo,chargeTime,totalAmount,insuranceAmount,selfPayAmount,billNo,miRegisterNo);
                }
            }*/
            String patient = request.getParameter("userId");
            String chargNo = request.getParameter("chargeNo");
            pay.updateData(patient,chargNo);
        } catch (Exception e) {
            response.getWriter().write(e.getMessage());
            }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();
            response.getWriter().write(ex.getMessage());
        }
        //                记录log日志到数据库
                logService.saveHttpLog(isSuccess, config.getReceiveNotify(), "异步支付通知", "POST", null, params, responses, error, logService.onepayType);
    }
}

+ 3 - 0
patient-co-wlyy/src/main/resources/system.properties

@ -75,6 +75,9 @@ prenatal_inspector_job_trigger=0 0 6 * * ?
evaluate_score_job = 0 0 */2 * * ?
#统一支付平台 页面跳转地址
return_url={server}/wx/html/qygl/html/bind_return.html
#-------------------------开发环境配置-------------------------#
## 服务器基本配置