更新记录

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-appuni-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.runtimeopenURL 事件,并调用 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 配置(必须做)

  1. 配置 iOS URL Scheme:值为管理后台生成的 schema(形如 wwauth...
    • HBuilderX:项目 → manifest.json 可视化界面 → App → iOS → URL Types / URL Schemes
  2. 真机安装企业微信 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 用户取消
  • 9001005 SDK 返回失败
  • 9001006 存在未完成的请求
  • 9001007 当前平台不支持
  • 9001008 文件不存在
  • 9001009 文件读取失败
  • 9001999 未知错误

隐私、权限声明

1. 本插件需要申请的系统权限列表:

无(iOS需配置URL Scheme;Android 11+ 已内置 <queries> 包可见性)

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件本身不采集任何数据;通过集成企业微信登录/分享SDK实现登录与分享,相关个人信息保护规则:https://work.weixin.qq.com/nl/act/p/47eb57a00e9f4ad5

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。