🆕 #1746: 【企业微信】第三方应用增加授权配置接口,同时增加向员工付款的接口

This commit is contained in:
LinXiaoHuChong
2020-11-29 23:00:38 +08:00
committed by GitHub
parent c0af379370
commit 0e2186632a
6 changed files with 324 additions and 2 deletions

View File

@ -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;
/**
* 获取企业的授权信息
*
@ -278,7 +292,7 @@ public interface WxCpTpService {
* <pre>
* 获取访问用户敏感信息
* </pre>
*
*
* @param userTicket
* @return
*/

View File

@ -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;
@ -210,6 +211,30 @@ public abstract class BaseWxCpTpServiceImpl<H, P> implements WxCpTpService, Requ
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();