侧边栏JS-SDK
侧边栏JS-SDK是面向网页开发者提供的的网页开发工具包,类似企业微信JS-SDK。
快速接入
侧边栏JS-SDK实现了企业微信的JS-SDK接口,通过wx对象可调用。如果企业已经有企业微信的侧边栏,页面原有的企业微信JS-SDK接口调用逻辑可不做修改,按下列步骤快速接入
步骤一:引入JS文件
<script src="https://cdn.botorange.com/js/sidebar/juzi-helper-1.0.2.js"></script>
步骤二:修改OAuth授权(可选)
企业控制台单独提供了一套OAuth的授权登录方式,详见身份认证。
使用说明
步骤一:引入JS文件
在需要调用JS接口的页面引入如下JS文件:https://cdn.botorange.com/js/sidebar/juzi-helper-1.0.2.js
在秒回侧边栏环境下秒回侧边栏JS-SDK会覆盖微信的wx对象,并通过wx对象提供相关接口。
<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script src="https://cdn.botorange.com/js/sidebar/juzi-helper-1.0.2.js"></script>
步骤二:通过config接口初始化配置
wx.config(); // 可不传参数,调用即可
步骤三:通过ready接口处理成功验证
wx.ready(function(){}); // 同微信JS-SDK
wx.error(function(){}); // 同微信JS-SDK
身份认证
提供了OAuth的授权登录方式,可以让从自定义侧边栏打开的网页获取成员的身份信息,从而免去登录的环节。
构造授权链接
如果企业需要在打开的网页里面携带用户的身份信息,第一步需要构造如下的链接来获取code参数:
https://hub.juzibot.com/oauth/connect/authorize?redirect_uri=REDIRECT_URI&state=STATE
参数说明:
参数 | 必须 | 说明 |
---|---|---|
redirect_uri | 是 | 授权后重定向的回调链接地址,请使用urlencode对链接进行处理 |
state | 否 | 重定向后会带上state参数,企业可以填写a-zA-Z0-9的参数值,长度不可超过128个字节 |
将会以当前聊天窗口所属的托管企业微信进行自动授权,授权后页面将跳转至 redirect_uri?code=CODE&state=STATE&juziBotId=juziBotId,企业可根据code参数获得员工的userId。juziBotId为托管微信的id。
获取访问用户身份
该接口用于根据code获取成员信息
请求地址:
GET https://hub.juzibot.com/api/v1/oauth/getUserInfo?code=**&token=**
参数说明:
参数 | 类型 | 备注 | 是否必须 |
---|---|---|---|
code | string | 通过成员授权获取到的code。每次成员授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。 | 是 |
token | string | 调用接口凭证,企业控制台Token 。 | 是 |
返回结果:
{
"errcode": 0,
"errmsg": "",
"data": {
"userId":"USERID",
}
}
返回参数说明:
参数 | 类型 | 必定存在 | 备注 |
---|---|---|---|
errcode | number | 是 | 返回码 |
errmsg | string | 否 | 对返回码的文本描述内容 |
data.userId | string | 是 | 企业微信,企业成员UserID。 |
相关接口
获取当前外部联系人userid
同企业微信JS-SDK
wx.invoke('getCurExternalContact', { }, function(res){ });
获取当前客户群的群ID
从客户群的聊天工具栏进入页面时才可成功调用该接口
wx.invoke('getCurExternalChat', {
}, function(res){
if(res.err_msg == "getCurExternalChat:ok"){
chatId = res.chatId ; //返回当前外部群的群聊ID
}else {
//错误处理
}
});
分享消息到当前会话
type TextMsg = { msgtype: 'text'; text: { content: string; } };
type ImageMsg = {
msgtype: 'image';
image: {
url: string;
title?: string;
};
}
type VideoMsg = {
msgtype: 'video';
video: {
url: string;
title?: string;
};
}
type FileMsg = {
msgtype: 'file';
file: {
url: string;
title?: string;
};
}
type NewsMsg = {
msgtype: 'news',
news: {
link: string,
title?: string,
desc?: string,
imgUrl?: string,
},
}
type SendParams = TextMsg | ImageMsg | VideoMsg | FileMsg | NewsMsg;
type ErrMsg = 'sendChatMessage:ok' | 'text content is empty' | 'url is empty';
type Callback = (res: { err_msg: ErrMsg; }) => void;
wx.invoke('sendChatMessage', sendParams: SendParams, callback: Callback);