更新记录
1.0.20250831(2025-08-30)
更新README
1.0.20250830(2025-08-30)
- 实现andorid和ios分享逻辑
- 完善README
1.0.20250826(2025-08-25)
- 更新README
查看更多
平台兼容性
uni-app(4.07)
Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
- |
- |
- |
- |
- |
- |
√ |
12 |
- |
微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.07)
Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
- |
- |
- |
- |
- |
- |
引入插件
- 点击插件试用引入到项目
- 打包自定义基座包
- 按照下方示例测试
- 先插件试用,完全符合需求后购买
插件引入
import * as workwxUtils from "@/uni_modules/cms-workwx";
插件方法
方法 |
描述 |
参数 |
registerApp(WorkwxRegisterAppOption):boolean |
注册App |
WorkwxRegisterAppOption见下方 |
isInstalled():boolean |
是否安装企业微信 |
无 |
openApp():boolean |
打开企业微信 |
无 |
login(LoginOption):void |
登录 |
LoginOption见下方 |
sendText(text:string):boolean |
分享文本 |
text:分享的文本 |
sendImage(fileName:string, filePath:string):boolean |
分享图片 |
fileName:文件名, filePath:文件路径 |
sendVideo(fileName:string, filePath:string):boolean |
分享视频 |
fileName:文件名, filePath:文件路径 |
sendFile(fileName:string, filePath:string):boolean |
分享文件 |
fileName:文件名, filePath:文件路径 |
sendLink(SendLinkOption):boolean |
分享链接 |
SendLinkOption见下方 |
sendMiniProgram(SendMiniProgramOption):void |
分享小程序 |
SendMiniProgramOption见下方 |
export type WorkwxRegisterAppOption = {
// 第三方App的Scheme
scheme : string,
// 第三方App所属企业的ID
corpid : string,
// 第三方App在企业内部的ID也就是AgentId
appid : string
}
export type LoginOption = {
// state 会在成功和失败原样返回
state ?: string,
success : (code : string, state : string) => void,
fail : (errCode : number, errMsg : string, state : string) => void
}
export type SendLinkOption = {
// 缩略图
thumbUrl : string,
// 链接
webpageUrl : string,
// 标题
title : string,
//描述
desc : string,
}
export type SendMiniProgramOption = {
//必须是应用关联的小程序,注意要有@app后缀 gh_dde54cb88ce7@app
username : string,
// 描述
desc : string,
// 标题
title : string,
// 图片
hdImageUrl : string,
// 小程序路径
path ?: string,
// 成功回调
success ?: () => void,
// 失败回调
fail ?: (errCode : number, errMsg : string) => void
}
注意
- 分享的文件并不是所有类型都可以分享 目前发现类型: .zip
- IOS下可以分享链接的缩略图可以使用本地选择的图片但注意图片大小 32kb
- Andorid Content URI路径文件拿取不到真实的文件名称,需使用插件市场其他插件本插件仅做最简示例
IOS
找到cms-workwx/app-ios/Info.plist 文件替换其中【scheme】为你自己的scheme
示例页面
所有方法需在 registerApp() 方法调用之后
<template>
<view>
<button type="primary" @click="registerApp">注册</button>
<button type="primary" @click="isInstalled">是否安装企业微信</button>
<button type="primary" @click="openWWApp">打开企业微信</button>
<button type="primary" @click="login">登陆</button>
<button type="primary" @click="sendText">分享文本</button>
<button type="primary" @click="sendImage">分享图片</button>
<button type="primary" @click="sendVideo">分享视频</button>
<button type="primary" @click="sendFile">分享文件</button>
<button type="primary" @click="sendLink">分享网页</button>
<button type="primary" @click="sendMiniProgram">分享小程序</button>
</view>
</template>
<script>
import * as workwxUtils from "@/uni_modules/cms-workwx";
export default {
methods: {
registerApp() {
this.showModal('registerApp', workwxUtils.registerApp({
// 第三方App的Scheme
scheme: "",
// 第三方App所属企业的ID
corpid: "",
// 第三方App在企业内部的ID也就是AgentId
appid: ""
}))
},
isInstalled(){;
this.showModal('isInstalled', workwxUtils.isInstalled() ? '已安装' : '未安装')
},
openWWApp(){
console.log('openApp:',workwxUtils.openApp());
},
login() {
workwxUtils.login({
state: "test",
success: (code, state) => {
this.showModal('login success', JSON.stringify({
code,
state
}));
},
fail: (errCode, errMsg, state) => {
this.showModal('login fail', JSON.stringify({
errCode,
errMsg,
state
}));
}
});
},
sendText() {
this.showModal("sendText", workwxUtils.sendText("一段文本"));
},
sendImage() {
uni.chooseImage({
count: 1,
success: (res) => {
let absPath = plus.io.convertLocalFileSystemURL(res.tempFilePaths[0]);
let splitArray = absPath.split('/');
let fileName = splitArray[splitArray.length - 1];
workwxUtils.sendImage(fileName, absPath)
}
});
},
sendVideo() {
uni.chooseVideo({
count: 1,
success: (res) => {
let absPath = plus.io.convertLocalFileSystemURL(res.tempFilePath);
let splitArray = absPath.split('/');
let fileName = splitArray[splitArray.length - 1];
workwxUtils.sendVideo(fileName, absPath)
}
});
},
sendFile() {
plus.io.chooseFile({
title: '选择文件',
filetypes: ['*'], // 允许所有文件类型
multiple: false,
}, (e) => {
if (e.files && e.files.length > 0) {
let osName = uni.getSystemInfoSync().osName;
let arr = e.files[0].split('/');
// 注:Andorid情况下如果获取到Content URI是拿不到真实文件名!需要用户使用其他文件选择插件,此处仅演示功能
let fileName = arr[arr.length - 1];
workwxUtils.sendFile(fileName, osName == 'ios' ? e.files[0] : plus.io.convertLocalFileSystemURL(e.files[0]))
}
}, (err) => {
uni.showToast({
title: '文件选择失败',
icon: 'none'
});
});
},
sendLink() {
workwxUtils.sendLink({
thumbUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png", // 缩略图
webpageUrl: "https://ext.dcloud.net.cn/plugin?id=24912", // 链接
title: "UTS 企业微信", // 标题
desc: "这是一段描述这是一段描述这是一段描述,这是一段描述...", //描述
})
},
sendMiniProgram() {
uni.chooseImage({
count: 1,
success: (res) => {
let absPath = plus.io.convertLocalFileSystemURL(res.tempFilePaths[0]);
let splitArray = absPath.split('/');
let fileName = splitArray[splitArray.length - 1];
workwxUtils.sendMiniProgram({
//必须是应用关联的小程序,注意要有@app后缀
username: "gh_dde54cb88ce7@app",
title: "测试_MaHow",
hdImageUrl: absPath,
path: "/pages/plugin/index.html?plugid=1cbd3b7c8674e61769436b5e354ddb2f",
desc: "dddddd1",
success: () => {
console.log('分享小程序成功')
},
fail: (errCode, errMsg) => {
console.log(`分享小程序失败:errCode:${errCode},errMsg:${errMsg}`);
}
})
}
});
},
showModal(title, content) {
uni.showModal({
title,
content: content + ''
})
}
}
}
</script>
参考链接
需要帮助?有其他插件的需求?联系我!