微信服務號應用每一個頁面均可以點擊右上角分享本頁面給朋友,如須要統一處理限定分享結果,能夠經過分享攔截器實現。 java
public class ShareInterceptor implements Interceptor { private static Logger log = Logger .getLogger(ShareInterceptor.class); @Override public void intercept(Invocation ai) { ApiConfig ac = new ApiConfig(); ac.setToken(PropKit.get("token")); ac.setAppId(PropKit.get("appId")); ac.setAppSecret(PropKit.get("appSecret")); ApiConfigKit.setThreadLocalApiConfig(ac); Controller contro = (Controller) ai.getController(); HttpServletRequest request = contro.getRequest(); String url = PropKit.get("weixin_uri")+ai.getActionKey()+"?"+request.getQueryString(); JsTicket jsapi_ticket = JsTicketApi.getTicket(JsApiType.jsapi); String ticket = jsapi_ticket.getTicket(); Map<String, String> signMap = WxUtil.sign(ticket,url); signMap.put("appId", PropKit.get("appId")); request.setAttribute("signMap", signMap); ai.invoke(); } }
若是須要全局攔截,就在configInterceptor時設置,若是隻對單個action攔截,就在action前@Before便可;同理能夠處理其餘微信api支持的操做。 api