WeixinDispatcherServlet.java 文件源码

java
阅读 19 收藏 0 点赞 0 评论 0

项目:jwx 作者:
/**
 * 解析微信类
 * 
 * @param clazz
 * @throws ServletException
 * @throws MultiWeixinEncodingAESKeyException
 * @throws IllegalAccessException
 * @throws InstantiationException
 */
private void parseWeixinClass(Class<?> clazz) throws ServletException {
    Weixin wx = clazz.getAnnotation(Weixin.class);
    String url = wx.value();
    // 获取url对应的微信上下文,如果不存在,就新建一个
    WeixinContext context = contextMapper.get(url);
    if (context == null) {
        context = new WeixinContext();
        logger.debug("新建微信上下文(" + url + ")");
        contextMapper.put(url, context);
    }

    // 获取微信上下文的url,如果为空,则赋值
    if (StringUtil.isNull(context.getUrl())) {
        context.setUrl(url);
    }

    WeixinSetting setting = new WeixinSetting();
    setting.setUrl(url);
    setting.setAppID(wx.appID());
    setting.setAppSecret(wx.appSecret());
    setting.setEncodingAESKey(wx.encodingAESKey());
    setting.setToken(wx.token());

    //配置微信参数
    setContextParameter(context, setting);

    Object wxObj;
    try {
        // 生成微信对象实例
        wxObj = clazz.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        throw new InitialWeixinConfigureException("实例化微信对象异常", e);
    }

    // 注入spring服务
    SpringBeanAutowiringSupport.processInjectionBasedOnServletContext(wxObj, getServletContext());

    Method[] methods = clazz.getDeclaredMethods();
    // 解析微信方法
    for (Method method : methods) {
        if (WeixinMethod.hasWeixinAnnotationType(method)) {
            logger.debug("解析微信上下文(" + url + ")微信方法:" + method.getName());
            parseWeixinMethod(context, method, wxObj);
        }
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号