| 
					
				 | 
			
			
				@ -0,0 +1,168 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.hospital.service.consult; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSON; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.fasterxml.jackson.databind.ObjectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.doctor.BaseDoctorDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.file_upload.FileUploadService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.prescription.service.entrance.EntranceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.prescription.service.entrance.XzzxEntranceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.iot.common.UploadVO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.util.wechat.wxhttp.HttpUtil; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.dao.WechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.service.WechatInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.service.WxAccessTokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.json.JSONObject; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.slf4j.LoggerFactory; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Value; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.mock.web.MockMultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.web.multipart.MultipartFile; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.io.InputStream; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.HttpURLConnection; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.URL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.net.URLEncoder; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import java.util.Map; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class QrcodeService { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(QrcodeService.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WechatInfoService wechatInfoService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${wechat.id}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String wxId; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${fastDFS.fastdfs_file_url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String fastdfs_file_url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoctorDao baseDoctorDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private FileUploadService fileUploadService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${testPattern.sign}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String isClose; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Value("${testPattern.remote_inner_url}") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private String remote_inner_url; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private ObjectMapper objectMapper; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WechatDao wechatDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private WxAccessTokenService wxAccessTokenService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private EntranceService entranceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private XzzxEntranceService xzzxEntranceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 生成某个医生的二维码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param doctor 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws Exception 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String makeSpecialistQrcode(String doctor) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        System.out.println("doctorID"+doctor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String token=null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //中山医院互联网医院 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if("xm_zsyy_wx".equals(wxId)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String response = entranceService.getAccessToken("100033"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            net.sf.json.JSONObject object1 = net.sf.json.JSONObject.fromObject(response); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (null != object1&&null!=object1.get("respCode") && "00".equals(object1.get("respCode"))) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                token  = object1.getJSONObject("respEntity").getString("access_token"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("获取ACCESSTOKEN失败"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if("xm_xzzx_wx".equals(wxId)){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            token = xzzxEntranceService.getXzToken(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            token = wxAccessTokenService.getWxAccessTokenById(wxId).getAccessToken(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        System.out.println("token"+token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        System.out.println("wxId"+wxId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseDoctorDO baseDoctorDO = baseDoctorDao.findById(doctor); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if (null!=baseDoctorDO){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (null==baseDoctorDO.getQrcode()||"".equals(baseDoctorDO.getQrcode())){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                // 二维码内容 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String content = "hlw_doctor_" + baseDoctorDO.getId() +"_"+baseDoctorDO.getName(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println("content"+content); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                // 二维码图片文件名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String fileName = baseDoctorDO.getId()+"_"+baseDoctorDO.getMobile()+".png"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                /*String path = QrcodeService.class.getResource("/").getPath().replace("/WEB-INF/classes/", "") 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        + File.separator + "qrcode";*/ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println("fileName"+fileName); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                // 通过微信接口生成医生二维码 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String uri = makeQrcodeFromWeiXin(content, fileName.replaceAll("\r\n", ""), token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                System.out.println("uri"+uri); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                baseDoctorDO.setQrcode(uri); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                baseDoctorDao.save(baseDoctorDO); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return uri; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return baseDoctorDO.getQrcode(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception("找不到对应医生信息!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 从微信生成二维码并下载到本地 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param content  场景值 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param fileName 二维码文件名 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @throws 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public String makeQrcodeFromWeiXin(String content, String fileName, String token) throws Exception { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String token_url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + token; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String params = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\": {\"scene\": {\"scene_str\": \"" + content + "\"}}}"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LOGGER.info("参数:"+params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String result = HttpUtil.sendPost(token_url, params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            LOGGER.info("步骤1:"+result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (!StringUtils.isEmpty(result)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                JSONObject json = new JSONObject(result); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                LOGGER.info("步骤2:"+json.toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                if (json.has("ticket")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    // 请求输入流 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    InputStream inputStream = null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    // 下载二维码图片 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    URL urlGet = new URL("https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                            + URLEncoder.encode(json.get("ticket").toString(), "UTF-8")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    HttpURLConnection connection = (HttpURLConnection) urlGet.openConnection(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    connection.connect(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    inputStream = connection.getInputStream(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    UploadVO uploadVO = new UploadVO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    MultipartFile multipartFile = new MockMultipartFile(fileName,fileName,"", inputStream); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if (isClose.equalsIgnoreCase("1")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        System.out.println("isClose"+1); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        Map<String, Object> map = fileUploadService.uploadImg(multipartFile); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        uploadVO.setFullUri(map.get("accessory").toString()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    }else if(isClose.equals("2")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        System.out.println("isClose"+2); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        //内网上传 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        String rs = fileUploadService.request(remote_inner_url,multipartFile,null); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        System.out.println("rs"+rs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        com.alibaba.fastjson.JSONObject rsJson = JSON.parseObject(rs); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        uploadVO = objectMapper.readValue(rsJson.getJSONObject("obj").toJSONString(),UploadVO.class); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    }else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        // 上传服务器 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        uploadVO = fileUploadService.uploadStream(inputStream,fileName+".png",fastdfs_file_url); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    return uploadVO.getFullUri(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    throw new Exception("请求微信生成二维码失败!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new Exception("请求微信生成二维码失败!"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            throw new Exception(e.getMessage()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				} 
			 |