Skip to content

Commit

Permalink
🆕 #2207 【企业微信】增加构建扫码登录二维码链接的方法
Browse files Browse the repository at this point in the history
  • Loading branch information
binarywang committed Jul 25, 2021
1 parent 7db5207 commit 0eb474d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,14 @@ public interface WxCpService extends WxService {
*/
void setWxCpConfigStorage(WxCpConfigStorage wxConfigProvider);

/**
* 构造扫码登录链接 - 构造独立窗口登录二维码
* @param redirectUri 重定向地址,需要进行UrlEncode
* @param state 用于保持请求和回调的状态,授权请求后原样带回给企业。该参数可用于防止csrf攻击(跨站请求伪造攻击),建议企业带上该参数,可设置为简单的随机数加session进行校验
* @return .
*/
String buildQrConnectUrl(String redirectUri, String state);

/**
* 获取部门相关接口的服务类对象
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
import me.chanjar.weixin.common.util.DataUtils;
import me.chanjar.weixin.common.util.RandomUtils;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.common.util.http.RequestExecutor;
import me.chanjar.weixin.common.util.http.RequestHttp;
import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor;
import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor;
import me.chanjar.weixin.common.util.http.*;
import me.chanjar.weixin.common.util.json.GsonParser;
import me.chanjar.weixin.cp.api.*;
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import org.apache.commons.lang3.StringUtils;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -394,6 +392,13 @@ public String getTaskResult(String joinId) throws WxErrorException {
return get(url, null);
}

@Override
public String buildQrConnectUrl(String redirectUri, String state) {
return String.format("https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=%s&agentid=%s&redirect_uri=%s&state=%s",
this.configStorage.getCorpId(), this.configStorage.getAgentId(),
URIUtil.encodeURIComponent(redirectUri), StringUtils.trimToEmpty(state));
}

public File getTmpDirFile() {
return this.tmpDirFile;
}
Expand Down

0 comments on commit 0eb474d

Please sign in to comment.