
本文共 10739 字,大约阅读时间需要 35 分钟。
���������������������������������accessToken������������������������������������������������������������������spring bean������������������������������������������xml������������������������������������������������������������������spring������������������������
���������������������������������spring������������������������������������
1���������������springUtil���
2���������������������������
������SpringUtils���������
1 package com.dt.base.weixin.util; 2 3 import org.springframework.aop.framework.AopContext; 4 import org.springframework.beans.BeansException; 5 import org.springframework.beans.factory.NoSuchBeanDefinitionException; 6 import org.springframework.beans.factory.config.BeanFactoryPostProcessor; 7 import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; 8 import org.springframework.stereotype.Component; 9 10 /** 11 * @Description: spring��������� ������������spring���������������������bean 12 * @author: ZhangChongHu 13 * @Date: 2020/12/8 17:23 14 * @Copyright: Xi'an Dian Tong Software Co., Ltd. All Rights Reserved. 15 * @Version 1.0 16 */ 17 @Component 18 public final class SpringUtils implements BeanFactoryPostProcessor 19 { 20 /** Spring��������������������� */ 21 private static ConfigurableListableBeanFactory beanFactory; 22 23 @Override 24 public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException 25 { 26 SpringUtils.beanFactory = beanFactory; 27 } 28 29 /** 30 * ������������ 31 * 32 * @param name 33 * @return Object ������������������������������bean��������� 34 * @throws BeansException 35 * 36 */ 37 @SuppressWarnings("unchecked") 38 public staticT getBean(String name) throws BeansException 39 { 40 return (T) beanFactory.getBean(name); 41 } 42 43 /** 44 * ���������������requiredType��������� 45 * 46 * @param clz 47 * @return 48 * @throws BeansException 49 * 50 */ 51 public static T getBean(Class clz) throws BeansException 52 { 53 T result = (T) beanFactory.getBean(clz); 54 return result; 55 } 56 57 /** 58 * ������BeanFactory������������������������������������bean������������������true 59 * 60 * @param name 61 * @return boolean 62 */ 63 public static boolean containsBean(String name) 64 { 65 return beanFactory.containsBean(name); 66 } 67 68 /** 69 * ������������������������������bean���������������singleton������������prototype��� ������������������������������bean���������������������������������������������������NoSuchBeanDefinitionException��� 70 * 71 * @param name 72 * @return boolean 73 * @throws NoSuchBeanDefinitionException 74 * 75 */ 76 public static boolean isSingleton(String name) throws NoSuchBeanDefinitionException 77 { 78 return beanFactory.isSingleton(name); 79 } 80 81 /** 82 * @param name 83 * @return Class ��������������������� 84 * @throws NoSuchBeanDefinitionException 85 * 86 */ 87 public static Class getType(String name) throws NoSuchBeanDefinitionException 88 { 89 return beanFactory.getType(name); 90 } 91 92 /** 93 * ���������������bean���������bean������������������������������������������ 94 * 95 * @param name 96 * @return 97 * @throws NoSuchBeanDefinitionException 98 * 99 */100 public static String[] getAliases(String name) throws NoSuchBeanDefinitionException101 {102 return beanFactory.getAliases(name);103 }104 105 /**106 * ������aop������������107 * 108 * @param invoker109 * @return110 */111 @SuppressWarnings("unchecked")112 public static T getAopProxy(T invoker)113 {114 return (T) AopContext.currentProxy();115 }116 }
������������������������
���������������getValidator()������������������������ AgentCfgDao agentCfgDao ,���������
1 @Autowired2 private AgentCfgDao agentCfgDao;
1 /** 2 * Copyright (c) 2014 - 2016 Xi'an Dian Tong Software Co., Ltd. All Rights Reserved. 3 *4 * This software is the confidential and proprietary information of Xi'an Dian Tong 5 * Software Co., Ltd. ("Confidential Information"). You shall not disclose such 6 * Confidential Information and shall use it only in accordance with the terms 7 * of the license agreement you entered into with Xi'an Dian Tong Software Co., Ltd. 8 */ 9 10 package com.dt.base.weixin.app; 11 12 import cn.hutool.http.HttpRequest; 13 import cn.hutool.http.HttpUtil; 14 import com.dt.base.weixin.util.SpringUtils; 15 import com.dt.ncfg.dao.AgentCfgDao; 16 import com.dt.sys.manage.entity.DtwxAgentCfg; 17 import org.apache.logging.log4j.LogManager; 18 import org.apache.logging.log4j.Logger; 19 import org.springframework.stereotype.Component; 20 import java.util.HashMap; 21 22 /** 23 * ��������� corpID + secret ������������ access token ��� 24 * key: corpID + secret 25 * value: access token 26 */ 27 28 public class AccessTokenPool { 29 30 protected final static Logger log = LogManager.getLogger("AccessTokenPool"); 31 32 DtwxAgentCfg dtwxAgentCfg = null; 33 34 35 /** 36 * ������AgentCfgDao 37 * 38 * @return 39 */ 40 protected AgentCfgDao getValidator() { 41 return SpringUtils.getBean(AgentCfgDao.class); 42 } 43 44 /** 45 * ������corpID, secret ������AccessToken 46 * 47 * @param corpID corpID 48 * @param secret secret 49 * @param type type 50 * @return 51 */ 52 public String getAccessToken(String corpID, String secret, String type) { 53 54 //������������������ 55 if ("QYH".equals(type)) { 56 57 //������������������http���������������������������������URL������������������URL��� 58 HashMap
paramMap = new HashMap<>(); 59 paramMap.put("corpId", corpID); 60 paramMap.put("corpSecret", secret); 61 String result = HttpUtil.get(resUrl() + "/api/mobile/QYH/isExist", paramMap); 62 return result; 63 } 64 //������������������ 65 if ("FWH".equals(type)) { 66 67 //������������������http���������������������������������URL������������������URL��� 68 HashMap paramMap = new HashMap<>(); 69 paramMap.put("appId", corpID); 70 paramMap.put("appSecret", secret); 71 72 String result = HttpUtil.get(resUrl() + "/api/mobile/FWH/isExist", paramMap); 73 return result; 74 } 75 //������������������ 76 if ("DING".equals(type)) { 77 78 //������������������http���������������������������������URL������������������URL��� 79 HashMap paramMap = new HashMap<>(); 80 paramMap.put("appKey", corpID); 81 paramMap.put("appSecret", secret); 82 83 String result = HttpUtil.get(resUrl() + "/api/mobile/DING/isExist", paramMap); 84 return result; 85 } 86 return null; 87 } 88 89 90 91 /** 92 * ������corpID, secret ������������token 93 * 94 * @param corpID 95 * @param secret 96 * @return 97 */ 98 public String delAccessToken(String corpID, String secret, String type) { 99 100 if ("QYH".equals(type)) {101 //������������������http���������������������������������URL������������������URL���102 HashMap paramMap = new HashMap<>(16);103 paramMap.put("corpId", corpID);104 paramMap.put("corpSecret", secret);105 //���������������������������106 HttpRequest.delete(resUrl() + "/api/mobile/QYH")107 .form(paramMap).execute().body();108 109 return null;110 }111 112 if ("FWH".equals(type)) {113 //������������������http���������������������������������URL������������������URL���114 HashMap paramMap = new HashMap<>(16);115 paramMap.put("appId", corpID);116 paramMap.put("appSecret", secret);117 //���������������������������118 HttpRequest.delete(resUrl() + "/api/mobile/FWH")119 .form(paramMap).execute().body();120 return null;121 }122 123 if ("DING".equals(type)) {124 HashMap paramMap = new HashMap<>(16);125 paramMap.put("appKey", corpID);126 paramMap.put("appSecret", secret);127 //���������������������������128 HttpRequest.delete(resUrl() + "/api/mobile/DING")129 .form(paramMap).execute().body();130 return "";131 }132 return "";133 }134 135 /**136 * ������corpID, secret ������JSTicket137 *138 * @param corpID139 * @param secret140 * @return141 */142 public String getJSTicket(String corpID, String secret, String type) {143 144 if ("QYH".equals(type)) {145 //������������������http���������������������������������URL������������������URL���146 HashMap paramMap = new HashMap<>(16);147 paramMap.put("corpId", corpID);148 paramMap.put("corpSecret", secret);149 //���������������������������150 String result = HttpUtil.get(resUrl() + "/api/mobile/QYH/isJSTicket", paramMap);151 152 return result;153 }154 155 if ("FWH".equals(type)) {156 //������������������http���������������������������������URL������������������URL���157 HashMap paramMap = new HashMap<>(16);158 paramMap.put("appId", corpID);159 paramMap.put("appSecret", secret);160 //���������������������������161 String result = HttpUtil.get(resUrl() + "/api/mobile/FWH/isJSTicket", paramMap);162 163 return result;164 }165 166 if ("DING".equals(type)) {167 HashMap paramMap = new HashMap<>(16);168 paramMap.put("appKey", corpID);169 paramMap.put("appSecret", secret);170 //���������������������������171 String result = HttpUtil.get(resUrl() + "/api/mobile/DING/isJSTicket", paramMap);172 173 return result;174 }175 return "";176 }177 /**178 * ���������������������url179 * @return url ������180 */181 public String resUrl(){182 //������url183 DtwxAgentCfg dtwxAgentCfg = new DtwxAgentCfg();184 dtwxAgentCfg.setAppType("wxInterfaceUrl");185 dtwxAgentCfg.setConfigKey("RESQUEST_ACS_TOKEN");186 DtwxAgentCfg agentCfg = getValidator().selectDataCfg(dtwxAgentCfg);187 //url=http://localhost:8080188 String url = agentCfg.getConfigValue();189 return url;190 }191 192 193 }
���������bug������������������������������������������������������������2020/12/16������������������������������������������������������������������
发表评论
最新留言
关于作者
