ソースを参照

对接易联众,统一支付

hzp 8 年 前
コミット
baad8a0fec

+ 20 - 0
patient-co-wlyy/pom.xml

@ -156,6 +156,12 @@
            <artifactId>kaptcha</artifactId>
            <version>2.3</version>
        </dependency>
        <dependency>
            <groupId>com.ylzinfo.onepay</groupId>
            <artifactId>onepay</artifactId>
            <version>1.0</version>
        </dependency>
        <!-- spring data access -->
        <dependency>
            <groupId>org.springframework.data</groupId>
@ -539,6 +545,20 @@
                <artifactId>maven-install-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>onepay</id>
                        <phase>initialize</phase>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                        <configuration>
                            <groupId>com.ylzinfo.onepay</groupId>
                            <artifactId>onepay</artifactId>
                            <version>1.0</version>
                            <packaging>jar</packaging>
                            <file>${basedir}/src/main/resources/onepay-java-sdk.jar</file>
                        </configuration>
                    </execution>
                    <execution>
                        <id>kaptcha</id>
                        <phase>initialize</phase>

+ 21 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/entity/organization/HospitalMapping.java

@ -22,6 +22,11 @@ public class HospitalMapping extends IdEntity {
	private String type;
	// 映射机构代码
	private String mappingCode;
	// 易联众appid
	private String appId;
	// 易联众app secret
	private String appSecret;
	public String getType() {
		return type;
@ -54,4 +59,20 @@ public class HospitalMapping extends IdEntity {
	public void setMappingCode(String mappingCode) {
		this.mappingCode = mappingCode;
	}
	public String getAppId() {
		return appId;
	}
	public void setAppId(String appId) {
		this.appId = appId;
	}
	public String getAppSecret() {
		return appSecret;
	}
	public void setAppSecret(String appSecret) {
		this.appSecret = appSecret;
	}
}

+ 2 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/repository/organization/HospitalMappingDao.java

@ -23,4 +23,6 @@ public interface HospitalMappingDao extends PagingAndSortingRepository<HospitalM
	@Query("select a.code from HospitalMapping a where a.mappingCode=?1 and a.type=?2")
	String getCodeByMapping(String mappingCode,String type);
	HospitalMapping findByCode(String code);
}

+ 16 - 16
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/guahao/GuahaoXMService.java

@ -217,19 +217,19 @@ public class GuahaoXMService implements IGuahaoService {
            // 请求失败
            //保存http日志
            error = title;
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
            throw new Exception(error);
        } else if (StringUtils.startsWith(xml, "System-Error")) {
            // 调用失败
            //保存http日志
            error = xml.substring(xml.indexOf(":") + 1, xml.length());
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
            throw new Exception(error);
        } else if (StringUtils.startsWith(xml, "Error")) {
            // 调用失败
            //保存http日志
            error = xml.substring(xml.indexOf(":") + 1, xml.length());
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,"2");
            logService.saveHttpLog(isSuccess,url,content,method,null,msgBody,res,error,logService.archiveType);
            throw new Exception(error);
        }
    }
@ -298,7 +298,7 @@ public class GuahaoXMService implements IGuahaoService {
            }
            //保存http日志
            logService.saveHttpLog(true,ORG_LIST,content,method,null,msgBody,res,null,"2");
            logService.saveHttpLog(true,ORG_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        }
        return re;
    }
@ -343,7 +343,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,DEP_LIST,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DEP_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        return re;
    }
@ -436,7 +436,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        return re;
    }
@ -486,7 +486,7 @@ public class GuahaoXMService implements IGuahaoService {
        verificationXml(xml,"获取医生排班表失败!",DOCTOR_ARRANGE,content,method,msgBody,res);
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_ARRANGE,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DOCTOR_ARRANGE,content,method,null,msgBody,res,null,logService.archiveType);
        return xmlToList(xml);
    }
@ -562,7 +562,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_ARRANGE_SIMPLE,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DOCTOR_ARRANGE_SIMPLE,content,method,null,msgBody,res,null,logService.archiveType);
        return re;
    }
