| 
					
				 | 
			
			
				@ -0,0 +1,185 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.hospital.service.MultipleCode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.patient.BasePatientDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.wx.BasePatientWechatDo; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.hospital.httplog.WlyyHttpLogDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.ylzinfo.OauthYlzConfigDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.httplog.dao.WlyyHttpLogDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.prescription.dao.OauthYlzConfigDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.patient.dao.BasePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.MixEnvelop; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.dao.BasePatientWechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.ylzinfo.ehc.EhcHandler; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.ylzinfo.ehc.common.utils.DateUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.ylzinfo.ehc.trans.TransRequest; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.ylzinfo.ehc.trans.TransResponse; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.List; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.UUID; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @author HZY 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @vsrsion 1.0 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * Created at 2020/4/17 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class MultipleCodeService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private OauthYlzConfigDao oauthYlzConfigDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientDao basePatientDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BasePatientWechatDao basePatientWechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop mcfRegister(BasePatientDO patientDO, String wechatId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BasePatientWechatDo patientWechatDo = basePatientWechatDao.findByWechatIdAndPatientId(wechatId, patientDO.getId()).get(0); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("mcf_config"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TransResponse re= new TransResponse(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        WlyyHttpLogDO wlyyHttpLogDO = new WlyyHttpLogDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            TransRequest request = new TransRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setMethod("ehc.ehealthcard.register"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setApp_id(oauthYlzConfigDO.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setTerm_id(oauthYlzConfigDO.getTermId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setVersion("X.M.0.1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setTimestamp(DateUtils.getOutTradeTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setSign_type("RSA"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setEnc_type("Plain"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject bizContent = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("out_register_time", DateUtils.getOutTradeTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("out_register_no", DateUtils.getOutTradeTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("open_id", patientWechatDo.getOpenid()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("account_id", "gh_a09552a72c9b"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("certificate_mode", "01"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("id_type", "01"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("id_no", patientDO.getIdcard()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("user_name", patientDO.getName()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("birthday", patientDO.getBirthday()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("address", patientDO.getAddress()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("mobile_phone", patientDO.getMobile()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("apply_method", "1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("user_sex", "1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("nation", "01"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setBiz_content(JSONObject.toJSONString(bizContent)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            EhcHandler ehcHandler = new EhcHandler(oauthYlzConfigDO.getUrl()+"ehcweb/gateway.do", oauthYlzConfigDO.getAppId(), oauthYlzConfigDO.getTermId(), oauthYlzConfigDO.getPrivateKey(), oauthYlzConfigDO.getEhcPublicKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            re = ehcHandler.execute(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            jsonObject.put("code_url",JSONObject.parseObject(re.getBiz_content()).getString("code_url")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String result = jsonObject.toJSONString().replaceAll("\\|888", ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(result!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                patientDO.setRegister("1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                basePatientDao.save(patientDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return MixEnvelop.getSuccess("注册成功",result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return MixEnvelop.getError(JSONObject.parseObject(re.getRet_msg()).toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return MixEnvelop.getError(JSONObject.parseObject(re.getRet_msg()).toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//     根据openId、 accountId查询三码融合码信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop mcfOpenquery(String openId,String accountId) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findOne("mcf_config"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            TransRequest request = new TransRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setMethod("ehc.ehealthcard.openquery"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setApp_id(oauthYlzConfigDO.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setTerm_id(oauthYlzConfigDO.getTermId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setVersion("X.M.0.1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setTimestamp(DateUtils.getOutTradeTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setSign_type("MD5"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setEnc_type("Plain"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject bizContent = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("open_id", openId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            bizContent.put("account_id", accountId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            request.setBiz_content(JSONObject.toJSONString(bizContent)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            EhcHandler ehcHandler = new EhcHandler(oauthYlzConfigDO.getUrl()+"ehcService/gateway.do", oauthYlzConfigDO.getAppId(), oauthYlzConfigDO.getTermId(), oauthYlzConfigDO.getAppKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            TransResponse re = ehcHandler.execute(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if ("0000".equals(JSONObject.parseObject(re.getRet_code()))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String ehealth_card_id = JSONObject.parseObject(re.getBiz_content()).getString("ehealth_card_id").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (ehealth_card_id!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return MixEnvelop.getSuccess("查询用户信息成功",ehealth_card_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getError(JSONObject.parseObject(re.getRet_msg()).toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				//     获取展码地址 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop mcfGetCodeUrl(String ehealth_card_id) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("mcf_config"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TransRequest request = new TransRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setMethod("ehc.ehealthcard.getCodeUrl"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setApp_id(oauthYlzConfigDO.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setTerm_id(oauthYlzConfigDO.getTermId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setVersion("X.M.0.1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setTimestamp(DateUtils.getOutTradeTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setSign_type("RSA"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setEnc_type("Plain"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject bizContent = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String no = UUID.randomUUID().toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        bizContent.put("ehealth_card_id",ehealth_card_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        bizContent.put("out_trade_no",no); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        bizContent.put("out_trade_time",DateUtils.getOutTradeTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setBiz_content(JSONObject.toJSONString(bizContent)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        EhcHandler ehcHandler = new EhcHandler(oauthYlzConfigDO.getUrl()+"ehcweb/gateway.do", oauthYlzConfigDO.getAppId(), oauthYlzConfigDO.getTermId(), oauthYlzConfigDO.getPrivateKey(), oauthYlzConfigDO.getEhcPublicKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TransResponse re = ehcHandler.execute(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("0000".equalsIgnoreCase(re.getRet_code())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject jsonObject = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            jsonObject.put("code_url",JSONObject.parseObject(re.getBiz_content()).getString("code_url")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String code_url = jsonObject.toJSONString().replaceAll("\\|888", ""); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (code_url!=null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return MixEnvelop.getSuccess("获取展码成功",code_url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getError("获取展码失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    //通过身边证查询用户信息 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public  TransResponse  mcfQueryInfo(String idType,String ID) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("mcf_config"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TransRequest request = new TransRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setMethod("ehc.ehealthcard.queryInfo"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setApp_id(oauthYlzConfigDO.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setTerm_id(oauthYlzConfigDO.getTermId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setVersion("X.M.0.1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setTimestamp(DateUtils.getOutTradeTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setSign_type("MD5"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setEnc_type("Plain"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject bizContent = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String no = UUID.randomUUID().toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        bizContent.put("id_type", idType); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        bizContent.put("id_no", ID); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setBiz_content(JSONObject.toJSONString(bizContent)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        EhcHandler ehcHandler = new EhcHandler(oauthYlzConfigDO.getUrl()+"ehcService/gateway.do", oauthYlzConfigDO.getAppId(), oauthYlzConfigDO.getTermId(), oauthYlzConfigDO.getAppKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TransResponse re = ehcHandler.execute(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return re; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public MixEnvelop mcfQueryInfo(String ehealth_card_id ) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        OauthYlzConfigDO oauthYlzConfigDO = oauthYlzConfigDao.findById("mcf_config"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TransRequest request = new TransRequest(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setMethod("ehc.ehealthcard.queryInfo"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setApp_id(oauthYlzConfigDO.getAppId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setTerm_id(oauthYlzConfigDO.getTermId()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setVersion("X.M.0.1"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setTimestamp(DateUtils.getOutTradeTime()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setSign_type("MD5"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setEnc_type("Plain"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject bizContent = new JSONObject(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String no = UUID.randomUUID().toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        bizContent.put("ehealth_card_id",ehealth_card_id); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        request.setBiz_content(JSONObject.toJSONString(bizContent)); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        EhcHandler ehcHandler = new EhcHandler(oauthYlzConfigDO.getUrl()+"ehcService/gateway.do", oauthYlzConfigDO.getAppId(), oauthYlzConfigDO.getTermId(), oauthYlzConfigDO.getAppKey()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        TransResponse re = ehcHandler.execute(request); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if ("0000".equals(JSONObject.parseObject(re.getRet_code()))){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return MixEnvelop.getSuccess("获取用户信息成功",re); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        return MixEnvelop.getError("获取用户信息失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |