Java Code Examples for com.jfinal.weixin.sdk.api.ApiConfigKit#removeThreadLocalApiConfig()

The following examples show how to use com.jfinal.weixin.sdk.api.ApiConfigKit#removeThreadLocalApiConfig() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiInterceptor.java    From jfinal-weixin with Apache License 2.0 5 votes vote down vote up
public void intercept(Invocation inv) {
	Controller controller = inv.getController();
	if (controller instanceof ApiController == false)
		throw new RuntimeException("控制器需要继承 ApiController");
	
	try {
		ApiConfigKit.setThreadLocalApiConfig(((ApiController)controller).getApiConfig());
		inv.invoke();
	}
	finally {
		ApiConfigKit.removeThreadLocalApiConfig();
	}
}
 
Example 2
Source File: MsgInterceptor.java    From jfinal-weixin with Apache License 2.0 5 votes vote down vote up
public void intercept(Invocation inv) {
	Controller controller = inv.getController();
	if (controller instanceof MsgController == false)
		throw new RuntimeException("控制器需要继承 MsgController");
	
	try {
		// 将 ApiConfig 对象与当前线程绑定,以便在后续操作中方便获取该对象: ApiConfigKit.getApiConfig();
		ApiConfigKit.setThreadLocalApiConfig(((MsgController)controller).getApiConfig());
		
		// 如果是服务器配置请求,则配置服务器并返回
		if (isConfigServerRequest(controller)) {
			configServer(controller);
			return ;
		}
		
		// 对开发测试更加友好
		if (ApiConfigKit.isDevMode()) {
			inv.invoke();
		} else {
			// 如果是服务器配置请求,则配置服务器并返回
			if (isConfigServerRequest(controller)) {
				configServer(controller);
				return ;
			}
			
			// 签名检测
			if (checkSignature(controller)) {
				inv.invoke();
			}
			else {
				controller.renderText("签名验证失败,请确定是微信服务器在发送消息过来");
			}
		}

	}
	finally {
		ApiConfigKit.removeThreadLocalApiConfig();
	}
}