更新记录
1.0.20251201(2025-12-01)
- 修正已知问题
1.0.20251102(2025-11-02)
- 修正已知问题
1.0.20251031(2025-10-31)
修正已知bug
查看更多
平台兼容性
uni-app(4.57)
| Vue2 |
Vue3 |
Chrome |
Safari |
app-vue |
app-nvue |
Android |
iOS |
鸿蒙 |
| - |
- |
- |
- |
- |
- |
5.0 |
12 |
√ |
| 微信小程序 |
支付宝小程序 |
抖音小程序 |
百度小程序 |
快手小程序 |
京东小程序 |
鸿蒙元服务 |
QQ小程序 |
飞书小程序 |
快应用-华为 |
快应用-联盟 |
| - |
- |
- |
- |
- |
- |
- |
- |
- |
- |
- |
uni-app x(4.57)
| Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
| - |
- |
5.0 |
12 |
- |
- |
引入插件
- 点击插件试用引入到项目
- 按下方修改Android/IOS/Harmony需要修改的内容
- 打包自定义基座包
- 按照下方示例测试
- 先插件试用,完全符合需求后购买
- 若使用本插件请勿勾选uniapp自带微信支付二者存在冲突
SDK Version
- IOS Sdk 2.0.5
- Android Sdk 6.8.34
- Harmony Sdk 1.0.15
IOS
- 替换uni_modules/cms-weixin/utssdk/app-ios/Info.plist 文件替换其中【appId】为你自己应用的appId
Android
- 替换uni_modules/cms-weixin/utssdk/app-android/AndroidManifest.xml 文件替换其中${applicationId}为你自己应用的包名
Harmony鸿蒙
- 参照链接创建harmony-configs/entry/src/main/module.json5文件, 定义 querySchemes。
- 在harmony-configs/entry/src/main/module.json5的 "module"下增加 "querySchemes": ["weixin","wxopensdk"]
- 在harmony-configs/entry/src/main/module.json5的 "module/abilities/skills/actions"下增加 "wxentity.action.open"

