Skip to content

Commit ca00553

Browse files
penglesbinarywang
authored andcommitted
🆕 【公众号】优化配置类,增加新方法获取 OAuth 2.0重定向 URL 和 QR 连接重定向 URL !146
1 parent 03f78ca commit ca00553

File tree

6 files changed

+48
-4
lines changed

6 files changed

+48
-4
lines changed

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/WxMpConfigStorage.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ public interface WxMpConfigStorage {
2222

2323
/**
2424
* Is use stable access token api
25-
* @Link https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/getStableAccessToken.html
25+
*
2626
* @return the boolean
27+
* @link https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/getStableAccessToken.html
2728
*/
2829
boolean isStableAccessToken();
2930

3031
/**
3132
* Set use stable access token api
33+
*
3234
* @param useStableAccessToken true is use, false is not
3335
*/
3436
void useStableAccessToken(boolean useStableAccessToken);
@@ -154,9 +156,28 @@ public interface WxMpConfigStorage {
154156
* Gets oauth 2 redirect uri.
155157
*
156158
* @return the oauth 2 redirect uri
159+
* @deprecated This method is deprecated due to incorrect naming convention.
160+
* Use {@link #getOauth2RedirectUrl()} instead.
157161
*/
162+
@Deprecated
158163
String getOauth2redirectUri();
159164

165+
/**
166+
* Gets OAuth 2.0 redirect Url
167+
*
168+
* @return the OAuth 2.0 redirect Url
169+
* @author <a href="https://gitee.com/pengles">Peng Les</a>
170+
*/
171+
String getOauth2RedirectUrl();
172+
173+
/**
174+
* Gets QR connect redirect Url
175+
*
176+
* @return the QR connect redirect Url
177+
* @author <a href="https://gitee.com/pengles">Peng Les</a>
178+
*/
179+
String getQrConnectRedirectUrl();
180+
160181
/**
161182
* Gets http proxy host.
162183
*

weixin-java-mp/src/main/java/me/chanjar/weixin/mp/config/impl/WxMpDefaultConfigImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ public class WxMpDefaultConfigImpl implements WxMpConfigStorage, Serializable {
3434
protected volatile String aesKey;
3535
protected volatile long expiresTime;
3636

37+
@Deprecated
3738
protected volatile String oauth2redirectUri;
39+
protected volatile String oauth2RedirectUrl;
40+
protected volatile String qrConnectRedirectUrl;
3841

3942
protected volatile String httpProxyHost;
4043
protected volatile int httpProxyPort;

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImplTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ public void testBuildQrConnectUrl() {
4444
System.out.println(qrConnectUrl);
4545
}
4646

47+
@Test
48+
public void testBuildQrConnectRedirectUrl() {
49+
String qrConnectRedirectUrl = this.wxService.getWxMpConfigStorage().getQrConnectRedirectUrl();
50+
String qrConnectUrl = this.wxService.buildQrConnectUrl(qrConnectRedirectUrl,
51+
WxConsts.QrConnectScope.SNSAPI_LOGIN, null);
52+
Assert.assertNotNull(qrConnectUrl);
53+
System.out.println(qrConnectUrl);
54+
}
55+
4756
public void testGetTicket() throws WxErrorException {
4857
String ticket = this.wxService.getTicket(TicketType.SDK, false);
4958
System.out.println(ticket);

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/demo/DemoOAuth2Handler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
1818
Map<String, Object> context, WxMpService wxMpService,
1919
WxSessionManager sessionManager) {
2020
String href = "<a href=\"" + wxMpService.getOAuth2Service().buildAuthorizationUrl(
21-
wxMpService.getWxMpConfigStorage().getOauth2redirectUri(),
21+
wxMpService.getWxMpConfigStorage().getOauth2RedirectUrl(),
2222
WxConsts.OAuth2Scope.SNSAPI_USERINFO, null) + "\">测试oauth2</a>";
2323
return WxMpXmlOutMessage.TEXT().content(href)
2424
.fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())

weixin-java-mp/src/test/resources/test-config.sample.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<partnerKey>商户平台设置的API密钥</partnerKey>
1111
<keyPath>商户平台的证书文件地址</keyPath>
1212
<templateId>模版消息的模版ID</templateId>
13-
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
14-
<qrconnectRedirectUrl>网页应用授权登陆回调地址</qrconnectRedirectUrl>
13+
<oauth2RedirectUrl>网页授权获取用户信息回调地址</oauth2RedirectUrl>
14+
<qrConnectRedirectUrl>网页应用授权登陆回调地址</qrConnectRedirectUrl>
1515
<kfAccount>完整客服账号,格式为:账号前缀@公众号微信号</kfAccount>
1616
</xml>

weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenInMemoryConfigStorage.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,11 +572,22 @@ public String getMsgDataFormat() {
572572
return null;
573573
}
574574

575+
@Deprecated
575576
@Override
576577
public String getOauth2redirectUri() {
577578
return null;
578579
}
579580

581+
@Override
582+
public String getOauth2RedirectUrl() {
583+
return null;
584+
}
585+
586+
@Override
587+
public String getQrConnectRedirectUrl() {
588+
return null;
589+
}
590+
580591
@Override
581592
public String getHttpProxyHost() {
582593
return this.wxOpenConfigStorage.getHttpProxyHost();

0 commit comments

Comments
 (0)