Skip to content

Commit

Permalink
Fix issue Wechat-Group#1746: 企业微信第三方应用增加授权配置接口
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoInnovateLab committed Nov 28, 2020
1 parent c0af379 commit 63fb5a0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,20 @@ public interface WxCpTpService {
*/
String getPreAuthUrl(String redirectUri, String state) throws WxErrorException;

/**
* <pre>
* 获取预授权链接,测试环境下使用
* @Link https://work.weixin.qq.com/api/doc/90001/90143/90602
* </pre>
*
* @param redirectUri 授权完成后的回调网址
* @param state a-zA-Z0-9的参数值(不超过128个字节),用于第三方自行校验session,防止跨域攻击
* @param authType 授权类型:0 正式授权, 1 测试授权。
* @return pre auth url
* @throws WxErrorException the wx error exception
*/
String getPreAuthUrl(String redirectUri, String state, int authType) throws WxErrorException;

/**
* 获取企业的授权信息
*
Expand Down Expand Up @@ -278,7 +292,7 @@ public interface WxCpTpService {
* <pre>
* 获取访问用户敏感信息
* </pre>
*
*
* @param userTicket
* @return
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.chanjar.weixin.cp.tp.service.impl;

import com.google.common.base.Joiner;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -210,6 +211,30 @@ public String getPreAuthUrl(String redirectUri, String state) throws WxErrorExce
return preAuthUrl;
}

@Override
@SneakyThrows
public String getPreAuthUrl(String redirectUri, String state, int authType) throws WxErrorException {
String result = get(configStorage.getApiUrl(GET_PREAUTH_CODE), null);
WxCpTpPreauthCode preAuthCode = WxCpTpPreauthCode.fromJson(result);
String setSessionUrl = "https://qyapi.weixin.qq.com/cgi-bin/service/set_session_info";

Map<String,Object> sessionInfo = new HashMap<>(1);
sessionInfo.put("auth_type", authType);
Map<String,Object> param = new HashMap<>(2);
param.put("pre_auth_code", preAuthCode.getPreAuthCode());
param.put("session_info", sessionInfo);
String postData = new Gson().toJson(param);

post(setSessionUrl, postData);

String preAuthUrl = "https://open.work.weixin.qq.com/3rdapp/install?suite_id=" + configStorage.getSuiteId() +
"&pre_auth_code=" + preAuthCode.getPreAuthCode() + "&redirect_uri=" + URLEncoder.encode(redirectUri, "utf-8");
if (StringUtils.isNotBlank(state)) {
preAuthUrl += "&state=" + state;
}
return preAuthUrl;
}

@Override
public WxCpTpAuthInfo getAuthInfo(String authCorpId, String permanentCode) throws WxErrorException {
JsonObject jsonObject = new JsonObject();
Expand Down

0 comments on commit 63fb5a0

Please sign in to comment.