|
1 | 1 | package me.chanjar.weixin.cp.tp.service.impl;
|
2 | 2 |
|
3 | 3 | import com.google.common.base.Joiner;
|
| 4 | +import com.google.gson.Gson; |
4 | 5 | import com.google.gson.JsonObject;
|
5 | 6 | import lombok.SneakyThrows;
|
6 | 7 | import lombok.extern.slf4j.Slf4j;
|
@@ -210,6 +211,30 @@ public String getPreAuthUrl(String redirectUri, String state) throws WxErrorExce
|
210 | 211 | return preAuthUrl;
|
211 | 212 | }
|
212 | 213 |
|
| 214 | + @Override |
| 215 | + @SneakyThrows |
| 216 | + public String getPreAuthUrl(String redirectUri, String state, int authType) throws WxErrorException { |
| 217 | + String result = get(configStorage.getApiUrl(GET_PREAUTH_CODE), null); |
| 218 | + WxCpTpPreauthCode preAuthCode = WxCpTpPreauthCode.fromJson(result); |
| 219 | + String setSessionUrl = "https://qyapi.weixin.qq.com/cgi-bin/service/set_session_info"; |
| 220 | + |
| 221 | + Map<String,Object> sessionInfo = new HashMap<>(1); |
| 222 | + sessionInfo.put("auth_type", authType); |
| 223 | + Map<String,Object> param = new HashMap<>(2); |
| 224 | + param.put("pre_auth_code", preAuthCode.getPreAuthCode()); |
| 225 | + param.put("session_info", sessionInfo); |
| 226 | + String postData = new Gson().toJson(param); |
| 227 | + |
| 228 | + post(setSessionUrl, postData); |
| 229 | + |
| 230 | + String preAuthUrl = "https://open.work.weixin.qq.com/3rdapp/install?suite_id=" + configStorage.getSuiteId() + |
| 231 | + "&pre_auth_code=" + preAuthCode.getPreAuthCode() + "&redirect_uri=" + URLEncoder.encode(redirectUri, "utf-8"); |
| 232 | + if (StringUtils.isNotBlank(state)) { |
| 233 | + preAuthUrl += "&state=" + state; |
| 234 | + } |
| 235 | + return preAuthUrl; |
| 236 | + } |
| 237 | + |
213 | 238 | @Override
|
214 | 239 | public WxCpTpAuthInfo getAuthInfo(String authCorpId, String permanentCode) throws WxErrorException {
|
215 | 240 | JsonObject jsonObject = new JsonObject();
|
|
0 commit comments