mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-03 04:13:37 +08:00
✨ #1230 企业微信增加第三方应用获取服务商凭证凭证的接口
This commit is contained in:
parent
4ff65a0ccb
commit
bd1cf2d8c3
@ -10,10 +10,12 @@ import me.chanjar.weixin.common.util.http.RequestHttp;
|
|||||||
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
|
||||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 微信API的Service.
|
* 微信API的Service.
|
||||||
|
*
|
||||||
* @author chanjaster
|
* @author chanjaster
|
||||||
*/
|
*/
|
||||||
public interface WxCpService {
|
public interface WxCpService {
|
||||||
@ -72,9 +74,10 @@ public interface WxCpService {
|
|||||||
/**
|
/**
|
||||||
* 获得jsapi_ticket,不强制刷新jsapi_ticket
|
* 获得jsapi_ticket,不强制刷新jsapi_ticket
|
||||||
* 应用的jsapi_ticket用于计算agentConfig(参见“通过agentConfig注入应用的权限”)的签名,签名计算方法与上述介绍的config的签名算法完全相同,但需要注意以下区别:
|
* 应用的jsapi_ticket用于计算agentConfig(参见“通过agentConfig注入应用的权限”)的签名,签名计算方法与上述介绍的config的签名算法完全相同,但需要注意以下区别:
|
||||||
*
|
* <p>
|
||||||
* 签名的jsapi_ticket必须使用以下接口获取。且必须用wx.agentConfig中的agentid对应的应用secret去获取access_token。
|
* 签名的jsapi_ticket必须使用以下接口获取。且必须用wx.agentConfig中的agentid对应的应用secret去获取access_token。
|
||||||
* 签名用的noncestr和timestamp必须与wx.agentConfig中的nonceStr和timestamp相同。
|
* 签名用的noncestr和timestamp必须与wx.agentConfig中的nonceStr和timestamp相同。
|
||||||
|
*
|
||||||
* @see #getJsapiTicket(boolean)
|
* @see #getJsapiTicket(boolean)
|
||||||
*/
|
*/
|
||||||
String getAgentJsapiTicket() throws WxErrorException;
|
String getAgentJsapiTicket() throws WxErrorException;
|
||||||
@ -134,6 +137,26 @@ public interface WxCpService {
|
|||||||
*/
|
*/
|
||||||
String[] getCallbackIp() throws WxErrorException;
|
String[] getCallbackIp() throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 获取服务商凭证
|
||||||
|
* 文档地址:https://work.weixin.qq.com/api/doc#90001/90143/91200
|
||||||
|
* 请求方式:POST(HTTPS)
|
||||||
|
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/service/get_provider_token
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @param corpId 服务商的corpid
|
||||||
|
* @param providerSecret 服务商的secret,在服务商管理后台可见
|
||||||
|
* @return {
|
||||||
|
* "errcode":0 ,
|
||||||
|
* "errmsg":"ok" ,
|
||||||
|
* "provider_access_token":"enLSZ5xxxxxxJRL",
|
||||||
|
* "expires_in":7200
|
||||||
|
* }
|
||||||
|
* @throws WxErrorException .
|
||||||
|
*/
|
||||||
|
WxCpProviderToken getProviderToken(String corpId, String providerSecret) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
|
* 当本Service没有实现某个API的时候,可以用这个,针对所有微信API中的GET请求
|
||||||
*
|
*
|
||||||
@ -206,7 +229,7 @@ public interface WxCpService {
|
|||||||
* @return WxSessionManager
|
* @return WxSessionManager
|
||||||
*/
|
*/
|
||||||
WxSessionManager getSessionManager();
|
WxSessionManager getSessionManager();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 设置WxSessionManager,只有当需要使用个性化的WxSessionManager的时候才需要调用此方法,
|
* 设置WxSessionManager,只有当需要使用个性化的WxSessionManager的时候才需要调用此方法,
|
||||||
@ -289,7 +312,7 @@ public interface WxCpService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取群聊服务
|
* 获取群聊服务
|
||||||
*
|
*
|
||||||
* @return 群聊服务
|
* @return 群聊服务
|
||||||
*/
|
*/
|
||||||
WxCpChatService getChatService();
|
WxCpChatService getChatService();
|
||||||
|
@ -24,6 +24,7 @@ import me.chanjar.weixin.cp.api.*;
|
|||||||
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||||
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
|
||||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -199,6 +200,14 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
|
|||||||
return ips;
|
return ips;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WxCpProviderToken getProviderToken(String corpId, String providerSecret) throws WxErrorException {
|
||||||
|
JsonObject jsonObject = new JsonObject();
|
||||||
|
jsonObject.addProperty("corpid", corpId);
|
||||||
|
jsonObject.addProperty("provider_secret", providerSecret);
|
||||||
|
return WxCpProviderToken.fromJson(this.post(this.configStorage.getApiUrl(GET_PROVIDER_TOKEN), jsonObject.toString()));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String get(String url, String queryParam) throws WxErrorException {
|
public String get(String url, String queryParam) throws WxErrorException {
|
||||||
return execute(SimpleGetRequestExecutor.create(this), url, queryParam);
|
return execute(SimpleGetRequestExecutor.create(this), url, queryParam);
|
||||||
|
@ -0,0 +1,30 @@
|
|||||||
|
package me.chanjar.weixin.cp.bean;
|
||||||
|
|
||||||
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
import lombok.Data;
|
||||||
|
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 服务商凭证.
|
||||||
|
*
|
||||||
|
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||||
|
* @date 2019-11-02
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class WxCpProviderToken {
|
||||||
|
/**
|
||||||
|
* 服务商的access_token,最长为512字节。
|
||||||
|
*/
|
||||||
|
@SerializedName("provider_access_token")
|
||||||
|
private String providerAccessToken;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* provider_access_token有效期(秒)
|
||||||
|
*/
|
||||||
|
@SerializedName("expires_in")
|
||||||
|
private Integer expiresIn;
|
||||||
|
|
||||||
|
public static WxCpProviderToken fromJson(String json) {
|
||||||
|
return WxCpGsonBuilder.create().fromJson(json, WxCpProviderToken.class);
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,8 @@ public final class WxCpApiPathConsts {
|
|||||||
public static final String BATCH_REPLACE_USER = "/cgi-bin/batch/replaceuser";
|
public static final String BATCH_REPLACE_USER = "/cgi-bin/batch/replaceuser";
|
||||||
public static final String BATCH_GET_RESULT = "/cgi-bin/batch/getresult?jobid=";
|
public static final String BATCH_GET_RESULT = "/cgi-bin/batch/getresult?jobid=";
|
||||||
public static final String JSCODE_TO_SESSION = "/cgi-bin/miniprogram/jscode2session";
|
public static final String JSCODE_TO_SESSION = "/cgi-bin/miniprogram/jscode2session";
|
||||||
public static final String GET_TOKEN = "/cgi-bin/gettoken?&corpid=%s&corpsecret=%s";
|
public static final String GET_TOKEN = "/cgi-bin/gettoken?corpid=%s&corpsecret=%s";
|
||||||
|
public static final String GET_PROVIDER_TOKEN = "/cgi-bin/service/get_provider_token";
|
||||||
|
|
||||||
public static class Agent {
|
public static class Agent {
|
||||||
public static final String AGENT_GET = "/cgi-bin/agent/get?agentid=%d";
|
public static final String AGENT_GET = "/cgi-bin/agent/get?agentid=%d";
|
||||||
|
@ -33,4 +33,9 @@ public class BaseWxCpServiceImplTest {
|
|||||||
public void testJsCode2Session() throws WxErrorException {
|
public void testJsCode2Session() throws WxErrorException {
|
||||||
assertThat(this.wxService.jsCode2Session("111")).isNotNull();
|
assertThat(this.wxService.jsCode2Session("111")).isNotNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetProviderToken() throws WxErrorException {
|
||||||
|
assertThat(this.wxService.getProviderToken("111","123")).isNotNull();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user