更新记录
1.0.0(2026-01-30)
- 初始发布
- 支持 App-Android / App-iOS(App-Harmony 提供 stub)
- 登录:
setup/isInstalled/auth - 分享:
shareText/shareImage/shareFile/shareVideo/shareLink/shareMiniProgram - 日志:
setLogEnabled/isLogEnabled
平台兼容性
uni-app(4.87)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | - | - | - | - | √ | √ | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
uni-app x(4.87)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| - | - | √ | √ | - | - |
hans-wework
企业微信(WeCom)登录(SSO) 与 分享(文本/图片/文件/视频/链接/小程序)UTS 插件,支持 uni-app 与 uni-app x。
平台支持
- App-Android:√
- App-iOS:√
- App-Harmony:-(stub)
安装
在项目的 uni_modules/ 下安装本插件(插件市场或直接拷贝目录均可),然后在业务代码里引入:
uni-app(Vue2/Vue3)
import * as wework from '@/uni_modules/hans-wework'
uni-app x(.uvue / UTS)
import * as wework from '@/uni_modules/hans-wework'
// 可选:在 uni-app x(UTS)里直接引入类型,获得更好的代码提示
import type { WeworkAuthOptions, WeworkShareLinkOptions } from '@/uni_modules/hans-wework/utssdk/interface.uts'
uni-app 与 uni-app x 使用差异
主要差异在 App-iOS 回跳(openURL):
uni-app x:插件已通过UTSiOSHookProxy自动接管回跳,无需额外写 openURL 转发。uni-app(Vue):需要在宿主层监听plus.runtime的openURL事件,并调用wework.handleOpenURL(url)转发给插件(见下方「uni-app(Vue)额外说明」)。
其余 API(setup/auth/share*)两边用法一致,都是 Promise 异步接口,推荐用 async/await。
快速开始
初始化(必须先调用):
wework.setup({
appId: 'wwxxxxxxxxxxxxxxxx',
agentId: '1000002',
schema: 'wwauthxxxxxxxxxxxxxxxxxxxx',
logEnabled: true
})
授权登录(获取一次性 code):
const { code, state } = await wework.auth({ state: 'csrf-rand' })
分享:
await wework.shareText({ text: 'hello wecom' })
await wework.shareLink({ url: 'https://www.tencent.com', title: '链接标题' })
管理后台配置(必须做)
在企业微信管理后台创建应用并配置移动端应用后,拿到三元组:
appId:企业 CorpID(形如wwxxxxxxxxxxxxxxxx)agentId:应用 AgentId(数字字符串)schema:管理后台生成(形如wwauth...)
说明:Android 的 schema 强依赖「包名 + 签名」,调试包/正式包签名不同会导致 schema 不同。
iOS 配置(必须做)
- 配置 iOS URL Scheme:值为管理后台生成的
schema(形如wwauth...)- HBuilderX:项目 →
manifest.json可视化界面 → App → iOS → URL Types / URL Schemes
- HBuilderX:项目 →
- 真机安装企业微信 App
uni-app(Vue)额外说明:openURL 转发
uni-app x 在 iOS 侧会通过 hook 自动接管回跳;但 uni-app(Vue)工程需要在宿主里把 openURL 转发给插件:
// App.vue
import * as wework from '@/uni_modules/hans-wework'
export default {
onLaunch() {
// #ifdef APP-PLUS
if (typeof plus !== 'undefined' && plus.runtime && plus.runtime.addEventListener) {
plus.runtime.addEventListener('openURL', (e) => {
if (e && e.url) wework.handleOpenURL(e.url)
}, false)
}
// #endif
}
}
Android 配置
- Android 无需额外配置 SDK
- 需安装企业微信 App
- 仍需在企业微信管理后台配置 Android 应用(包名 + 签名 → 生成
schema)
API
setup({ appId, agentId, schema, logEnabled? })isInstalled()auth({ state? }) => Promise<{ code, state? }>shareText({ text })shareImage({ filePath, fileName? })shareFile({ filePath, fileName? })shareVideo({ filePath, fileName? })shareLink({ url, title, summary?, thumbUrl?(Android), thumbPath?(iOS) })shareMiniProgram({ userName, path, title, summary?, hdImagePath })setLogEnabled(enabled)isLogEnabled()
小程序分享注意:
userName必须为应用关联的小程序且带@app后缀- 描述字段使用
summary(Android 生效;iOS SDK 无该字段,会忽略)
错误码(90xxxxx)
9001001参数错误9001002未初始化(未调用setup)9001003未安装企业微信9001004用户取消9001005SDK 返回失败9001006存在未完成的请求9001007当前平台不支持9001008文件不存在9001009文件读取失败9001999未知错误

收藏人数:
购买普通授权版(
试用
赞赏(0)
下载 229
赞赏 0
下载 11181789
赞赏 1854
赞赏
京公网安备:11010802035340号