|  |  | @ -9,6 +9,7 @@ import com.epmet.commons.tools.security.dto.TokenDto; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.commons.tools.utils.HttpClientManager; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.constant.ModuleConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.constant.ThirdApiConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.constant.ThirdRunTimeInfoConstant; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dao.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.form.*; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.dto.result.AuthorizationInfoResultDTO; | 
			
		
	
	
		
			
				
					|  |  | @ -18,11 +19,9 @@ import com.epmet.service.ComponentVerifyTicketService; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.util.WXBizMsgCrypt; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.util.WXXmlToMapUtil; | 
			
		
	
		
			
				
					|  |  |  | import com.epmet.util.XmlUtil; | 
			
		
	
		
			
				
					|  |  |  | import com.fasterxml.jackson.annotation.JsonIgnore; | 
			
		
	
		
			
				
					|  |  |  | import com.github.pagehelper.util.StringUtil; | 
			
		
	
		
			
				
					|  |  |  | import lombok.extern.slf4j.Slf4j; | 
			
		
	
		
			
				
					|  |  |  | import org.apache.commons.lang3.StringUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.beans.BeanUtils; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.stereotype.Service; | 
			
		
	
		
			
				
					|  |  |  | import org.springframework.transaction.annotation.Transactional; | 
			
		
	
	
		
			
				
					|  |  | @ -35,6 +34,7 @@ import java.lang.reflect.Field; | 
			
		
	
		
			
				
					|  |  |  | import java.util.*; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | import static com.epmet.constant.ThirdPlatformConstant.*; | 
			
		
	
		
			
				
					|  |  |  | import static com.epmet.constant.ThirdRunTimeInfoConstant.*; | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  | /** | 
			
		
	
		
			
				
					|  |  |  |  * @Author zxc | 
			
		
	
	
		
			
				
					|  |  | @ -71,24 +71,24 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public String componentVerifyTicket(HttpServletRequest request, HttpServletResponse response) { | 
			
		
	
		
			
				
					|  |  |  |         log.info(ModuleConstant.START_RECEIVE); | 
			
		
	
		
			
				
					|  |  |  |         log.info(ThirdRunTimeInfoConstant.START_RECEIVE); | 
			
		
	
		
			
				
					|  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |             request.setCharacterEncoding("UTF-8"); | 
			
		
	
		
			
				
					|  |  |  |             response.setCharacterEncoding("UTF-8"); | 
			
		
	
		
			
				
					|  |  |  |             request.setCharacterEncoding(ModuleConstant.UTF8); | 
			
		
	
		
			
				
					|  |  |  |             response.setCharacterEncoding(ModuleConstant.UTF8); | 
			
		
	
		
			
				
					|  |  |  |             // 微信加密签名
 | 
			
		
	
		
			
				
					|  |  |  |             String msgSignature = request.getParameter("msg_signature"); | 
			
		
	
		
			
				
					|  |  |  |             String msgSignature = request.getParameter(ModuleConstant.MSG_SIGNATURE); | 
			
		
	
		
			
				
					|  |  |  |             // 时间戳
 | 
			
		
	
		
			
				
					|  |  |  |             String timeStamp = request.getParameter("timestamp"); | 
			
		
	
		
			
				
					|  |  |  |             String timeStamp = request.getParameter(ModuleConstant.TIMESTAMP); | 
			
		
	
		
			
				
					|  |  |  |             // 随机数
 | 
			
		
	
		
			
				
					|  |  |  |             String nonce = request.getParameter("nonce"); | 
			
		
	
		
			
				
					|  |  |  |             String nonce = request.getParameter(ModuleConstant.NONCE); | 
			
		
	
		
			
				
					|  |  |  |             // 从请求中读取整个post数据
 | 
			
		
	
		
			
				
					|  |  |  |             InputStream inputStream; | 
			
		
	
		
			
				
					|  |  |  |             String postData = null; | 
			
		
	
		
			
				
					|  |  |  |             inputStream = request.getInputStream(); | 
			
		
	
		
			
				
					|  |  |  |             postData= IOUtils.toString(inputStream, "UTF-8"); | 
			
		
	
		
			
				
					|  |  |  |             postData= IOUtils.toString(inputStream,ModuleConstant.UTF8); | 
			
		
	
		
			
				
					|  |  |  |             //从XML中获取<Encrypt></Encrypt>标签内的密文文本
 | 
			
		
	
		
			
				
					|  |  |  |             String encrypt = XmlUtil.toXml(postData); | 
			
		
	
		
			
				
					|  |  |  |             log.info("Encrypt:"+encrypt); | 
			
		
	
		
			
				
					|  |  |  |             log.info(String.format(ThirdRunTimeInfoConstant.ENCRYPT,encrypt)); | 
			
		
	
		
			
				
					|  |  |  |             //格式化密文文本,否则没有<ToUserName>标签,会解密失败,参考官方的加解密代码JAVA版本
 | 
			
		
	
		
			
				
					|  |  |  |             String format = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%1$s]]></Encrypt></xml>"; | 
			
		
	
		
			
				
					|  |  |  |             String fromXML = String.format(format, encrypt); | 
			
		
	
	
		
			
				
					|  |  | @ -102,14 +102,14 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |                 // 解密消息
 | 
			
		
	
		
			
				
					|  |  |  |                 msg = wxcpt.decryptMsg(msgSignature, timeStamp, nonce, fromXML); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |             log.info("msg:"+msg); | 
			
		
	
		
			
				
					|  |  |  |             log.info(String.format(ThirdRunTimeInfoConstant.MSG,msg)); | 
			
		
	
		
			
				
					|  |  |  |             // 将xml转为map
 | 
			
		
	
		
			
				
					|  |  |  |             Map<String, String> result = WXXmlToMapUtil.xmlToMap(msg); | 
			
		
	
		
			
				
					|  |  |  |             String infotype = result.get("InfoType");  //获取infotype,注:微信开放平台文档中标明固定为:"component_verify_ticket",但参考其他代码,还包含authorized???
 | 
			
		
	
		
			
				
					|  |  |  |             String infotype = result.get(ModuleConstant.INFO_TYPE);  //获取infotype,注:微信开放平台文档中标明固定为:"component_verify_ticket",但参考其他代码,还包含authorized???
 | 
			
		
	
		
			
				
					|  |  |  |             log.info(infotype); | 
			
		
	
		
			
				
					|  |  |  |             switch (infotype){ | 
			
		
	
		
			
				
					|  |  |  |                 case "component_verify_ticket":   //验证票据
 | 
			
		
	
		
			
				
					|  |  |  |                     String ComponentVerifyTicket = result.get("ComponentVerifyTicket"); | 
			
		
	
		
			
				
					|  |  |  |                 case ModuleConstant.TICKET_UNDERLINE_KEY:   //验证票据
 | 
			
		
	
		
			
				
					|  |  |  |                     String ComponentVerifyTicket = result.get(ModuleConstant.TICKET_KEY); | 
			
		
	
		
			
				
					|  |  |  |                     // 缓存 ticket
 | 
			
		
	
		
			
				
					|  |  |  |                     redisThird.setComponentVerifyTicket(ComponentVerifyTicket); | 
			
		
	
		
			
				
					|  |  |  |                     // 存数据库
 | 
			
		
	
	
		
			
				
					|  |  | @ -117,17 +117,17 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |                     ticketFormDTO.setAppid(PLATFORM_APP_ID); | 
			
		
	
		
			
				
					|  |  |  |                     ticketFormDTO.setComponentVerifyTicket(ComponentVerifyTicket); | 
			
		
	
		
			
				
					|  |  |  |                     ticketDao.insertComponentVerifyTicket(ticketFormDTO); | 
			
		
	
		
			
				
					|  |  |  |                     log.info("component_verify_ticket:"+ComponentVerifyTicket); | 
			
		
	
		
			
				
					|  |  |  |                     log.info(ModuleConstant.TICKET_UNDERLINE_KEY+":"+ComponentVerifyTicket); | 
			
		
	
		
			
				
					|  |  |  |                     break; | 
			
		
	
		
			
				
					|  |  |  |                 case "unauthorized"://用户取消授权
 | 
			
		
	
		
			
				
					|  |  |  |                     return ""; | 
			
		
	
		
			
				
					|  |  |  |                 case ModuleConstant.UNAUTHORIZED://用户取消授权
 | 
			
		
	
		
			
				
					|  |  |  |                     return ModuleConstant.NULL_CHAR; | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |             log.error(e.getMessage()); | 
			
		
	
		
			
				
					|  |  |  |             return ""; | 
			
		
	
		
			
				
					|  |  |  |             return ModuleConstant.NULL_CHAR; | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         log.info(ModuleConstant.END_TICKET); | 
			
		
	
		
			
				
					|  |  |  |         return "success"; | 
			
		
	
		
			
				
					|  |  |  |         log.info(ThirdRunTimeInfoConstant.END_TICKET); | 
			
		
	
		
			
				
					|  |  |  |         return ModuleConstant.SUCCESS; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
	
		
			
				
					|  |  | @ -138,7 +138,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void getComponentAccessToken() { | 
			
		
	
		
			
				
					|  |  |  |         log.info("====================开始执行定时任务获取令牌【component_access_token】===================="); | 
			
		
	
		
			
				
					|  |  |  |         log.info(ThirdRunTimeInfoConstant.START_GET_COMPONENT_ACCESS_TOKEN); | 
			
		
	
		
			
				
					|  |  |  |         Map<String, String> reMap; | 
			
		
	
		
			
				
					|  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |             // 核心定时器
 | 
			
		
	
	
		
			
				
					|  |  | @ -157,17 +157,18 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |                 formDTO.setComponentAccessToken(componentAccessToken); | 
			
		
	
		
			
				
					|  |  |  |                 formDTO.setExpiresIn(Integer.valueOf(expiresIn)); | 
			
		
	
		
			
				
					|  |  |  |                 //先逻辑删,在插入
 | 
			
		
	
		
			
				
					|  |  |  |                 log.info(ThirdRunTimeInfoConstant.START_DELETE_COMPONENT_ACCESS_TOKEN); | 
			
		
	
		
			
				
					|  |  |  |                 componentAccessTokenDao.updateOldComponentAccessToken(); | 
			
		
	
		
			
				
					|  |  |  |                 componentAccessTokenDao.insertComponentAccessToken(formDTO); | 
			
		
	
		
			
				
					|  |  |  |                 //存缓存
 | 
			
		
	
		
			
				
					|  |  |  |                 redisThird.setComponentAccessToken(componentAccessToken); | 
			
		
	
		
			
				
					|  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException(ModuleConstant.FAILURE_ACCESS_TOKEN); | 
			
		
	
		
			
				
					|  |  |  |                 throw new RenException(ThirdRunTimeInfoConstant.FAILURE_ACCESS_TOKEN); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |             e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         log.info(ModuleConstant.SUCCESS_ACCESS_TOKEN); | 
			
		
	
		
			
				
					|  |  |  |         log.info(ThirdRunTimeInfoConstant.SUCCESS_ACCESS_TOKEN); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
	
		
			
				
					|  |  | @ -178,13 +179,13 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     @Override | 
			
		
	
		
			
				
					|  |  |  |     public void preAuthCode() { | 
			
		
	
		
			
				
					|  |  |  |         log.info("====================开始执行定时任务获取预授权码【pre_auth_code】===================="); | 
			
		
	
		
			
				
					|  |  |  |         log.info(START_GET_PRE_AUTH_CODE); | 
			
		
	
		
			
				
					|  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |             String accessToken = redisThird.getComponentAccessToken(ModuleConstant.COMPONENT_ACCESS_TOKEN); | 
			
		
	
		
			
				
					|  |  |  |             JSONObject jsonObject = new JSONObject(); | 
			
		
	
		
			
				
					|  |  |  |             jsonObject.put(ModuleConstant.COMPONENT_APPID, PLATFORM_APP_ID); | 
			
		
	
		
			
				
					|  |  |  |             String post = HttpClientManager.getInstance().sendPostByJSON(ThirdApiConstant.API_CREATE_PREAUTHCODE_URL + accessToken, JSON.toJSONString(jsonObject)).getData(); | 
			
		
	
		
			
				
					|  |  |  |             log.info("====================返回post结果:" + post); | 
			
		
	
		
			
				
					|  |  |  |             log.info(String.format(POST_RESULT,post)); | 
			
		
	
		
			
				
					|  |  |  |             HashMap<String, String> hashMap = JSON.parseObject(post, HashMap.class); | 
			
		
	
		
			
				
					|  |  |  |             String preAuthCode = hashMap.get(ModuleConstant.PRE_AUTH_CODE); | 
			
		
	
		
			
				
					|  |  |  |             String expiresIn = hashMap.get(ModuleConstant.EXPIRES_IN); | 
			
		
	
	
		
			
				
					|  |  | @ -200,12 +201,12 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |                 //预授权码 放入缓存
 | 
			
		
	
		
			
				
					|  |  |  |                 redisThird.setPreAuthCode(preAuthCode,ex); | 
			
		
	
		
			
				
					|  |  |  |             } else { | 
			
		
	
		
			
				
					|  |  |  |                 throw new RuntimeException("微信开放平台,第三方平台获取【预授权码】失败"); | 
			
		
	
		
			
				
					|  |  |  |                 throw new RuntimeException(FAILURE_GET_PRE_AUTH_CODE); | 
			
		
	
		
			
				
					|  |  |  |             } | 
			
		
	
		
			
				
					|  |  |  |         } catch (Exception e) { | 
			
		
	
		
			
				
					|  |  |  |             e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         log.info("====================结束执行定时任务获取预授权码【pre_auth_code】===================="); | 
			
		
	
		
			
				
					|  |  |  |         log.info(END_GET_PRE_AUTH_CODE); | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
		
			
				
					|  |  |  |     /** | 
			
		
	
	
		
			
				
					|  |  | @ -214,6 +215,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |      */ | 
			
		
	
		
			
				
					|  |  |  |     @Transactional(rollbackFor = Exception.class) | 
			
		
	
		
			
				
					|  |  |  |     public AuthorizationInfoResultDTO authInfoByAuthCode(String authCode,String authAppId,String customerId) { | 
			
		
	
		
			
				
					|  |  |  |         log.info(START_GET_AUTH_INFO); | 
			
		
	
		
			
				
					|  |  |  |         AuthorizationInfoResultDTO authorizationInfoResultDTO = new AuthorizationInfoResultDTO(); | 
			
		
	
		
			
				
					|  |  |  |         // 获取令牌【component_access_token】
 | 
			
		
	
		
			
				
					|  |  |  |         String accessToken = redisThird.getComponentAccessToken(ModuleConstant.COMPONENT_ACCESS_TOKEN); | 
			
		
	
	
		
			
				
					|  |  | @ -247,6 +249,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |         refreshAuthorizerAccessTokenDao.updateOldAuthorizerAccessToken(customerId); | 
			
		
	
		
			
				
					|  |  |  |         refreshAuthorizerAccessTokenDao.insertAuthorizerAccessToken(refreshAccessToken); | 
			
		
	
		
			
				
					|  |  |  |         // 2. 权限列表
 | 
			
		
	
		
			
				
					|  |  |  |         log.info(START_INSERT_FUNC_INFO); | 
			
		
	
		
			
				
					|  |  |  |         List<FuncInfoFormDTO> funcInfos = new ArrayList<>(); | 
			
		
	
		
			
				
					|  |  |  |         List<Map> func_info = authorizationInfoResultDTO.getFunc_info(); | 
			
		
	
		
			
				
					|  |  |  |         for (Map map1 : func_info) { | 
			
		
	
	
		
			
				
					|  |  | @ -268,6 +271,7 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |         redisThird.setAuthInfo(authorizationInfoResultDTO); | 
			
		
	
		
			
				
					|  |  |  |         //authorizer_refresh_token 放入缓存
 | 
			
		
	
		
			
				
					|  |  |  |         redisThird.setAuthorizerRefreshToken(refreshAccessToken); | 
			
		
	
		
			
				
					|  |  |  |         log.info(END_GET_AUTH_INFO); | 
			
		
	
		
			
				
					|  |  |  |         return authorizationInfoResultDTO; | 
			
		
	
		
			
				
					|  |  |  |     } | 
			
		
	
		
			
				
					|  |  |  | 
 | 
			
		
	
	
		
			
				
					|  |  | @ -323,13 +327,13 @@ public class ComponentVerifyTicketServiceImpl implements ComponentVerifyTicketSe | 
			
		
	
		
			
				
					|  |  |  |         String userId = tokenDto.getUserId(); | 
			
		
	
		
			
				
					|  |  |  |         String customerId = paCustomerAgencyDao.getCustomerIdByUserId(userId); | 
			
		
	
		
			
				
					|  |  |  |         try { | 
			
		
	
		
			
				
					|  |  |  |             request.setCharacterEncoding("UTF-8"); | 
			
		
	
		
			
				
					|  |  |  |             request.setCharacterEncoding(ModuleConstant.UTF8); | 
			
		
	
		
			
				
					|  |  |  |         } catch (UnsupportedEncodingException e) { | 
			
		
	
		
			
				
					|  |  |  |             e.printStackTrace(); | 
			
		
	
		
			
				
					|  |  |  |         } | 
			
		
	
		
			
				
					|  |  |  |         response.setCharacterEncoding("UTF-8"); | 
			
		
	
		
			
				
					|  |  |  |         String authCode = request.getParameter("auth_code"); | 
			
		
	
		
			
				
					|  |  |  |         String expiresIn = request.getParameter("expires_in"); | 
			
		
	
		
			
				
					|  |  |  |         response.setCharacterEncoding(ModuleConstant.UTF8); | 
			
		
	
		
			
				
					|  |  |  |         String authCode = request.getParameter(ModuleConstant.AUTH_CODE); | 
			
		
	
		
			
				
					|  |  |  |         String expiresIn = request.getParameter(ModuleConstant.EXPIRES_IN); | 
			
		
	
		
			
				
					|  |  |  |         //authCode存数据库
 | 
			
		
	
		
			
				
					|  |  |  |         AuthCodeFormDTO formDTO = new AuthCodeFormDTO(); | 
			
		
	
		
			
				
					|  |  |  |         formDTO.setAuthCode(authCode); | 
			
		
	
	
		
			
				
					|  |  | 
 |