@ -630,7 +630,7 @@ public class GuahaoXMService implements IGuahaoService {
            //xml验证
            verificationXml(response,"获取医生排班表失败!",ORDER_CREATE,content,method,msgBody,res);
            //保存http日志
            logService.saveHttpLog(true,ORDER_CREATE,content,method,null,msgBody,res,null,"2");
            logService.saveHttpLog(true,ORDER_CREATE,content,method,null,msgBody,res,null,logService.archiveType);
            re = CreateOrderAfter(response, hospitalId, hospitalName, hosDeptId, hosDeptName, doctorId, doctorName, sectionType, startTime, endTime, patient, patientName, cardNo, clinicCard, patientPhone, null, null);
        } else {
            throw new Exception("该排班信息错误或者不存在!");
@ -685,7 +685,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(isOk,ORDER_CANCEL,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(isOk,ORDER_CANCEL,content,method,null,msgBody,res,null,logService.archiveType);
        return isOk;
    }
@ -778,7 +778,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,DOCTOR_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        return doctor;
    }
@ -856,10 +856,10 @@ public class GuahaoXMService implements IGuahaoService {
                }
                //保存http日志
                logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,"2");
                logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,logService.archiveType);
            } else {
                //保存http日志
                logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,errMsg,"2");
                logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,errMsg,logService.archiveType);
                throw new Exception(errMsg);
            }
        } catch (Exception ex) {
@ -999,7 +999,7 @@ public class GuahaoXMService implements IGuahaoService {
        }
        //保存http日志
        logService.saveHttpLog(true,REG_LIST,content,method,null,msgBody,res,null,"2");
        logService.saveHttpLog(true,REG_LIST,content,method,null,msgBody,res,null,logService.archiveType);
        return patientRegList;
    }
@ -1115,12 +1115,12 @@ public class GuahaoXMService implements IGuahaoService {
            patientReservation.setDoctorJob(guahaoDoctor.getTitle());//职称
            //保存http日志
            logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,"2");
            logService.saveHttpLog(true,ORDER_INFO,content,method,null,msgBody,res,null,logService.archiveType);
            return patientReservation;
        } else {
            //保存http日志
            logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,null,"2");
            logService.saveHttpLog(false,ORDER_INFO,content,method,null,msgBody,res,null,logService.archiveType);
            return null;
        }
    }

+ 10 - 1
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/third/httplog/LogService.java

