| 
					
				 | 
			
			
				@ -1,60 +1,811 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.wlyy.service.app.prescription; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.Hospital; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.entity.patient.prescription.Prescription; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.PrescriptionExpressage; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.PrescriptionInfo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.entity.patient.prescription.PrescriptionPay; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.charge.ChargeDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.doctor.DoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.organization.HospitalDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.organization.HospitalMappingDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.patient.PatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.patient.SignFamilyDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.repository.prescription.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.wlyy.service.BaseService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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.wx.OnePayController; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				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 com.ylzinfo.onepay.sdk.utils.StringUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.Logger; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.jdbc.core.JdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.security.access.method.P; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.util.StreamUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.servlet.http.HttpServletResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import javax.transaction.Transactional; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.PrintWriter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.StringWriter; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.lang.reflect.Method; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.nio.charset.Charset; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.text.SimpleDateFormat; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.*; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created by Reece on 2017/7/28/028. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 患者支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class PatientPrescriptionPayService extends BaseService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //公共配置文件 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    Properties systemConf = SystemConf.getInstance().getSystemProperties(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final Logger LOGGER = LoggerFactory.getLogger(OnePayController.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    各环境对应配置 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${server.server_url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String serverUrl; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.accId}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String accId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    Java配置文件 后续删除 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String signType = "MD5"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String encryptType = "AES"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //    引入实例 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private Configure config; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ObjectMapper objectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private LogService logService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PatientDao patientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private DoctorDao doctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OnePayService onePayService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private SignFamilyDao signFamilyDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionPayDao payDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ChargeDao chargeDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private HospitalMappingDao mappingDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionLogService payLogService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionService prescriptionService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionInfoDao infoDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JdbcTemplate jdbcTemplate; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private HospitalDao hospitalDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionDao prescriptionDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private PrescriptionExpressageDao expressageDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 患者支付接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 长处方配送信息查询接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param payInfo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject charge()throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject dispatch(String prescriptionCode, String orgCode) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject result = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List manage = new ArrayList(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Hospital hospital = hospitalDao.findByCode(orgCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String hostpitalName = hospital.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String address = hospital.getAddress(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String streeCode = hospital.getRoadCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String townCode = hospital.getTown(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String townName = hospital.getTownName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String cityCode = hospital.getCity(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String cityName = hospital.getCityName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String provinceCode = hospital.getProvince(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String provinceName = hospital.getProvinceName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<PrescriptionInfo> prescriptionInfos = infoDao.findByPrescriptionCode(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (PrescriptionInfo presInfo : prescriptionInfos) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            是否冷藏 1是 0否 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            int refrigerate = presInfo.getIsRefrigerate(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (refrigerate == 1) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                只能自取返回签约社区信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                Map self = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("code", orgCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("name", hostpitalName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("provinceCode", provinceCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("provinceName", provinceName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("cityCode", cityCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("cityName", cityName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("townCode", townCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("townName", townName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("streeCode", streeCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("address", address); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                self.put("type", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result.put("self", self); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String h = orgCode.substring(0, 8); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String sql = "SELECT h.`code`,h.`name`,h.`province` provinceCode,h.`province_name` provinceName,h.`city` cityCode ,h.`city_name` cityName," + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " h.`town` townCode,h.`town_name` townName,h.`road_code` streeCode,h.`address` " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " FROM dm_hospital h  " + 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                " WHERE h.`code` LIKE '%" + h + "%' AND RIGHT(h.code,2)<>'00' "; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        List<Map<String, Object>> hs = jdbcTemplate.queryForList(sql); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        for (Map<String, Object> hspital : hs) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map temp = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String code = (String) hspital.get("code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String name = (String) hspital.get("name"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            provinceCode = (String) hspital.get("provinceCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            provinceName = (String) hspital.get("provinceName"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cityCode = (String) hspital.get("cityCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            cityName = (String) hspital.get("cityName"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            townCode = (String) hspital.get("townCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            townName = (String) hspital.get("townName"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            streeCode = (String) hspital.get("streeCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            address = (String) hspital.get("address"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("code", code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("name", name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("provinceCode", provinceCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("provinceName", provinceName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("cityCode", cityCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("cityName", cityName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("townCode", townCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("townName", townName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("streeCode", streeCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            temp.put("address", address); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            manage.add(temp); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //                社区下没有服务站只能自取或快递 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (hs == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map self = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("code", orgCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("name", hostpitalName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("provinceCode", provinceCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("provinceName", provinceName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("cityCode", cityCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("cityName", cityName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("townCode", townCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("townName", townName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("streeCode", streeCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("address", address); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            self.put("type", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map express = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            express.put("type", 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("self", self); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            result.put("express", express); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map self = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("code", orgCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("name", hostpitalName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("provinceCode", provinceCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("provinceName", provinceName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("cityCode", cityCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("cityName", cityName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("townCode", townCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("townName", townName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("streeCode", streeCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("address", address); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        self.put("type", 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map express = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        express.put("type", 2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Map manager = new HashMap(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        manager.put("codes", manage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        manager.put("type", 3); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("self", self); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("express", express); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        result.put("manager", manager); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 患者支付结果查询接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 长处方支付成功前端页面回调接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param outChargeNo 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject chargeQuery(String outChargeNo)throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void recipeReturnUrl(HttpServletRequest request, HttpServletResponse response, String accessToken) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Prescription prescription = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int flag = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Boolean isSuccess = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String error = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String responses = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        response.setContentType("text/html;charset=utf-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //		如:查询显示订单信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            isSuccess = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            flag = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String appId = request.getParameter("appId"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String billNo = request.getParameter("billNo");//待结算费用单据号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String cardNo = request.getParameter("cardNo");//医保卡号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String channel = request.getParameter("channel");//支付方式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String chargeNo = request.getParameter("chargeNo");//支付平台流水号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String chargeTime = request.getParameter("chargeTime");//支付平台交易成功时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String idNo = request.getParameter("idNo");//证件号码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String idType = request.getParameter("idType");//证件类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String insuranceAmount = request.getParameter("insuranceAmount");//医保支付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String outChargeNo = request.getParameter("outChargeNo");//接入应用业务流水号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String outChargeTime = request.getParameter("outChargeTime");//接入应用时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String selfPayAmount = request.getParameter("selfPayAmount");//自付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String sign = request.getParameter("sign"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String signType = request.getParameter("signType"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String timestamp = request.getParameter("timestamp"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String totalAmount = request.getParameter("totalAmount");//交易总金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String tradeStatus = request.getParameter("tradeStatus");//交易状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String userId = request.getParameter("userId");//用户openID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String userName = request.getParameter("userName");//用户名字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String result = chargeQuery(outChargeNo, accessToken);//业务出参 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            org.json.JSONObject param = new org.json.JSONObject(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String requestParam = param.getString("responseContent"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            org.json.JSONObject responseContents = new org.json.JSONObject(requestParam);//医保结构体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            PrescriptionPay prescriptionPay = payDao.findByCode(outChargeNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (responseContents != null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String miSettleNo = responseContents.getString("miSettleNo");//医保收费单据号 (医保签约号) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String miRegisterNo = responseContents.getString("miRegisterNo");//医保挂号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String miCollectDate = responseContents.getString("miCollectDate");//收费日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String miCollectTime = responseContents.getString("miCollectTime");//收费时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String miCollectorName = responseContents.getString("miCollectorName");//收费人姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String miTotalFee = responseContents.getString("miTotalFee");//本次报销总额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String selfPay = responseContents.getString("selfPay");//个人现金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String accountPay = responseContents.getString("accountPay");//个人账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String heathPay = responseContents.getString("heathPay");//健康账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String cadresPay = responseContents.getString("cadresPay");//公务员补助 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String fundPay = responseContents.getString("fundPay");//基金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String healthCarePay = responseContents.getString("healthCarePay");//保健基金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String commercePay = responseContents.getString("commercePay");//商业保险支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String familyPay = responseContents.getString("familyPay");//共济账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String civilPay = responseContents.getString("civilPay");//民政补助金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String civilZone = responseContents.getString("civilZone");//民政行政区号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String bdrugPay = responseContents.getString("bdrugPay");//乙类支付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String unlessAmount = responseContents.getString("unlessAmount");//非医保费用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String exceedAmount = responseContents.getString("exceedAmount");//超封顶线金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String accountBalance = responseContents.getString("accountBalance");//个人账户余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String healthBalance = responseContents.getString("healthBalance");//健康账户余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setBillNo(billNo);//待结算费用单据号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setInsuranceAmount(Integer.parseInt(insuranceAmount));//医保支付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setSelfPayAmount(Integer.parseInt(selfPayAmount));//自付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setMiSettleNo(miSettleNo);//医保收费单据号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setMiRegisterNo(miRegisterNo);//医保挂号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setMiCollectDate(format.parse(miCollectDate));//收费日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setMiCollectTime(format.parse(miCollectTime));//收费时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setMiCollectorName(miCollectorName);//收费人姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setMiTotalFee(Integer.parseInt(miTotalFee));//本次报销总额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setSelfPay(Integer.parseInt(selfPay));//个人现金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setAccountPay(Integer.parseInt(accountPay));//个人账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setHeathPay(Integer.parseInt(heathPay));//健康账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setCadresPay(Integer.parseInt(cadresPay));//公务员补助 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setFundPay(Integer.parseInt(fundPay));//基金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setHealthCarePay(Integer.parseInt(healthCarePay));//保健基金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setCommercePay(Integer.parseInt(commercePay));//商业保险支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setFamilyPay(Integer.parseInt(familyPay));//共济账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setCivilPay(Integer.parseInt(civilPay));//民政补助金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setCivilZone(civilZone);//民政行政区号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setBdrugPay(Integer.parseInt(bdrugPay));//乙类支付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setUnlessAmount(Integer.parseInt(unlessAmount));//非医保费用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setExceedAmount(Integer.parseInt(exceedAmount));//超封顶线金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setAccountBalance(Integer.parseInt(accountBalance));//个人账户余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setHealthBalance(Integer.parseInt(healthBalance));//健康账户余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //        保存数据库更改记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                payDao.save(prescriptionPay); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String prescriptionCode = prescriptionPay.getPrescriptionCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescription = prescriptionDao.findByCode(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            PrescriptionExpressage expressage = expressageDao.findByPrescriptionPay(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("0".equals(tradeStatus)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setTradeStatus("1");//交易状态 成功1 失败0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescription.setStatus(30);//续费状态 30支付成功 21支付失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setDel(1);//快递信息状态 1可用 0删除 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressageDao.save(expressage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionDao.save(prescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else if ("1".equals(tradeStatus)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setTradeStatus("0");//交易状态 成功1 失败0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescription.setStatus(21);////续费状态 30支付成功 21支付失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setDel(0);//快递信息状态 1可用 0删除 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressageDao.save(expressage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionDao.save(prescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            isSuccess = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            response.getWriter().write(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //                记录log日志到数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logService.saveHttpLog(isSuccess, config.getReturnUrl(), "长处方支付页面跳转", "POST", null, "", responses, error, logService.onepayType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //记录支付log日志到数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payLogService.addLog(prescription, 2, flag, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 支付成功前端页面回调接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 长处方对接方异步回调接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param json 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject returnUrl()throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public void receiveRecipeNotify(HttpServletRequest request, HttpServletResponse response) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Prescription prescription = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Boolean isSuccess = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int flag = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String error = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String responses = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        response.setContentType("text/html;charset=utf-8"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        InputStream inputStream = request.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String params = StreamUtils.copyToString(inputStream, Charset.forName("UTF-8")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        org.json.JSONObject json = new org.json.JSONObject(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String appId = json.getString("appId"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        HospitalMapping hospital = mappingDao.findByAppId(appId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String appSecret = hospital.getAppSecret(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        LOGGER.info("回调参数:{}", params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (StringUtil.isEmpty(params)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            response.getWriter().write("empty"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        // 参数转换 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        ResponseParams<?> encryptRes = JSON.parseObject(params, ResponseParams.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OnepayDefaultClient client = new OnepayDefaultClient("", appId, appSecret, encryptRes.getSignType(), encryptRes.getEncryptType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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 { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//					业务逻辑代码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    flag = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    isSuccess = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    responses = JSON.toJSONString(decryptRes); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    org.json.JSONObject requestParams = new org.json.JSONObject(responses); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    org.json.JSONObject requestParam = requestParams.getJSONObject("param");//业务出参 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String outChargeNo = requestParam.getString("outChargeNo");//接入应用业务流水号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String chargeNo = requestParam.getString("chargeNo"); //支付平台流水号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String chargeTime = requestParam.getString("chargeTime");//支付平台交易成功时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    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");//交易状态 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    org.json.JSONObject responseContents = requestParams.getJSONObject("responseContent");//医保结构体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String miSettleNo = responseContents.getString("miSettleNo");//医保收费单据号 (医保签约号) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String miRegisterNo = responseContents.getString("miRegisterNo");//医保挂号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String miCollectDate = responseContents.getString("miCollectDate");//收费日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String miCollectTime = responseContents.getString("miCollectTime");//收费时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String miCollectorName = responseContents.getString("miCollectorName");//收费人姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String miTotalFee = responseContents.getString("miTotalFee");//本次报销总额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String selfPay = responseContents.getString("selfPay");//个人现金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String accountPay = responseContents.getString("accountPay");//个人账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String heathPay = responseContents.getString("heathPay");//健康账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String cadresPay = responseContents.getString("cadresPay");//公务员补助 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String fundPay = responseContents.getString("fundPay");//基金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String healthCarePay = responseContents.getString("healthCarePay");//保健基金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String commercePay = responseContents.getString("commercePay");//商业保险支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String familyPay = responseContents.getString("familyPay");//共济账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String civilPay = responseContents.getString("civilPay");//民政补助金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String civilZone = responseContents.getString("civilZone");//民政行政区号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String bdrugPay = responseContents.getString("bdrugPay");//乙类支付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String unlessAmount = responseContents.getString("unlessAmount");//非医保费用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String exceedAmount = responseContents.getString("exceedAmount");//超封顶线金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String accountBalance = responseContents.getString("accountBalance");//个人账户余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String healthBalance = responseContents.getString("healthBalance");//健康账户余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //更新数据 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    PrescriptionPay prescriptionPay = payDao.findByCode(outChargeNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setBillNo(billNo);//待结算费用单据号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setInsuranceAmount(Integer.parseInt(insuranceAmount));//医保支付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setSelfPayAmount(Integer.parseInt(selfPayAmount));//自付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setMiSettleNo(miSettleNo);//医保收费单据号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setMiRegisterNo(miRegisterNo);//医保挂号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setMiCollectDate(format.parse(miCollectDate));//收费日期 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setMiCollectTime(format.parse(miCollectTime));//收费时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setMiCollectorName(miCollectorName);//收费人姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setMiTotalFee(Integer.parseInt(miTotalFee));//本次报销总额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setSelfPay(Integer.parseInt(selfPay));//个人现金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setAccountPay(Integer.parseInt(accountPay));//个人账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setHeathPay(Integer.parseInt(heathPay));//健康账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setCadresPay(Integer.parseInt(cadresPay));//公务员补助 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setFundPay(Integer.parseInt(fundPay));//基金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setHealthCarePay(Integer.parseInt(healthCarePay));//保健基金支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setCommercePay(Integer.parseInt(commercePay));//商业保险支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setFamilyPay(Integer.parseInt(familyPay));//共济账户支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setCivilPay(Integer.parseInt(civilPay));//民政补助金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setCivilZone(civilZone);//民政行政区号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setBdrugPay(Integer.parseInt(bdrugPay));//乙类支付金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setUnlessAmount(Integer.parseInt(unlessAmount));//非医保费用 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setExceedAmount(Integer.parseInt(exceedAmount));//超封顶线金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setAccountBalance(Integer.parseInt(accountBalance));//个人账户余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescriptionPay.setHealthBalance(Integer.parseInt(healthBalance));//健康账户余额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    String prescriptionCode = prescriptionPay.getPrescriptionCode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    prescription = prescriptionDao.findByCode(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    PrescriptionExpressage expressage = expressageDao.findByPrescriptionPay(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ("0".equals(tradeStatus)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        prescriptionPay.setTradeStatus("1");//交易状态 成功1 失败0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        prescription.setStatus(30);//续费状态 30支付成功 21支付失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        expressage.setDel(1);//快递信息状态 1可用 0删除 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        expressageDao.save(expressage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        prescriptionDao.save(prescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else if ("1".equals(tradeStatus)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        prescriptionPay.setTradeStatus("0");//交易状态 成功1 失败0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        prescription.setStatus(21);////续费状态 30支付成功 21支付失败 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        expressage.setDel(0);//快递信息状态 1可用 0删除 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        expressageDao.save(expressage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        prescriptionDao.save(prescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    //        保存数据库更改记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    payDao.save(prescriptionPay); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    response.getWriter().write("SUCCESS"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            response.getWriter().write(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //                记录log日志到数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logService.saveHttpLog(isSuccess, config.getReceiveNotify(), "异步支付通知", "POST", null, params, responses, error, logService.onepayType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //记录支付log日志到数据库 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payLogService.addLog(prescription, 2, flag, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //******************************************  反射获取私有属性基本工具方法  ******************************************************************************* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public BindCard getBindCard(Object obj, String openId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Class cls = obj.getClass(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //获得类的私有方法 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Method method = cls.getDeclaredMethod("privateMethod", null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        method.setAccessible(true); //没有设置就会报错 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //调用该方法 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BindCard bindCard = (BindCard) method.invoke(obj, openId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return bindCard; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//******************************************  长处方支付基本工具方法  ******************************************************************************* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 对接方异步回调接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 长处方支付,成功则返回支付路径 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Transactional 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String charge(int type, String addressJson, String orgCode, String prescriptionCode, int totalAmount, String people, String accessToken) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //获取机构映射 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        HospitalMapping hos = mappingDao.findByCode(orgCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (hos == null) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception("no hospital mapping!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String orgName = hos.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String appId = hos.getAppId(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String appSecret = hos.getAppSecret(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Patient patient = patientDao.findByCode(people); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String userName = patient.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String openid = patient.getOpenid(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String userAddress = patient.getAddress(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String uuid = UUID.randomUUID().toString().replaceAll("-", ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Date now = new Date(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Boolean isSuccess = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int flag = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String msgBody = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String response = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String error = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String result = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String channel = "WX_MMP";   //  医保支付渠道 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String subject = "续方订单支付";   //  订单名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), appId, appSecret, signType, encryptType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//     未真正完成支付以前预存储支付信息到wlyy_prescription_pay表 更改wlyy_prescription表支付时间  wlyy_prescription_expressage 新增物流记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PrescriptionExpressage expressage = new PrescriptionExpressage(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setCode(getCode()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setPrescriptionCode(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject addressInfo = JSON.parseObject(addressJson); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String phone = addressInfo.getString("phone"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setMobile(phone);//收货人手机号码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String proviceCode = addressInfo.getString("provinceCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setProvinceCode(proviceCode);//省代码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String proviceName = addressInfo.getString("provinceName"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setProvinceName(proviceName);//省名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String cityCode = addressInfo.getString("cityCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setCityCode(cityCode);//市代码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String cityName = addressInfo.getString("cityName"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setCityName(cityName);//市名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String townCode = addressInfo.getString("townCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setTownCode(townCode);//区code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String townName = addressInfo.getString("townName"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setTownName(townName);//区名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String streeCode = addressInfo.getString("streeCode"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setStreetCode(streeCode);//街道code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String streeName = addressInfo.getString("streeName"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setStreetName(streeName);//街道名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String address = addressInfo.getString("address"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressage.setHospitalAddress(address);//取药地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        switch (type) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case 1: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //自取保存居民信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setName(userName);//居民姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setAddress(userAddress);//居民详细地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setHospitalCode(orgCode);//机构code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setHospitalName(hos.getName());//取药点 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setCreateTime(now);//创建时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setOneselfPickupFlg(1);//是否自取 1是 0否 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setDel(1);//有效 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case 2: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //快递保存信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String name = addressInfo.getString("receiver"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setName(name);//居民姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setHospitalCode(orgCode);//机构code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setHospitalName("顺丰快递");//取药点 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                expressage.setHospitalAddress("5");//取药地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setCreateTime(now);//创建时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setOneselfPickupFlg(0);//是否自取 1是 0否 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setDel(1);//有效 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            case 3: 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //健管师配送 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setName(userName);//收件人姓名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String orgCodess = addressInfo.getString("code"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setHospitalCode(orgCodess);//机构code 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String orgNames = addressInfo.getString("name"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setHospitalName(orgNames);//取药点 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setCreateTime(now);//创建时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setOneselfPickupFlg(0);//是否自取 1是 0否 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                expressage.setDel(1);//有效 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Prescription prescription = prescriptionDao.findByCode(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescription.setPayTime(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        PrescriptionPay prescriptionPay = new PrescriptionPay(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//        居民信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setCode(uuid);  //  接入应用支付业务流水号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setPrescriptionCode(prescriptionCode);   //开处方的医生code 关联 wlyy_prescription 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setType(1);//支付方式 1 医保支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setOutChargeTime(new Date());//接入应用时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setChannel(channel);//支付方式 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setChargeTime(new Date());//预支付时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setOpenid(openid);     //  用戶微信openid 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setTotalAmount(totalAmount);//交易总金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setCreateTime(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionPay.setCzrq(now); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            BindCard card = getBindCard(onePayService, openid); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String name = card.getAttachName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String ssc = card.getAttachCardNo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String idType = card.getAttachIdType(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String idNo = card.getAttachIdNo(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescriptionPay.setCardNo(ssc);//医保卡号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescriptionPay.setUserName(name);//用户名字 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescriptionPay.setIdType(idType);//证件类型 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescriptionPay.setIdNo(idNo);//证件号码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            requestParams.setEncryptType(encryptType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            requestParams.setTransType(config.getChargeType()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //业务参数 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject params = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("outChargeNo", uuid);  //接入应用结算业务流水号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("outChargeTime", currentDateTime);    //接入应用内结算时间 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("userId", openid);   //用户 ID 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("cardNo", ssc);   //医保卡号"D64775061" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //获取绑卡信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("userName", name); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("idType", idType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("idNo", idNo); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("totalAmount", Integer.toString(totalAmount));   //处方总金额 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Properties systemConf = SystemConf.getInstance().getSystemProperties(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String returnUrl = systemConf.getProperty("return_url"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            returnUrl = returnUrl.replace("{server}", serverUrl); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("returnUrl", returnUrl);   //长处方页面跳转地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("channel", channel);  //微信医保支付 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("merchName", orgName);  //收款单位名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("subject", subject);  //订单名称 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("wxToken", accessToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject jsonParams = prescriptionService.getPayInfo(prescriptionCode); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject recipe = jsonParams.getJSONObject("recipeContent"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("recipeContent", recipe);// 处方主信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescriptionPay.setRecipeContent(recipe.toJSONString());//处方主信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject zdContent = jsonParams.getJSONObject("zdlist"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("zdlist", zdContent);// 诊断明细 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescriptionPay.setZdlist(zdContent.toJSONString());//诊断明细 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject mxContent = jsonParams.getJSONObject("mxlist"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("mxlist", mxContent);//处方明细 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            prescriptionPay.setMxlist(mxContent.toJSONString());//处方明细 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            Map<String, String> map = new HashMap<>();//请求结构体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("feeType", "06");//长处方结算 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            map.put("settleType", "01"); //诊间医保结算 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            params.put("requestContent", objectMapper.writeValueAsString(map));// 请求结构体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            requestParams.setParam(params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            msgBody = JSON.toJSONString(requestParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //执行支付  获取预支付原生返回值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ResponseParams<JSONObject> res = onepayClient.execute(requestParams); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            response = JSON.toJSONString(res); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (OnepayDefaultClient.isSuccessful(res)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject json = res.getParam(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String chargeNo = String.valueOf(json.get("chargeNo"));      //医保结算业务流水号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result = String.valueOf(json.get("payUrl")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                prescriptionPay.setChargeNo(chargeNo);//支付后返回的流水号 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                isSuccess = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                flag = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                error = "请求失败,返回结果:" + res.getRespCode() + "," + res.getRespMsg(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception ex) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            isSuccess = false; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            flag = 0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            StringWriter sw = new StringWriter(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            PrintWriter pw = new PrintWriter(sw); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            ex.printStackTrace(pw); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            error = sw.toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //保存交易记录 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payDao.save(prescriptionPay); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //保存续方更改消息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        prescriptionDao.save(prescription); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //保存物流信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        expressageDao.save(expressage); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //保存http日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logService.saveHttpLog(isSuccess, config.getRecipeChargeType(), "长处方结算", "POST", null, msgBody, response, error, logService.onepayType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //保存长处方日志  type=2易联众对接 flag =1成功 flag=0 0失败 userType 1 患者 2医生 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        payLogService.addLog(prescription, 2, flag, 1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!isSuccess) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception(error); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//******************************************  支付查询基本工具方法  ******************************************************************************* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 家庭医生签约支付查询 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public JSONObject receiveNotify() throws Exception{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return jsonObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String chargeQuery(String code, String accessToken) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        int flag =0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        Boolean isSuccess = true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String msgBody = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String response = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String error = ""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String result = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        WlyyCharge charge = chargeDao.findByCode(code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        HospitalMapping hospitalMapping = mappingDao.findByCode(charge.getHospital()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OnepayDefaultClient onepayClient = new OnepayDefaultClient(config.getOnepayApi(), hospitalMapping.getAppId(), hospitalMapping.getAppSecret(), signType, encryptType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            RequestParams requestParams = new RequestParams(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            requestParams.setVersion(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            requestParams.setSign(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            requestParams.setEncryptData(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//            requestParams.setAppId(appId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            requestParams.setAppId(hospitalMapping.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            requestParams.setTimestamp(DateUtil.getCurrentDateTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            requestParams.setSignType(signType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            requestParams.setEncryptType(encryptType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            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)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                //业务处理******************* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                只返回业务出参 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                result = JSON.toJavaObject(res.getParam(), Charge.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                flag = 1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                result = JSON.toJSONString(res.getParam()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//                 返回医保机构体 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LOGGER.info("请求成功,返回参数: " + result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 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(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //type = 3易联众接口保存http日志 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        logService.saveHttpLog(isSuccess, config.getRecipeChargeType(), "长处方支付查询", "POST", null, msgBody, response, error, logService.onepayType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (!isSuccess) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception(error); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return result; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//基卫接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//    第三方快递接口 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 |