🎨 修复部分单元测试

This commit is contained in:
Binary Wang
2020-08-23 23:54:15 +08:00
parent 33b13b1bcd
commit daf0b23328
5 changed files with 4 additions and 103 deletions

View File

@ -221,28 +221,12 @@ public abstract class BaseWxMpServiceImpl<H, P> implements WxMpService, RequestH
return WxMpSemanticQueryResult.fromJson(responseContent);
}
@Override
public String oauth2buildAuthorizationUrl(String redirectURI, String scope, String state) {
return String.format(CONNECT_OAUTH2_AUTHORIZE_URL.getUrl(this.getWxMpConfigStorage()),
this.getWxMpConfigStorage().getAppId(), URIUtil.encodeURIComponent(redirectURI), scope, StringUtils.trimToEmpty(state));
}
@Override
public String buildQrConnectUrl(String redirectUri, String scope, String state) {
return String.format(QRCONNECT_URL.getUrl(this.getWxMpConfigStorage()), this.getWxMpConfigStorage().getAppId(),
URIUtil.encodeURIComponent(redirectUri), scope, StringUtils.trimToEmpty(state));
}
private WxMpOAuth2AccessToken getOAuth2AccessToken(String url) throws WxErrorException {
try {
RequestExecutor<String, String> executor = SimpleGetRequestExecutor.create(this);
String responseText = executor.execute(url, null, WxType.MP);
return WxMpOAuth2AccessToken.fromJson(responseText);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
@Override
public String[] getCallbackIP() throws WxErrorException {
String responseContent = this.get(GET_CALLBACK_IP_URL, null);

View File

@ -17,7 +17,7 @@ public class DemoOAuth2Handler implements WxMpMessageHandler {
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
Map<String, Object> context, WxMpService wxMpService,
WxSessionManager sessionManager) {
String href = "<a href=\"" + wxMpService.oauth2buildAuthorizationUrl(
String href = "<a href=\"" + wxMpService.getOAuth2Service().buildAuthorizationUrl(
wxMpService.getWxMpConfigStorage().getOauth2redirectUri(),
WxConsts.OAuth2Scope.SNSAPI_USERINFO, null) + "\">测试oauth2</a>";
return WxMpXmlOutMessage.TEXT().content(href)

View File

@ -31,15 +31,15 @@ public class WxMpOAuth2Servlet extends HttpServlet {
response.getWriter().println("<h1>code</h1>");
response.getWriter().println(code);
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = this.wxMpService.oauth2getAccessToken(code);
WxMpOAuth2AccessToken wxMpOAuth2AccessToken = this.wxMpService.getOAuth2Service().getAccessToken(code);
response.getWriter().println("<h1>access token</h1>");
response.getWriter().println(wxMpOAuth2AccessToken.toString());
WxMpUser wxMpUser = this.wxMpService.oauth2getUserInfo(wxMpOAuth2AccessToken, null);
WxMpUser wxMpUser = this.wxMpService.getOAuth2Service().getUserInfo(wxMpOAuth2AccessToken, null);
response.getWriter().println("<h1>user info</h1>");
response.getWriter().println(wxMpUser.toString());
wxMpOAuth2AccessToken = this.wxMpService.oauth2refreshAccessToken(wxMpOAuth2AccessToken.getRefreshToken());
wxMpOAuth2AccessToken = this.wxMpService.getOAuth2Service().refreshAccessToken(wxMpOAuth2AccessToken.getRefreshToken());
response.getWriter().println("<h1>after refresh</h1>");
response.getWriter().println(wxMpOAuth2AccessToken.toString());