@ -21,6 +21,13 @@ public class LogService {
    @Autowired
    private SystemDictService systemDictService;
    public String openApiType = "0";
    public String signType = "1";
    public String archiveType = "2";
    public String onepayType = "3";
    /**
     * 新增开放api调用日志
     * */
@ -48,7 +55,7 @@ public class LogService {
    /**
     * 保存http调用日志
     * 保存http调用日志  type 0开放api  1基卫接口  2市民健康网接口   3易联众接口
     */
    public void saveHttpLog(Boolean isSuccess,String url,String content,String method,String header,String params,String response,String error,String type)
    {
@ -76,4 +83,6 @@ public class LogService {
            ex.printStackTrace();
        }
    }
}

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

@ -0,0 +1,72 @@
package com.yihu.wlyy.service.weixin.wxpay.common;
import org.springframework.context.annotation.Configuration;
/**
 * User: hzp
 * Date: 20170518
 * 这里放置各种配置数据
 */
@Configuration
public class Configure {
	/******************************* 易联众统一支付平台 ***********************************************************/
	private String onepayApi = "http://120.42.37.94:1301/onepay-web/";
	private String onepayAppId = "1BGKM1UHM03P7B2CA8C000005626EB0E";
	private String onepayAppSecret = "1BGKM1UHM03I7B2CA8C00000AB682E9A";
	private String bindCardType = "onepay.sicard.bind.info";
	private String chargeType = "onepay.trade.medical.charge";
	private String chargeQueryType = "onepay.trade.medical.charge.query";
	public String getOnepayApi() {
		return onepayApi;
	}
	public String getOnepayAppId() {
		return onepayAppId;
	}
	public String getOnepayAppSecret() {
		return onepayAppSecret;
	}
	public String getBindCardType() {
		return bindCardType;
	}
	public String getChargeType() {
		return chargeType;
	}
	public String getChargeQueryType() {
		return chargeQueryType;
	}
	/******************* 微信社保支付配置 ******************************************/
	//这个就是自己要保管好的私有Key了(切记只能放在自己的后台代码里,不能放在任何可能被看到源代码的客户端程序中)
	// 每次自己Post数据给API的时候都要用这个key来对所有字段进行签名,生成的签名会放在Sign这个字段,API收到Post数据的时候也会用同样的签名算法对Post过来的数据进行签名和验证
	// 收到API的返回的时候也要用这个key来对返回的数据算下签名,跟API的Sign数据进行比较,如果值不一致,有可能数据被第三方给篡改
	private String key = "2935b54b53a957d9516c920a544f2537";
	//微信分配的公众号ID(开通公众号之后可以获取到)
	private String appID = "wxd03f859efdf0873d";
	public String getKey(){
		return key;
	}
	public String getAppid(){
		return appID;
	}
	//获取token地址
	public String TOKEN_API = "https://api.weixin.qq.com/payinsurance/gettoken";
	//挂号/诊间支付统一下单 API 接口
	public String ORDER_API = "https://api.weixin.qq.com/payinsurance/unifiedorder?access_token ACCESS_TOKEN";
}

+ 70 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/model/BindCard.java

@ -0,0 +1,70 @@
package com.yihu.wlyy.service.weixin.wxpay.model;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.organization.HospitalMapping;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
import com.yihu.wlyy.service.third.httplog.LogService;
import com.yihu.wlyy.service.weixin.wxpay.common.Configure;
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.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
 * 社保卡绑定信息
 * add by hzp at 20170524
 */
public class BindCard {
    private String cardNo;
    private String idType;
    private String idNo;
    private String userName;
    private String userId;
    public String getCardNo() {
        return cardNo;
    }
    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }
    public String getIdType() {
        return idType;
    }
    public void setIdType(String idType) {
        this.idType = idType;
    }
    public String getIdNo() {
        return idNo;
    }
    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
}

+ 161 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/service/weixin/wxpay/model/Charge.java

@ -0,0 +1,161 @@
package com.yihu.wlyy.service.weixin.wxpay.model;
/**
 * 医保扣费
 * add by hzp at 20170524
 */
public class Charge {
    private String tradeStatus; //交易状态    0 成功 1 失败  2 已退款
    private String settleNo;  //医保业务流水号
    private String settleTime;  //  医保交易成功时间
    private String outSettleNo;  //  接入应用业务流水号
    private String outSettleTime;  //  接入应用内业务时间
    private String medOrgNo;  //  医疗机构编号
    private String medOrgName;  //  医疗机构名称
    private String billNo;  //  待结算费用单据号
    private String cardNo;  //  医保卡号
    private String totalAmount;  //  交易总金额
    private String insuranceAmount;  //  医保支付金额
    private String selfPayAmount;  //  自付金额
    private String userId;  // 用户openId
    private String userName;  // 用户姓名
    private String idType;  // 证件号码
    private String idNo;  // 证件类型
    private String responseContent;  //扣费详情
    public String getTradeStatus() {
        return tradeStatus;
    }
    public void setTradeStatus(String tradeStatus) {
        this.tradeStatus = tradeStatus;
    }
    public String getSettleNo() {
        return settleNo;
    }
    public void setSettleNo(String settleNo) {
        this.settleNo = settleNo;
    }
    public String getSettleTime() {
        return settleTime;
    }
    public void setSettleTime(String settleTime) {
        this.settleTime = settleTime;
    }
    public String getOutSettleNo() {
        return outSettleNo;
    }
    public void setOutSettleNo(String outSettleNo) {
        this.outSettleNo = outSettleNo;
    }
    public String getOutSettleTime() {
        return outSettleTime;
    }
    public void setOutSettleTime(String outSettleTime) {
        this.outSettleTime = outSettleTime;
    }
    public String getMedOrgNo() {
        return medOrgNo;
    }
    public void setMedOrgNo(String medOrgNo) {
        this.medOrgNo = medOrgNo;
    }
    public String getMedOrgName() {
        return medOrgName;
    }
    public void setMedOrgName(String medOrgName) {
        this.medOrgName = medOrgName;
    }
    public String getBillNo() {
        return billNo;
    }
    public void setBillNo(String billNo) {
        this.billNo = billNo;
    }
    public String getCardNo() {
        return cardNo;
    }
    public void setCardNo(String cardNo) {
        this.cardNo = cardNo;
    }
    public String getTotalAmount() {
        return totalAmount;
    }
    public void setTotalAmount(String totalAmount) {
        this.totalAmount = totalAmount;
    }
    public String getInsuranceAmount() {
        return insuranceAmount;
    }
    public void setInsuranceAmount(String insuranceAmount) {
        this.insuranceAmount = insuranceAmount;
    }
    public String getSelfPayAmount() {
        return selfPayAmount;
    }
    public void setSelfPayAmount(String selfPayAmount) {
        this.selfPayAmount = selfPayAmount;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userId) {
        this.userId = userId;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getIdType() {
        return idType;
    }
    public void setIdType(String idType) {
        this.idType = idType;
    }
    public String getIdNo() {
        return idNo;
    }
    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }
    public String getResponseContent() {
        return responseContent;
    }
    public void setResponseContent(String responseContent) {
        this.responseContent = responseContent;
    }
}

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

