更新记录

1.0.20251018(2025-10-17)

  1. 更新版本

1.0.20251017(2025-10-17)

  1. 更新版本

1.0.20250930.1(2025-09-30)

  1. 修正andorid分享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需要修改的内容
  • 打包自定义基座包
  • 按照下方示例测试
  • 先插件试用,完全符合需求后购买

IOS

  • 替换uni_modules/cms-weixin/utssdk/app-ios/Info.plist 文件替换其中【appId】为你自己应用的appId

Android

  • 替换uni_modules/cms-weixin/utssdk/app-android/AndroidManifest.xml 文件替换其中${applicationId}为你自己应用的包名

SDK Version

  • IOS Sdk 2.0.5
  • Android Sdk 6.8.34

插件引入

import * as wxUtils from "@/uni_modules/cms-weixin";

插件方法

方法 描述 参数
isInstalled():boolean 是否安装微信
openApp():boolean 打开微信
registerApp(RegisterAppOption):boolean 注册App 见下方
login(LoginWxOption):void 授权登录 见下方
sendText(SendWxMessageOption):void 分享文本 见下方
sendImage(SendWxMessageOption):void 分享图片 见下方
sendVideo(SendWxMessageOption):void 分享视频 见下方
sendLink(SendWxMessageOption):void 分享链接 见下方
sendMiniProgram(SendWxMessageOption):void 分享小程序 见下方
openMiniProgram(SendWxMessageOption):void 打开小程序 见下方
openWWService(SendWxMessageOption):void 打开客服 见下方
wxPay(WxPayOption):void 微信支付 见下方

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) 失败回调

错误码

  • 小于0的错误码是微信自己的错误码不在下方列表中
错误码 描述
9010001 未安装微信
9010002 未调用registerApp
9010003 ios send fail
9070001 sendText: text未填写
9020001 sendImage: imagePath未填写
9030001 sendVideo: videoUrl未填写
9040001 sendLink: webpageUrl未填写
9050001 sendMiniProgram: userName未填写
9060001 openWWService: corpId未填写
9060002 openWWService: url未填写
9060003 openWWService: 当前微信版本不支持

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: "***",
                    prepayId: "1101000000140415649af9fc314aa427",
                    package: "Sign=WXPay",
                    nonceStr: "1101000000140429eb40476f8896f4c9",
                    timeStamp: "***",
                    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: "***",
            prepayId: "1101000000140415649af9fc314aa427",
            package: "Sign=WXPay",
            nonceStr: "1101000000140429eb40476f8896f4c9",
            timeStamp: "***",
            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>

需要帮助?有其他插件的需求?联系我!

隐私、权限声明

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

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

插件不采集任何数据

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