|  | @ -85,6 +85,42 @@ public class EnterpriseService {
 | 
												
													
														
															|  |         return token.getAccessToken();
 |  |         return token.getAccessToken();
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     public String getXCXToken(String enterpriseId)throws Exception{
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         logger.info("getXCXToken");
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         WxEnterpriseDO wxEnterpriseDO = wxEnterpriseDao.findOne(enterpriseId+"_xcx");
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         List<WxEnterpriseTokenDO> wxEnterpriseTokenDOs = wxEnterpriseTokenDao.findByCodeOrderByCreateTimeDesc(enterpriseId+"_xcx");
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         if(wxEnterpriseTokenDOs!=null&&wxEnterpriseTokenDOs.size()>0) {
 | 
												
													
														
															|  | 
 |  |             logger.info("token size:"+wxEnterpriseTokenDOs.size());
 | 
												
													
														
															|  | 
 |  |             WxEnterpriseTokenDO tokenDO = wxEnterpriseTokenDOs.get(0);
 | 
												
													
														
															|  | 
 |  |             if (tokenDO.getExpiresTime().after(new Date())) {
 | 
												
													
														
															|  | 
 |  |                 return tokenDO.getAccessToken();
 | 
												
													
														
															|  | 
 |  |             }else{
 | 
												
													
														
															|  | 
 |  |                 wxEnterpriseTokenDao.delete(wxEnterpriseTokenDOs);
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         String result = HttpUtil.sendGet("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+wxEnterpriseDO.getCorpid()+"&corpsecret="+wxEnterpriseDO.getCorpsecret());
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         logger.info("getToken result:"+result);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         JSONObject json = JSONObject.parseObject(result);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         //保存当前token
 | 
												
													
														
															|  | 
 |  |         WxEnterpriseTokenDO token = new WxEnterpriseTokenDO();
 | 
												
													
														
															|  | 
 |  |         Date date = new Date();
 | 
												
													
														
															|  | 
 |  |         token.setAccessToken(json.getString("access_token"));
 | 
												
													
														
															|  | 
 |  |         token.setCreateTime(date);
 | 
												
													
														
															|  | 
 |  |         token.setExpiresTime(DateUtil.setDateHours(date,2));
 | 
												
													
														
															|  | 
 |  |         token.setCode(enterpriseId+"_xcx");
 | 
												
													
														
															|  | 
 |  |         wxEnterpriseTokenDao.save(token);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         return token.getAccessToken();
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     public String sendTextMes(String enterpriseId,String userId,String content)throws Exception{
 |  |     public String sendTextMes(String enterpriseId,String userId,String content)throws Exception{
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+getToken(enterpriseId);
 |  |         String url = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+getToken(enterpriseId);
 | 
												
											
												
													
														
															|  | @ -307,7 +343,7 @@ public class EnterpriseService {
 | 
												
													
														
															|  |      */
 |  |      */
 | 
												
													
														
															|  |     public String sendXCXMes(String enterpriseId, String userId, String appid,String page, String title, String description, Boolean emphasis_first_item, String content_item)throws Exception{
 |  |     public String sendXCXMes(String enterpriseId, String userId, String appid,String page, String title, String description, Boolean emphasis_first_item, String content_item)throws Exception{
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         String mesurl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+getToken(enterpriseId);
 |  | 
 | 
												
													
														
															|  | 
 |  |         String mesurl = "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token="+getXCXToken(enterpriseId);
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |         JSONObject param = new JSONObject();
 |  |         JSONObject param = new JSONObject();
 | 
												
													
														
															|  |         param.put("touser",userId);
 |  |         param.put("touser",userId);
 |