@ -0,0 +1,256 @@
package com.yihu.wlyy.service.weixin.wxpay.service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yihu.wlyy.entity.organization.HospitalMapping;
import com.yihu.wlyy.repository.organization.HospitalMappingDao;
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.ylzinfo.onepay.sdk.OnepayDefaultClient;
import com.ylzinfo.onepay.sdk.domain.RequestParams;
import com.ylzinfo.onepay.sdk.domain.ResponseParams;
import com.ylzinfo.onepay.sdk.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.io.PrintWriter;
import java.io.StringWriter;
/**
 * 易联众统一支付服务类
 * add by hzp at 20170523
 */
@Service
public class OnePayService {
    @Autowired
    private Configure config;
    @Autowired
    private LogService logService;
    private String signType= "MD5";
    private String encryptType= "AES";
    @Autowired
    private HospitalMappingDao hospitalMappingDao;
    /**
     * 查询绑卡信息
     */
    public BindCard bindCard(String openid) throws Exception
    {
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
        String error = "";
        BindCard result = null;
        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);
            requestParams.setParam(params);
            requestParams.setTransType(config.getBindCardType());
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            msgBody =  JSON.toJSONString(requestParams);
            response =  JSON.toJSONString(res);
            // 如医保卡绑卡信息返回参数
            if (OnepayDefaultClient.isSuccessful(res)) {
                result = JSON.toJavaObject(res.getParam(), BindCard.class);
                //业务处理***********
                System.out.println("请求成功,返回参数:" + result.getCardNo() + "," +  result.getIdType() + "," + result.getIdNo() + "," + result.getUserName() + "," + result.getUserId());
            }
            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)
        {
            throw new Exception(error);
        }
        return result;
    }
    /**
     * 家庭医生签约支付
     */
    public String charge(String orgCode,String code,String date,String cardNo,String openid) throws Exception
    {
        //获取机构映射
        HospitalMapping hos = hospitalMappingDao.findByCode(orgCode);
        if(hos==null)
        {
            throw new Exception("no hospital mapping!");
        }
        return charge(hos.getAppId(), hos.getAppSecret(), code, date, cardNo, openid);
    }
    /**
     * 家庭医生签约支付
     */
    public String charge(String appId,String appSecret,String code,String date,String cardNo,String openid) throws Exception
    {
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
        String error = "";
        String result = "";
        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());
            requestParams.setTransType(config.getChargeType());
            //业务参数
            JSONObject params = new JSONObject();
            params.put("outSettleNo",code);  //接入应用结算业务流水号
            params.put("outSettleTime",date);    //接入应用内结算时间
            params.put("userId",openid);   //用户 ID
            params.put("cardNo",cardNo);   //医保卡号"D64775061"
            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 请求结构体
            requestParams.setParam(params);
            //执行支付
            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"));
                //业务处理***********
            } 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.getChargeType(),"家庭医生签约支付","POST",null,msgBody,response,error,logService.onepayType);
        if(!isSuccess)
        {
            throw new Exception(error);
        }
        return result;
    }
    /**
     * 家庭医生签约支付查询
     */
    public Charge chargeQuery(String code) throws Exception
    {
        Boolean isSuccess = true;
        String msgBody = "";
        String response = "";
        String error = "";
        Charge result = null;
        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());
            requestParams.setTransType(config.getChargeQueryType());
            //业务参数
            JSONObject params = new JSONObject();
            params.put("outSettleNo",code);  //接入应用结算业务流水号
            params.put("settleNo","");
            requestParams.setParam(params);
            //执行支付
            ResponseParams<JSONObject> res = onepayClient.execute(requestParams);
            msgBody =  JSON.toJSONString(requestParams);
            response =  JSON.toJSONString(res);
            if (OnepayDefaultClient.isSuccessful(res)) {
                result = JSON.toJavaObject(res.getParam(),Charge.class);
                //业务处理*******************
                System.out.println("请求成功,返回参数:" + result.getTradeStatus() +"  " + result.getUserName());
            } 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.getChargeType(),"家庭医生签约支付","POST",null,msgBody,response,error,logService.onepayType);
        if(!isSuccess)
        {
            throw new Exception(error);
        }
        return result;
    }
}

