forked from chanjarster/weixin-java-tools
-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bae84e1
commit 36028b8
Showing
5 changed files
with
103 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpOAuth2Service.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package me.chanjar.weixin.cp.tp.service; | ||
|
||
/** | ||
* <pre> | ||
* 构造第三方应用oauth2链接 | ||
* Created by feidian108 on 2023/3/24. | ||
* </pre> | ||
* <p> | ||
* <a href="https://developer.work.weixin.qq.com/document/path/91120">企业微信服务商文档</a> | ||
*/ | ||
public interface WxCpTpOAuth2Service { | ||
|
||
/** | ||
* <pre> | ||
* 构造第三方应用oauth2链接(静默授权) | ||
* </pre> | ||
* @param redirectUri 授权后重定向的回调链接地址 | ||
* @param state 重定向后state参数 | ||
* @return url string | ||
*/ | ||
String buildAuthorizeUrl(String redirectUri, String state); | ||
|
||
|
||
/** | ||
* <pre> | ||
* 构造第三方应用oauth2链接 | ||
* </pre> | ||
* @param redirectUri 授权后重定向的回调链接地址 | ||
* @param state 重定向后state参数 | ||
* @param scope 应用授权作用域,snsapi_base:静默授权,snsapi_privateinfo:手动授权 | ||
* @return url string | ||
*/ | ||
String buildAuthorizeUrl(String redirectUri, String state, String scope); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...n-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpOAuth2ServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package me.chanjar.weixin.cp.tp.service.impl; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.chanjar.weixin.common.util.http.URIUtil; | ||
import me.chanjar.weixin.cp.tp.service.WxCpTpOAuth2Service; | ||
import me.chanjar.weixin.cp.tp.service.WxCpTpService; | ||
|
||
import static me.chanjar.weixin.common.api.WxConsts.OAuth2Scope.SNSAPI_BASE; | ||
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.OAuth2.URL_OAUTH2_AUTHORIZE; | ||
|
||
@RequiredArgsConstructor | ||
public class WxCpTpOAuth2ServiceImpl implements WxCpTpOAuth2Service { | ||
|
||
private final WxCpTpService mainService; | ||
|
||
|
||
@Override | ||
public String buildAuthorizeUrl(String redirectUri, String state) { | ||
return this.buildAuthorizeUrl(redirectUri, state, SNSAPI_BASE); | ||
} | ||
|
||
@Override | ||
public String buildAuthorizeUrl(String redirectUri, String state, String scope) { | ||
StringBuilder url = new StringBuilder(URL_OAUTH2_AUTHORIZE); | ||
url.append("?appid=").append(this.mainService.getWxCpTpConfigStorage().getSuiteId()); | ||
url.append("&redirect_uri=").append(URIUtil.encodeURIComponent(redirectUri)); | ||
url.append("&response_type=code"); | ||
url.append("&scope=").append(scope); | ||
if (state != null) { | ||
url.append("&state=").append(state); | ||
} | ||
url.append("#wechat_redirect"); | ||
return url.toString(); | ||
} | ||
} |