| @@ -31,6 +31,7 @@ public class ApiTestModule implements Module { | |||||
| } | } | ||||
| } | } | ||||
| @SuppressWarnings("unchecked") | |||||
| public static <T> T fromXml(Class<T> clazz, InputStream is) { | public static <T> T fromXml(Class<T> clazz, InputStream is) { | ||||
| XStream xstream = XStreamInitializer.getInstance(); | XStream xstream = XStreamInitializer.getInstance(); | ||||
| xstream.alias("xml", clazz); | xstream.alias("xml", clazz); | ||||
| @@ -1,5 +1,6 @@ | |||||
| package me.chanjar.weixin.mp.api.impl; | package me.chanjar.weixin.mp.api.impl; | ||||
| import org.testng.Assert; | |||||
| import org.testng.annotations.Guice; | import org.testng.annotations.Guice; | ||||
| import org.testng.annotations.Test; | import org.testng.annotations.Test; | ||||
| @@ -9,8 +10,6 @@ import me.chanjar.weixin.common.api.WxConsts; | |||||
| import me.chanjar.weixin.mp.api.ApiTestModule; | import me.chanjar.weixin.mp.api.ApiTestModule; | ||||
| import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage; | import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlMpInMemoryConfigStorage; | ||||
| import org.testng.Assert; | |||||
| @Test | @Test | ||||
| @Guice(modules = ApiTestModule.class) | @Guice(modules = ApiTestModule.class) | ||||
| public class WxMpServiceImplTest { | public class WxMpServiceImplTest { | ||||
| @@ -110,11 +109,9 @@ public class WxMpServiceImplTest { | |||||
| @Test | @Test | ||||
| public void testBuildQrConnectUrl() { | public void testBuildQrConnectUrl() { | ||||
| String qrConnectUrl = this.wxService | |||||
| .buildQrConnectUrl( | |||||
| ((WxXmlMpInMemoryConfigStorage) this.wxService | |||||
| .getWxMpConfigStorage()).getOauth2redirectUri(), | |||||
| WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); | |||||
| String qrconnectRedirectUrl = ((WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage()).getQrconnectRedirectUrl(); | |||||
| String qrConnectUrl = this.wxService.buildQrConnectUrl(qrconnectRedirectUrl, | |||||
| WxConsts.QRCONNECT_SCOPE_SNSAPI_LOGIN, null); | |||||
| Assert.assertNotNull(qrConnectUrl); | Assert.assertNotNull(qrConnectUrl); | ||||
| System.out.println(qrConnectUrl); | System.out.println(qrConnectUrl); | ||||
| } | } | ||||
| @@ -1,5 +1,12 @@ | |||||
| package me.chanjar.weixin.mp.demo; | package me.chanjar.weixin.mp.demo; | ||||
| import java.io.IOException; | |||||
| import javax.servlet.ServletException; | |||||
| import javax.servlet.http.HttpServlet; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import me.chanjar.weixin.common.util.StringUtils; | import me.chanjar.weixin.common.util.StringUtils; | ||||
| import me.chanjar.weixin.mp.api.WxMpConfigStorage; | import me.chanjar.weixin.mp.api.WxMpConfigStorage; | ||||
| import me.chanjar.weixin.mp.api.WxMpMessageRouter; | import me.chanjar.weixin.mp.api.WxMpMessageRouter; | ||||
| @@ -7,21 +14,12 @@ import me.chanjar.weixin.mp.api.WxMpService; | |||||
| import me.chanjar.weixin.mp.bean.WxMpXmlMessage; | import me.chanjar.weixin.mp.bean.WxMpXmlMessage; | ||||
| import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; | import me.chanjar.weixin.mp.bean.WxMpXmlOutMessage; | ||||
| import javax.servlet.ServletException; | |||||
| import javax.servlet.http.HttpServlet; | |||||
| import javax.servlet.http.HttpServletRequest; | |||||
| import javax.servlet.http.HttpServletResponse; | |||||
| import java.io.IOException; | |||||
| /** | /** | ||||
| * @author Daniel Qian | * @author Daniel Qian | ||||
| */ | */ | ||||
| public class WxMpEndpointServlet extends HttpServlet { | public class WxMpEndpointServlet extends HttpServlet { | ||||
| /** | |||||
| * | |||||
| */ | |||||
| private static final long serialVersionUID = 1L; | private static final long serialVersionUID = 1L; | ||||
| protected WxMpConfigStorage wxMpConfigStorage; | protected WxMpConfigStorage wxMpConfigStorage; | ||||
| protected WxMpService wxMpService; | protected WxMpService wxMpService; | ||||
| protected WxMpMessageRouter wxMpMessageRouter; | protected WxMpMessageRouter wxMpMessageRouter; | ||||
| @@ -33,7 +31,8 @@ public class WxMpEndpointServlet extends HttpServlet { | |||||
| this.wxMpMessageRouter = wxMpMessageRouter; | this.wxMpMessageRouter = wxMpMessageRouter; | ||||
| } | } | ||||
| @Override protected void service(HttpServletRequest request, HttpServletResponse response) | |||||
| @Override | |||||
| protected void service(HttpServletRequest request, HttpServletResponse response) | |||||
| throws ServletException, IOException { | throws ServletException, IOException { | ||||
| response.setContentType("text/html;charset=utf-8"); | response.setContentType("text/html;charset=utf-8"); | ||||
| @@ -1,29 +1,28 @@ | |||||
| package me.chanjar.weixin.mp.demo; | package me.chanjar.weixin.mp.demo; | ||||
| import me.chanjar.weixin.common.exception.WxErrorException; | |||||
| import me.chanjar.weixin.mp.api.WxMpService; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||||
| import java.io.IOException; | |||||
| import javax.servlet.ServletException; | import javax.servlet.ServletException; | ||||
| import javax.servlet.http.HttpServlet; | import javax.servlet.http.HttpServlet; | ||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| import java.io.IOException; | |||||
| public class WxMpOAuth2Servlet extends HttpServlet { | |||||
| import me.chanjar.weixin.common.exception.WxErrorException; | |||||
| import me.chanjar.weixin.mp.api.WxMpService; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; | |||||
| import me.chanjar.weixin.mp.bean.result.WxMpUser; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| public class WxMpOAuth2Servlet extends HttpServlet { | |||||
| private static final long serialVersionUID = 1L; | private static final long serialVersionUID = 1L; | ||||
| protected WxMpService wxMpService; | protected WxMpService wxMpService; | ||||
| public WxMpOAuth2Servlet(WxMpService wxMpService) { | public WxMpOAuth2Servlet(WxMpService wxMpService) { | ||||
| this.wxMpService = wxMpService; | this.wxMpService = wxMpService; | ||||
| } | } | ||||
| @Override protected void service(HttpServletRequest request, HttpServletResponse response) | |||||
| @Override | |||||
| protected void service(HttpServletRequest request, HttpServletResponse response) | |||||
| throws ServletException, IOException { | throws ServletException, IOException { | ||||
| response.setContentType("text/html;charset=utf-8"); | response.setContentType("text/html;charset=utf-8"); | ||||