+ 81 - 0
patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/OnePayController.java

@ -0,0 +1,81 @@
package com.yihu.wlyy.web.wx;
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.web.WeixinBaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
/**
 * Created by hzp on 2017/05/23.
 */
@Controller
@RequestMapping(value = "/onepay", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
@Api(description = "统一支付服务")
public class OnePayController extends WeixinBaseController {
    @Autowired
    private OnePayService pay;
    @RequestMapping(value = "bindCard", method = RequestMethod.POST)
    @ApiOperation("查询绑卡信息")
    @ResponseBody
    public String bindCard() throws Exception {
        try {
            BindCard bindCard = pay.bindCard(getOpenid());         //oULM4xOARzTFqr9y1aTWuzCQdUL0
            return write(200, "查询绑卡信息成功!","data",bindCard);
        }
        catch (Exception e)
        {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "charge", method = RequestMethod.POST)
    @ApiOperation("家庭医生签约支付")
    @ResponseBody
    public String charge(
                         @ApiParam(name="orgCode",value="医疗机构编号",defaultValue = "3502050300")
                         @RequestParam String orgCode,
                         @ApiParam(name="code",value="签约代码",defaultValue = "044701ea5b2311e68344fa163e8aee56")
                         @RequestParam String code,
                         @ApiParam(name="date",value="签约付款时间yyyyMMddHHmmss",defaultValue = "20170523172400")
                         @RequestParam String date,
                         @ApiParam(name="cardNo",value="社保卡号",defaultValue = "DC0261911")
                         @RequestParam String cardNo) throws Exception {
        try {
            String settleNo = pay.charge(orgCode,code,date,cardNo,getOpenid());  //"oULM4xOARzTFqr9y1aTWuzCQdUL0"
            return write(200, "家庭医生签约支付成功!","data",settleNo);
        }
        catch (Exception e)
        {
            return error(-1, e.getMessage());
        }
    }
    @RequestMapping(value = "chargeQuery", method = RequestMethod.POST)
    @ApiOperation("家庭医生签约支付查询")
    @ResponseBody
    public String chargeQuery(@ApiParam(name="code",value="签约代码",defaultValue = "20170523172835")
                               @RequestParam String code) throws Exception {
        try {
            Charge charge = pay.chargeQuery(code);
            return write(200, "家庭医生签约支付查询成功!","data",charge);
        }
        catch (Exception e)
        {
            return error(-1, e.getMessage());
        }
    }
}

BIN
patient-co-wlyy/src/main/resources/onepay-java-sdk.jar