插件引入
import * as wxUtils from "@/uni_modules/cms-weixin";
插件方法
| 方法 |
描述 |
参数 |
兼容性 |
| isInstalled():boolean |
是否安装微信 |
无 |
Android/IOS/Harmony |
| openApp():boolean |
打开微信 |
无 |
Android/IOS/Harmony |
| registerApp(RegisterAppOption):boolean |
注册App |
见下方 |
Android/IOS/Harmony |
| login(LoginWxOption):void |
授权登录 |
见下方 |
Android/IOS/Harmony |
| sendText(SendWxMessageOption):void |
分享文本 |
见下方 |
Android/IOS/Harmony |
| sendImage(SendWxMessageOption):void |
分享图片 |
见下方 |
Android/IOS/Harmony |
| sendVideo(SendWxMessageOption):void |
分享视频 |
见下方 |
Android/IOS/Harmony |
| sendLink(SendWxMessageOption):void |
分享链接 |
见下方 |
Android/IOS/Harmony |
| sendMiniProgram(SendWxMessageOption):void |
分享小程序 |
见下方 |
Android/IOS/Harmony |
| openMiniProgram(SendWxMessageOption):void |
打开小程序 |
见下方 |
Android/IOS/Harmony |
| openWWService(SendWxMessageOption):void |
打开客服 |
见下方 |
Android/IOS/Harmony |
| wxPay(WxPayOption):void |
微信支付 |
见下方 |
Android/IOS/Harmony |
RegisterAppOption
| 参数 |
类型 |
描述 |
必填 |
| appId |
string |
微信应用appId |
是 |
| universalLink |
string |
iOS Universal Link |
ios平台必填 |
LoginWxOption
| 参数 |
类型 |
描述 |
必填 |
| scope |
string |
应用授权作用域 |
否 |
| state |
string |
自定义字符串、成功后会原样返回 |
否 |
| success(code:string, state:string):void |
function |
授权成功回调 code是微信返回数据 state 原样返回 |
否 |
| fail(errCode, errMsg):void |
function(number,string) |
授权失败回调 |
否 |
SendWxMessageOption
| 参数 |
类型 |
描述 |
必填 |
| scene |
number |
分享场景:0 对话 1 朋友圈 2收藏,默认0 |
否 |
| title |
string |
消息标题 sendLink/sendMiniProgram/openMiniProgram/sendVideo有效 |
否 |
| desc |
string |
消息描述 sendLink/sendMiniProgram/openMiniProgram/sendVideo有效 |
否 |
| thumbUrl |
string |
消息封面 sendLink/sendMiniProgram/openMiniProgram/sendVideo有效 |
否 |
| text |
string |
文本内容 |
sendText 必填 |
| imagePath |
string |
图片路径 |
sendImage 必填 |
| videoUrl |
string |
视频链接 |
sendVideo 必填 |
| videoLowBandUrl |
string |
供低带宽的环境下使用的视频链接 sendVideo有效 |
否 |
| webpageUrl |
string |
网页链接 / 小程序兼容低版本的网页链接 sendLink/sendMiniProgram有效 |
sendLink 必填 |
| userName |
string |
小程序的原始Id |
sendMiniProgram 必填 |
| path |
string |
小程序的 path sendMiniProgram有效 |
否 |
| miniprogramType |
number |
小程序的类型 正式版:0,测试版:1,体验版:2 默认正式版 sendMiniProgram有效 |
否 |
| corpId |
string |
打开客服的企业微信Id |
openWWService 必填 |
| url |
string |
客服URL |
openWWService 必填 |
| success() |
function |
成功回调 |
否 |
| fail(errCode, errMsg) |
function(number,string) |
失败回调 |
否 |
错误码
| 错误码 |
描述 |
| 9010001 |
未安装微信 |
| 9010002 |
未调用registerApp |
| 9010003 |
ios send fail |
| 9010004 |
鸿蒙分享仅支持分享到对话 |
| 9020001 |
sendImage: imagePath未填写 |
| 9030001 |
sendVideo: videoUrl未填写 |
| 9030002 |
sendVideo: 鸿蒙sdk暂不支持分享视频 |
| 9040001 |
sendLink: webpageUrl未填写 |
| 9050001 |
sendMiniProgram: userName未填写 |
| 9060001 |
openWWService: corpId未填写 |
| 9060002 |
openWWService: url未填写 |
| 9060003 |
openWWService: 当前微信版本不支持 |
| 9070001 |
sendText: text未填写 |
| 9080001 |
openMiniProgram:鸿蒙sdk暂不支持打开微信小程序 |
uniapp示例
所有方法需在 registerApp() 方法调用之后
<template>
<view>
<radio-group @change="radioChange" style="display: flex;align-items: center;margin: 10rpx 0;">
<label style="display: flex;align-items: center;" v-for="(item, index) in scenes" :key="item.value">
<view>
<radio :value="item.value" :checked="index === scene" />
</view>
<view>{{item.name}}</view>
</label>
</radio-group>
<button type="primary" @click="isWXAppInstalled">是否安装微信</button>
<button type="primary" @click="openApp">打开微信</button>
<button type="primary" @click="login">登录</button>
<button type="primary" @click="sendText">分享文本</button>
<button type="primary" @click="sendLocalImage">分享本地图片</button>
<button type="primary" @click="sendOnlieImage">分享在线图片(1M内)</button>
<button type="primary" @click="sendOnlieVideo">分享在线视频</button>
<button type="primary" @click="sendLink">分享网页</button>
<button type="primary" @click="sendMiniProgram">分享小程序</button>
<button type="primary" @click="openMiniProgram">打开小程序</button>
<button type="primary" @click="openWWService">打开客服</button>
<button type="primary" @click="wxpay">微信支付</button>
</view>
</template>
<script>
import * as wxUtils from "@/uni_modules/cms-weixin";
export default {
data() {
return {
scene: 0,
scenes: [
{ value: 0, name: '对话' },
{ value: 1, name: '朋友圈' },
{ value: 2, name: '收藏' }
],
}
},
onLoad() {
wxUtils.registerApp({
// 此处填写你自己的appId
appId: "",
// 此处填写你自己的universalLink
universalLink: ""
})
},
methods: {
radioChange(evt) {
for (let i = 0; i < this.scenes.length; i++) {
if (this.scenes[i].value === evt.detail.value) {
this.scene = i;
break;
}
}
},
login() {
wxUtils.login({
state: "wxUtils.login",
success(code, state) {
console.log('login success:', {
code,
state
})
},
fail(errCode, errMsg) {
console.log('login fail', {
errCode,
errMsg
})
}
});
},
isWXAppInstalled() {
uni.showToast({
title: wxUtils.isInstalled() ? "已安装微信" : "未安装微信",
icon: "none"
})
},
openApp(){
wxUtils.openApp()
},
sendText() {
wxUtils.sendText({
text: "你好微信",
scene: this.scene,
success() {
console.log('sendText success')
},
fail(errCode, errMsg) {
console.log('sendText fail', {
errCode,
errMsg
})
}
});
},
sendLocalImage() {
uni.chooseImage({
count: 1,
success: (res) => {
let absPath = plus.io.convertLocalFileSystemURL(res.tempFilePaths[0]);
wxUtils.sendImage({
imagePath: absPath,
scene: this.scene,
success() {
console.log('sendImage success')
},
fail(errCode, errMsg) {
console.log('sendImage fail', {
errCode,
errMsg
})
}
});
}
})
},
sendOnlieImage() {
wxUtils.sendImage({
imagePath: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png",
scene: this.scene,
success() {
console.log('sendImage success')
},
fail(errCode, errMsg) {
console.log('sendImage fail', {
errCode,
errMsg
})
}
});
},
sendOnlieVideo() {
wxUtils.sendVideo({
title: "UTS微信视频",
desc: "这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述",
videoUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/video.mp4",
videoLowBandUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/video.mp4",
thumbUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png",
scene: this.scene,
success() {
console.log('sendVideo success')
},
fail(errCode, errMsg) {
console.log('sendVideo fail', {
errCode,
errMsg
})
}
});
},
sendLink() {
wxUtils.sendLink({
title: "UTS微信网页",
desc: "这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述",
thumbUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png",
scene: this.scene,
webpageUrl: "https://ext.dcloud.net.cn/publisher?id=365074",
success() {
console.log('sendVideo success')
},
fail(errCode, errMsg) {
console.log('sendVideo fail', {
errCode,
errMsg
})
}
});
},
sendMiniProgram() {
wxUtils.sendMiniProgram({
title: "UTS 小程序",
desc: "这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述",
thumbUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png",
scene: this.scene,
webpageUrl: "https://ext.dcloud.net.cn/publisher?id=365074",
miniprogramType: 0,
// 小程序的原始ID
userName: "gh_82f38e6e43c9",
// 小程序路径
path: "pages/index/index",
success() {
console.log('sendMiniProgram success')
},
fail(errCode, errMsg) {
console.log('sendMiniProgram fail', {
errCode,
errMsg
})
}
});
},
openMiniProgram() {
wxUtils.openMiniProgram({
miniprogramType: 0,
// 小程序的原始ID
userName: "gh_82f38e6e43c9",
// 小程序路径
path: "pages/index/index",
success() {
console.log('openMiniProgram success')
},
fail(errCode, errMsg) {
console.log('openMiniProgram fail', {
errCode,
errMsg
})
}
});
},
openWWService() {
wxUtils.openWWService({
// 此处填写你自己的企业Id
corpId: "",
// 此处填写你自己的企业微信客服链接
url: "",
success() {
console.log('openWWService success')
},
fail(errCode, errMsg) {
console.log('openWWService fail',{
errCode, errMsg
})
}
});
},
wxpay() {
wxUtils.wxpay({
partnerId: "1900000109",
prepayId: "1101000000140415649af9fc314aa427",
package: "Sign=WXPay",
nonceStr: "1101000000140429eb40476f8896f4c9",
timeStamp: "1398746574",
sign: "oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZ\/X+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jq\/xDg==",
success(obj) {
console.log('wxpay success', obj)
},
fail(errCode, errMsg) {
console.log('wxpay fail', {
errCode,
errMsg
})
}
});
}
}
}
</script>
uniappx示例
所有方法需在 registerApp() 方法调用之后
<template>
<scroll-view class="page-scroll-view">
<radio-group @change="radioChange" style="display: flex;align-items: center;">
<radio v-for="(item, index) in scenes" :key="item.value" :checked="index === scene">
{{ item.name }}
</radio>
</radio-group>
<button type="primary" @click="isWXAppInstalled">是否安装微信</button>
<button type="primary" @click="openApp">打开微信</button>
<button type="primary" @click="login">登录</button>
<button type="primary" @click="sendText">分享文本</button>
<button type="primary" @click="sendLocalImage">分享本地图片</button>
<button type="primary" @click="sendOnlieImage">分享在线图片(1M内)</button>
<button type="primary" @click="sendOnlieVideo">分享在线视频</button>
<button type="primary" @click="sendLink">分享网页</button>
<button type="primary" @click="sendMiniProgram">分享小程序</button>
<button type="primary" @click="openMiniProgram">打开小程序</button>
<button type="primary" @click="openWWService">打开客服</button>
<button type="primary" @click="wxpay">微信支付</button>
</scroll-view>
</template>
<script setup lang="uts">
import { ref, onMounted } from 'vue'
import * as wxUtils from "@/uni_modules/cms-weixin";
// 响应式变量
const scene = ref(0)
const scenes = [
{ value: 0, name: '对话' },
{ value: 1, name: '朋友圈' },
{ value: 2, name: '收藏' }
]
// 生命周期
onMounted(() => {
wxUtils.registerApp({
// 此处填写你自己的appId
appId: "",
// 此处填写你自己的universalLink
universalLink: ""
} as wxUtils.RegisterAppOption)
})
// 方法定义
const radioChange = (evt : UniRadioGroupChangeEvent) => {
for (let i = 0; i < scenes.length; i++) {
if (scenes[i].value.toString() == evt.detail.value) {
scene.value = i;
break;
}
}
}
const login = () => {
wxUtils.login({
state: "wxUtils.login",
success(code : string, state : string) {
console.log('login success:', { code, state })
},
fail(errCode : number, errMsg : string) {
console.log('login fail', { errCode, errMsg })
}
} as wxUtils.LoginWxOption);
}
const isWXAppInstalled = () => {
uni.showToast({
title: wxUtils.isInstalled() ? "已安装微信" : "未安装微信",
icon: "none"
})
}
const openApp = () => {
wxUtils.openApp()
}
const sendText = () => {
wxUtils.sendText({
text: "你好微信",
scene: scene.value,
success() {
console.log('sendText success')
},
fail(errCode : number, errMsg : string) {
console.log('sendText fail', { errCode, errMsg })
}
} as wxUtils.SendWxMessageOption);
}
const sendLocalImage = () => {
uni.chooseImage({
count: 1,
success: (res) => {
// #ifdef APP-ANDROID
let absPath = res.tempFilePaths[0]
// let absPath = UTSAndroid.getResourcePath(res.tempFilePaths[0])
// let absPath = UTSAndroid.convert2AbsFullPath(res.tempFilePaths[0])
// #endif
// #ifdef APP-IOS
let absPath = res.tempFilePaths[0]
// let absPath = UTSiOS.getResourcePath(res.tempFilePaths[0])
// let absPath = UTSiOS.convert2AbsFullPath(res.tempFilePaths[0])
// #endif
wxUtils.sendImage({
imagePath: absPath,
scene: scene.value,
success() {
console.log('sendImage success')
},
fail(errCode : number, errMsg : string) {
console.log('sendImage fail', { errCode, errMsg })
}
} as wxUtils.SendWxMessageOption);
}
})
}
const sendOnlieImage = () => {
wxUtils.sendImage({
imagePath: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png",
scene: scene.value,
success() {
console.log('sendImage success')
},
fail(errCode : number, errMsg : string) {
console.log('sendImage fail', { errCode, errMsg })
}
} as wxUtils.SendWxMessageOption);
}
const sendOnlieVideo = () => {
wxUtils.sendVideo({
title: "UTS微信视频",
desc: "这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述",
videoUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/video.mp4",
videoLowBandUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/video.mp4",
thumbUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png",
scene: scene.value,
success() {
console.log('sendVideo success')
},
fail(errCode : number, errMsg : string) {
console.log('sendVideo fail', { errCode, errMsg })
}
} as wxUtils.SendWxMessageOption);
}
const sendLink = () => {
wxUtils.sendLink({
title: "UTS微信网页",
desc: "这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述",
thumbUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png",
scene: scene.value,
webpageUrl: "https://ext.dcloud.net.cn/publisher?id=365074",
success() {
console.log('sendLink success')
},
fail(errCode : number, errMsg : string) {
console.log('sendLink fail', { errCode, errMsg })
}
} as wxUtils.SendWxMessageOption);
}
const sendMiniProgram = () => {
wxUtils.sendMiniProgram({
title: "UTS 小程序",
desc: "这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述这是一段描述",
thumbUrl: "https://env-00jxt1cobn8u-static.normal.cloudstatic.cn/kuaiqucan/108.png",
scene: scene.value,
webpageUrl: "https://ext.dcloud.net.cn/publisher?id=365074",
miniprogramType: 0,
userName: "gh_82f38e6e43c9",
path: "pages/index/index",
success() {
console.log('sendMiniProgram success')
},
fail(errCode : number, errMsg : string) {
console.log('sendMiniProgram fail', { errCode, errMsg })
}
} as wxUtils.SendWxMessageOption);
}
const openMiniProgram = () => {
wxUtils.openMiniProgram({
miniprogramType: 0,
userName: "gh_82f38e6e43c9",
path: "pages/index/index",
success() {
console.log('openMiniProgram success')
},
fail(errCode : number, errMsg : string) {
console.log('openMiniProgram fail', { errCode, errMsg })
}
} as wxUtils.SendWxMessageOption);
}
const openWWService = () => {
wxUtils.openWWService({
// 此处填写你自己的企业Id
corpId: "",
// 此处填写你自己的企业微信客服链接
url: "",
success() {
console.log('openWWService success')
},
fail(errCode : number, errMsg : string) {
console.log('openWWService fail', { errCode, errMsg })
}
} as wxUtils.SendWxMessageOption);
}
const wxpay = () => {
wxUtils.wxpay({
partnerId: "1900000109",
prepayId: "1101000000140415649af9fc314aa427",
package: "Sign=WXPay",
nonceStr: "1101000000140429eb40476f8896f4c9",
timeStamp: "1398746574",
sign: `oR9d8PuhnIc+YZ8cBHFCwfgpaK9gd7vaRvkYD7rthRAZX+QBhcCYL21N7cHCTUxbQ+EAt6Uy+lwSN22f5YZvI45MLko8Pfso0jm46v5hqcVwrk6uddkGuT+Cdvu4WBqDzaDjnNa5UK3GfE1Wfl2gHxIIY5lLdUgWFts17D4WuolLLkiFZV+JSHMvH7eaLdT9N5GBovBwu5yYKUR7skR8Fu+LozcSqQixnlEZUfyE55feLOQTUYzLmR9pNtPbPsu6WVhbNHMS3Ss2+AehHvz+n64GDmXxbX++IOBvm2olHu3PsOUGRwhudhVf7UcGcunXt8cqNjKNqZLhLw4jqxDg==`,
success(obj : UTSJSONObject) {
console.log('wxpay success', obj)
},
fail(errCode : number, errMsg : string) {
console.log('wxpay fail', { errCode, errMsg })
}
} as wxUtils.WxPayOption);
}
</script>
<style>
.page-scroll-view {
height: 100%;
}
</style>
openMiniProgram / sendMiniProgram 注意事项
参考链接:https://developers.weixin.qq.com/doc/oplatform/Mobile_App/Launching_a_Mini_Program/Launching_a_Mini_Program.html
- 对于已通过认证的开放平台账号,其移动应用可以跳转至任何合法的小程序,且不限制跳转的小程序数量。
- 对于未通过认证的开放平台账号,其移动应用仅可以跳转至同一开放平台账号下小程序。
需要帮助?有其他插件的需求?联系我!