<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.8.js"></script>
<!--
1.juzi-helper仅在系统侧边栏环境下覆写wx对象,成功后window.wx.isJuziWx === true
2.如果使用npm安装的jweixin或页面不存在wx对象,juzi-helper的覆写可能不会成功,此时可使用window.juziWx
-->
wx.invoke('getCurExternalContact', { }, function(res){
if (res.err_msg == "getCurExternalContact:ok") {
//成功处理 {userId: 'xxx', err_msg: 'getCurExternalContact:ok'}
} else {
//错误处理 {userId: undefined, err_msg: 'getCurExternalContact:fail'}
}
});
wx.invoke('getCurExternalChat', {}, function(res){
if (res.err_msg == "getCurExternalChat:ok") {
//成功处理 {chatId: 'xxx', err_msg: 'getCurExternalChat:ok'}
} else {
//错误处理 {chatId: undefined, err_msg: 'getCurExternalChat:fail'}
}
});
wx.getCurChatInfo({
success: function(res) {
// 成功处理
},
fail: function(res) {
// 失败处理 {err_msg: 'xxx'}
}
})
名称 | 数据类型 | 描述 |
---|---|---|
Id | string | 会话id |
name | string | 会话名称 |
type | number | 会话类型:0 单聊,1群聊 |
external | boolean | 是否是外部的:true 外部的 false 内部的 |
wxUserId | string | 企业微信联系人userId 可选 当type为 0 时有 等同 getCurExternalContact 接口拿到的userId |
wxChatId | string | 企业微信群聊chatId 可选 当type为 1 时有 等同 getCurExternalChat 接口拿到的chatId |
botId | string | 托管账号ID |
botName | string | 托管账号名称 |
botStatus | number | 托管账号状态:1离线 2在线 |
botType | number | 托管账号类型 export enum BotType { BOTTYPE_NONE = 0 WECHAT = 1 WXWORK = 2 OA = 3 WHATSAPP = 4 } |
jzGroupId | string | 系统小组ID |
jzUserId | string | 系统用户(右上角用户)的ID 注意:非托管账号用户ID 托管账号用户ID请参考"身份认证" |
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 MiniprogramMsg = {
msgtype: "miniprogram",
miniprogram: {
appid: string, // 小程序的appid
title: string, // 小程序消息的title
imgUrl: string, // 小程序消息的封面图,必须带http或者https协议头。
page: string, // 小程序消息打开后的路径
desc: string, // 小程序描述
iconUrl: string, // 小程序icon地址
officialAccountId: string, // 小程序原始id
},
}
type SendParams = TextMsg | ImageMsg | VideoMsg | FileMsg | NewsMsg | MiniprogramMsg;
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);
wx.openEnterpriseChat({
userIds: 'zhangsan', // 企业微信企业成员userId,必传
externalUserIds: 'wmEAlECwAAHrbWYDOK5u3Bf13xlYDAAA', // 企业微信外部联系人userId
chatId: 'CHATID', // 企业微信外部群chatId
success: function(res) {
// 成功处理 {err_msg: 'openEnterpriseChat:ok'}
},
fail: function(res) {
// 失败处理 {err_msg: 'xxx'}
}
})
wx.previewImage({
current: '', // 可选,第一张显示的图片链接
urls: [], // 必填,需要预览的图片http链接列表
})
https://{指定区域url}/oauth/connect/authorize?redirect_uri=REDIRECT_URI&state=STATE
参数 | 必须 | 说明 |
---|---|---|
redirect_uri | 是 | 授权后重定向的回调链接地址,请使用urlencode对链接进行处理 。 |
state | 否 | 重定向后会带上state参数,企业可以填写a-zA-Z0-9的参数值,长度不可超过128个字节。 |
GET https://{指定区域url}/api/v1/oauth/getUserInfo?code=**
参数 | 类型 | 备注 | 是否必须 |
---|---|---|---|
code | string | 通过成员授权获取到的code。每次成员授权带上的code将不一样,code只能使用一次,5分钟未被使用自动过期。 | 是 |
{
"errcode": 0,
"errmsg": "",
"data": {
"userId":"userId",
"corpId":"ww5ecc1acd5dce6e9d",
"botId":"647844cd6059597fc5c79f38",
"orgId":"644a448ab93794cbdccf93cb",
"uid": "644a448ab93794cbdccf93ca",
"email": "donghao_12_15@163.com",
"name": "句子"
}
}
参数 | 类型 | 必定存在 | 备注 |
---|---|---|---|
errcode | number | 是 | 返回码:0 成功,-1 无效的授权码,-2 授权码已过期,-4 未找到授权码,-5 未知错误 |
errmsg | string | 否 | 对返回码的文本描述内容 |
data.userId | string | 是 | 托管账号的企业微信明文userId |
data.corpId | string | 是 | 托管账号的企业微信明文corpId |
data.botId | string | 是 | 托管账号id |
data.orgId | string | 是 | 系统企业id |
data.uid | string | 是 | 系统成员id |
data.email | string | 否 | 系统成员邮箱 |
data.name | string | 否 | 系统成员姓名 |