| 
					
				 | 
			
			
				@ -5,6 +5,7 @@ import com.yihu.jw.entity.base.wx.WxAccessTokenDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.wx.WxWechatDO; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.exception.ApiException; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.exception.code.ExceptionCode; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.hospital.prescription.service.entrance.TnyyEntranceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.rm.base.WechatRequestMapping; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.dao.JsapiTicketDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.wechat.dao.WechatDao; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -38,6 +39,8 @@ public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAcce 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private JsapiTicketDao jsapiTicketDao; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private TnyyEntranceService tnyyEntranceService; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public WxWechatDO getWxInfo(String wxId){ 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -183,6 +186,9 @@ public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAcce 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (wechatId.equalsIgnoreCase("sd_tnzyy_wx")){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return  getAccessTokenById(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String token_url = "https://api.weixin.qq.com/cgi-bin/token"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String appId=""; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            String appSecret=""; 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@ -222,6 +228,51 @@ public class WxAccessTokenService extends BaseJpaService<WxAccessTokenDO, WxAcce 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 泰安获取token 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param wechatId 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public WxAccessTokenDO getAccessTokenById(String wechatId) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        try { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            //根据wechatCode查找出appid和appSecret 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            WxWechatDO wxWechat = wechatDao.findById(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            List<WxAccessTokenDO> wxAccessTokens =  wxAccessTokenDao.getWxAccessTokenById(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(wxWechat==null){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                throw new ApiException(WechatRequestMapping.WxConfig.message_fail_wxWechat_is_no_exist, ExceptionCode.common_error_params_code); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if(wxAccessTokens!=null&&wxAccessTokens.size()>0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                for (WxAccessTokenDO accessToken : wxAccessTokens) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    if ((System.currentTimeMillis() - accessToken.getAddTimestamp()) < (accessToken.getExpiresIn() * 500)) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        return accessToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        wxAccessTokenDao.delete(accessToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                        break; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            com.alibaba.fastjson.JSONObject json = tnyyEntranceService.getAccessToken(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            if (json.containsKey("AccessToken")) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                String token = json.get("AccessToken").toString(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                WxAccessTokenDO newaccessToken = new WxAccessTokenDO(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setAccessToken(token); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setExpiresIn(7200); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setAddTimestamp(System.currentTimeMillis()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setCzrq(new Date()); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setCode(UUID.randomUUID().toString().replace("-","")); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                newaccessToken.setWechatId(wechatId); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                wxAccessTokenDao.save(newaccessToken); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return newaccessToken; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } else { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				                return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } catch (Exception e) { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            e.printStackTrace(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return null; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * 获取凭证 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param accId 微信原始id 
			 |