ww.register 最后更新:2024/11/26 目录 - [ww.register(options)](https://developer.work.weixin.qq.com/document/path/94313/#wwregisteroptions) - [功能描述](https://developer.work.weixin.qq.com/document/path/94313/#%E5%8A%9F%E8%83%BD%E6%8F%8F%E8%BF%B0) - [参数说明](https://developer.work.weixin.qq.com/document/path/94313/#%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E) - [options: Object](https://developer.work.weixin.qq.com/document/path/94313/#options-object) - [附加说明](https://developer.work.weixin.qq.com/document/path/94313/#%E9%99%84%E5%8A%A0%E8%AF%B4%E6%98%8E) - [旧版jweixin调用](https://developer.work.weixin.qq.com/document/path/94313/#%E6%97%A7%E7%89%88jweixin%E8%B0%83%E7%94%A8) - [通过config注入企业身份权限](https://developer.work.weixin.qq.com/document/path/94313/#%E9%80%9A%E8%BF%87config%E6%B3%A8%E5%85%A5%E4%BC%81%E4%B8%9A%E8%BA%AB%E4%BB%BD%E6%9D%83%E9%99%90) - [通过agentConfig注入应用的权限](https://developer.work.weixin.qq.com/document/path/94313/#%E9%80%9A%E8%BF%87agentconfig%E6%B3%A8%E5%85%A5%E5%BA%94%E7%94%A8%E7%9A%84%E6%9D%83%E9%99%90) ## ww.register(options) ### 功能描述 注册应用信息。 ```ts ww.register({ corpId: 'ww7ca4776b2a70000', jsApiList: ['getExternalContact'], getConfigSignature }) ``` ### 参数说明 #### options: Object | | 属性 | 类型 | 必填 | 说明 | |-----|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | | corpId | string | 是 | 当前用户所属企业 ID | | | agentId | string | number | 否 | 当前应用 AgentID | | | suiteId | string | 否 | 应用套件 ID | | | jsApiList | string[] | 否 | 需要使用的JS接口列表 | | | openTagList | string[] | 否 | 需要使用的开放标签列表,例如['wx-open-launch-app'] | | | getConfigSignature | Function | 否 | config 签名生成函数 | | | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | | | onConfigSuccess | Function | 否 | config 成功回调 | | | **参数** **res: Object** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Object** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Object** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Object** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | | | onConfigFail | Function | 否 | config 失败回调 | | | **参数** **res: Error | Object** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | | | onConfigComplete | Function | 否 | config 完成回调 | | | **参数** **res: Error | Object** **可能为以下类型** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 **或** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** **可能为以下类型** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 **或** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** **可能为以下类型** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 **或** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** **可能为以下类型** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 **或** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | | | getAgentConfigSignature | Function | 否 | agentConfig 签名生成函数 | | | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | | | onAgentConfigSuccess | Function | 否 | agentConfig 成功回调 | | | **参数** **res: Object** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Object** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Object** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Object** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | | | onAgentConfigFail | Function | 否 | agentConfig 失败回调 | | | **参数** **res: Error | Object** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | | | onAgentConfigComplete | Function | 否 | agentConfig 完成回调 | | | **参数** **res: Error | Object** **可能为以下类型** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 **或** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** **可能为以下类型** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 **或** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** **可能为以下类型** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 **或** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | **参数** **res: Error | Object** **可能为以下类型** 属性 类型 必填 说明 errMsg string 是 通用错误信息 errCode number 是 通用错误码 **或** 属性 类型 必填 说明 checkResult Object 是 jsApiList 权限检查结果 errMsg string 是 通用错误信息 errCode number 是 通用错误码 | | | getSuiteConfigSignature | Function | 否 | suiteConfig 签名生成函数 | | | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | **参数** **url: string** 用于生成签名的 URL **返回值** **Object | Promise** 属性 类型 必填 说明 timestamp string | number 是 生成签名的时间戳 nonceStr string 是 生成签名的随机串 signature string 是 签名 | ### [](https://developer.work.weixin.qq.com/document/path/94313/#%E9%99%84%E5%8A%A0%E8%AF%B4%E6%98%8E)附加说明 **参数中的回调函数(如 `getConfigSignature`、`onConfigSuccess` 等)调用时机由 JSSDK 自行控制,开发者无需关心具体的调用顺序。在非微信、企业微信内置浏览器的环境下,JSSDK 不会主动调用 `getConfigSignature` 回调。** ## [](https://developer.work.weixin.qq.com/document/path/94313/#%E6%97%A7%E7%89%88jweixin%E8%B0%83%E7%94%A8)旧版jweixin调用 > 此接口为旧版jweixin中进行应用身份鉴权的方式 > 在新版的wecom-jssdk.js中,统一使用ww.register进行身份注册,通过传入getAgentConfigSignature参数来进行应用身份权限的注册 > 如果你的应用正在使用旧版 jweixin-1.2.0.js进行接口调用,我们强烈建议[进行升级](https://developer.work.weixin.qq.com/document/path/94313/#14931/%E6%97%A7%E7%89%88jweixin%E8%BF%81%E7%A7%BB) ### [](https://developer.work.weixin.qq.com/document/path/94313/#%E9%80%9A%E8%BF%87config%E6%B3%A8%E5%85%A5%E4%BC%81%E4%B8%9A%E8%BA%AB%E4%BB%BD%E6%9D%83%E9%99%90)通过config注入企业身份权限 ```javascript wx.config({ beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题 debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: '', // 必填,企业微信的corpID,必须是本企业的corpID,不允许跨企业使用 timestamp: '', // 必填,生成签名的时间戳 nonceStr: '', // 必填,生成签名的随机串 signature: '',// 必填,签名,见 附录-JS-SDK使用权限签名算法 jsApiList: [] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来 }); ``` ### [](https://developer.work.weixin.qq.com/document/path/94313/#%E9%80%9A%E8%BF%87agentconfig%E6%B3%A8%E5%85%A5%E5%BA%94%E7%94%A8%E7%9A%84%E6%9D%83%E9%99%90)通过agentConfig注入应用的权限 调用 wx.agentConfig需要引入 jwxwork sdk ```html ``` ```javascript wx.agentConfig({ corpid: '', // 必填,企业微信的corpid,必须与当前登录的企业一致 agentid: '', // 必填,企业微信的应用id (e.g. 1000247) timestamp: , // 必填,生成签名的时间戳 nonceStr: '', // 必填,生成签名的随机串 signature: '',// 必填,签名,见附录-JS-SDK使用权限签名算法 jsApiList: ['selectExternalContact'], //必填,传入需要使用的接口名称 success: function(res) { // 回调 }, fail: function(res) { if(res.errMsg.indexOf('function not exist') > -1){ alert('版本过低请升级') } } }); ``` 生成签名算法详见:[附录-JS-SDK使用权限签名算法](https://developer.work.weixin.qq.com/document/path/94313/#14924) > 注意,参数agentid为企业微信的[应用id](https://developer.work.weixin.qq.com/document/path/94313/#14953/agentid) **agentConfig的作用** config注入的是企业的身份与权限,而agentConfig注入的是应用的身份与权限。尤其是当调用者为第三方服务商时,通过config无法准确区分出调用者是哪个第三方应用,而在部分场景下,又必须严谨区分出第三方应用的身份,此时即需要通过agentConfig来注入应用的身份信息。 **调用agentConfig的注意事项** 1. agentConfig与config的签名算法完全一样,但是jsapi\_ticket的获取方法不一样,请特别注意,查看"[获取应用身份的ticket](https://developer.work.weixin.qq.com/document/path/90539#%E8%8E%B7%E5%8F%96%E5%BA%94%E7%94%A8%E7%9A%84jsapi-ticket)". 2. 企业微信3.0.24以前的老版本(可通过[企业微信UA](https://developer.work.weixin.qq.com/document/path/94313/#12067/%E4%BC%81%E4%B8%9A%E5%BE%AE%E4%BF%A1%E7%9A%84UA)判断版本号),在调用wx.agentConfig之前,必须确保先成功调用wx.config 3. 当前页面url中的域名必须是在该应用中设置的可信域名。 4. agentConfig仅在企业微信2.5.0及以后版本支持,微信客户端不支持(微信开发者工具也不支持) 5. 仅部分接口才需要调用agentConfig,需注意每个接口的说明 6. 企业微信ios/mac 端如果出现 "wx.agentConfig undefined" 的报错,可将调用放在异步操作中进行,例如使用:setTimeout 包裹