更新记录
1.1.0(2026-08-15)
- readme.md增***ue2、vue3的示例代码。
1.0.0(2026-08-15)
1、支持Android、IOS、Harmony打开微信小程序。
平台兼容性
uni-app(5.15)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | × | × | √ | √ | √ | √ | √ |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| × | × | × | × | × | × | × | × | × | × | × | × |
uni-app x(5.15)
| Chrome | Safari | Android | iOS | 鸿蒙 | 微信小程序 |
|---|---|---|---|---|---|
| × | × | √ | √ | √ | × |
打开微信小程序
基于微信 Open SDK 封装的 UTS 插件,支持 HarmonyOS / Android / iOS 拉起微信小程序。
| 平台 | SDK |
|---|---|
| HarmonyOS | @tencent/wechat_open_sdk 1.0.15 |
| Android | com.tencent.mm.opensdk:wechat-sdk-android 6.8.0 |
| iOS | WechatOpenSDK-XCFramework 2.0.5 |
接入前准备
- 在微信开放平台创建移动应用,获取 AppID(不要填小程序 AppID)。
- 分别填写并审核通过各端信息:Android 包名与签名、iOS Bundle ID 与 Universal Links、鸿蒙 Bundle ID 与 Identifier。
- 准备目标小程序的原始 ID(以
gh_开头)。 - 真机已安装微信。模拟器通常无法拉起。
- Android、iOS 需制作自定义基座,运行时选择自定义基座,标准基座无法加载微信 Open SDK。
调用
Vue 3(uni-app x)
<template>
<view class="page">
<text class="title">打开微信小程序</text>
<text class="hint">通过微信 Open SDK 拉起小程序,请使用真机并填写开放平台参数。iOS 建议同时填写 Universal Link。</text>
<view class="form">
<text class="label">移动应用 AppID</text>
<input class="input" v-model="appId" placeholder="微信开放平台移动应用 AppID" />
<text class="label">小程序原始 ID</text>
<input class="input" v-model="userName" placeholder="gh_ 开头,不是小程序 AppID" />
<text class="label">页面路径(可选)</text>
<input class="input" v-model="path" placeholder="pages/index/index" />
<text class="label">Universal Link(iOS)</text>
<input class="input" v-model="universalLink" placeholder="https://your.domain.com/app/" />
<text class="label">小程序版本</text>
<view class="type-row">
<text class="type-item" :class="miniprogramType == 0 ? 'type-item-active' : ''"
@click="setMiniProgramType(0)">正式版</text>
<text class="type-item" :class="miniprogramType == 1 ? 'type-item-active' : ''"
@click="setMiniProgramType(1)">开发版</text>
<text class="type-item" :class="miniprogramType == 2 ? 'type-item-active' : ''"
@click="setMiniProgramType(2)">体验版</text>
</view>
</view>
<button class="btn" type="primary" @click="onCheckInstalled">检测微信是否安装</button>
<button class="btn" type="primary" @click="onLaunchMiniProgram">打开微信小程序</button>
<text class="result">{{ resultText }}</text>
</view>
</template>
<script setup lang="uts">
import { launchMiniProgram, isWXAppInstalled, LaunchMiniProgramOptions } from '@/uni_modules/omn-weixin-openmp'
const appId = ref('wxYourAppId')
const userName = ref('gh_xxxxxx')
const path = ref('pages/index/index')
const universalLink = ref('')
const miniprogramType = ref(0)
const resultText = ref('')
function setMiniProgramType(type : number) {
miniprogramType.value = type
}
function onCheckInstalled() {
const installed = isWXAppInstalled(appId.value)
resultText.value = installed ? '已安装微信' : '未安装微信,或 AppID 为空'
uni.showToast({
title: resultText.value,
icon: 'none'
})
}
function onLaunchMiniProgram() {
const type = miniprogramType.value
const options : LaunchMiniProgramOptions = {
appId: appId.value,
userName: userName.value,
path: path.value,
miniprogramType: type,
universalLink: universalLink.value,
success: (_res) => {
resultText.value = '已发起拉起'
uni.showToast({
title: '已发起拉起',
icon: 'success'
})
},
fail: (err) => {
resultText.value = err.errCode.toString() + ' ' + err.errMsg
uni.showToast({
title: err.errMsg,
icon: 'none'
})
}
}
launchMiniProgram(options)
}
</script>
Vue 2
<template>
<view class="page">
<text class="title">打开微信小程序</text>
<text class="hint">通过微信 Open SDK 拉起小程序,请使用真机并填写开放平台参数。iOS 建议同时填写 Universal Link。</text>
<view class="form">
<text class="label">移动应用 AppID</text>
<input class="input" v-model="appId" placeholder="微信开放平台移动应用 AppID" />
<text class="label">小程序原始 ID</text>
<input class="input" v-model="userName" placeholder="gh_ 开头,不是小程序 AppID" />
<text class="label">页面路径(可选)</text>
<input class="input" v-model="path" placeholder="pages/index/index" />
<text class="label">Universal Link(iOS)</text>
<input class="input" v-model="universalLink" placeholder="https://your.domain.com/app/" />
<text class="label">小程序版本</text>
<view class="type-row">
<text class="type-item" :class="miniprogramType == 0 ? 'type-item-active' : ''"
@click="setMiniProgramType(0)">正式版</text>
<text class="type-item" :class="miniprogramType == 1 ? 'type-item-active' : ''"
@click="setMiniProgramType(1)">开发版</text>
<text class="type-item" :class="miniprogramType == 2 ? 'type-item-active' : ''"
@click="setMiniProgramType(2)">体验版</text>
</view>
</view>
<button class="btn" type="primary" @click="onCheckInstalled">检测微信是否安装</button>
<button class="btn" type="primary" @click="onLaunchMiniProgram">打开微信小程序</button>
<text class="result">{{ resultText }}</text>
</view>
</template>
<script>
import { launchMiniProgram, isWXAppInstalled } from '@/uni_modules/omn-weixin-openmp'
export default {
data() {
return {
appId: 'wxYourAppId',
userName: 'gh_xxxxxx',
path: 'pages/index/index',
universalLink: '',
miniprogramType: 0,
resultText: ''
}
},
methods: {
setMiniProgramType(type) {
this.miniprogramType = type
},
onCheckInstalled() {
const installed = isWXAppInstalled(this.appId)
this.resultText = installed ? '已安装微信' : '未安装微信,或 AppID 为空'
uni.showToast({
title: this.resultText,
icon: 'none'
})
},
onLaunchMiniProgram() {
launchMiniProgram({
appId: this.appId,
userName: this.userName,
path: this.path,
miniprogramType: this.miniprogramType,
universalLink: this.universalLink,
success: () => {
this.resultText = '已发起拉起'
uni.showToast({
title: '已发起拉起',
icon: 'success'
})
},
fail: (err) => {
this.resultText = err.errCode + ' ' + err.errMsg
uni.showToast({
title: err.errMsg,
icon: 'none'
})
}
})
}
}
}
</script>
launchMiniProgram
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| appId | string | 是 | 微信开放平台移动应用 AppID |
| userName | string | 是 | 小程序原始 ID,如 gh_ff02937dbaec |
| path | string | 否 | 页面路径,可带参;不填打开首页 |
| miniprogramType | number | 否 | 0 正式版、1 开发版、2 体验版,默认 0 |
| universalLink | string | iOS 建议必填 | iOS 注册微信 SDK 使用的 Universal Link |
错误码
| errCode | 说明 |
|---|---|
| 9010001 | 移动应用 AppID 不能为空 |
| 9010002 | 小程序原始 ID 不能为空 |
| 9010003 | 未安装微信客户端 |
| 9010004 | 拉起失败(sendReq 返回 false) |
| 9010005 | 微信 SDK 调用异常 |
各端配置
HarmonyOS
harmony-configs/entry/src/main/module.json5 需包含:
{
"module": {
"querySchemes": ["weixin", "wxopensdk"]
}
}
若与 HBuilderX 生成文件冲突,把 querySchemes 合并进去,不要整文件覆盖。
Android
插件已配置:
- Maven 依赖
wechat-sdk-android AndroidManifest.xml中的INTERNET权限- Android 11+ 可见性
<queries><package android:name="com.tencent.mm" /></queries>
请保证打包签名与微信开放平台填写的一致。仅拉起小程序不需要 WXEntryActivity;若还要接收小程序回跳参数,需自行按微信文档增加 wxapi.WXEntryActivity。
iOS
插件已通过 CocoaPods 引入 WechatOpenSDK-XCFramework,并合并 LSApplicationQueriesSchemes:weixin、weixinULAPI、weixinURLParamsAPI。
宿主工程还需:
- URL Types 中增***信移动应用 AppID(与开放平台一致)。
- 开启 Associated Domains,配置 Universal Links(paths 需带
/*),并传入universalLink。 - SDK 2.0.4+ 才能在 iOS 18 / Xcode 16 上稳定拉起微信。
仅拉起小程序时可不实现 WXApiDelegate;若要接收小程序返回 App 的数据,需按微信文档处理 Universal Link / URL。
常见失败原因
- AppID 填成了小程序 AppID
- 开放平台对应端信息未审核通过
- Android 签名或包名不一致
- iOS 未配置 Universal Links / URL Scheme
- 未安装微信,或在模拟器上测试

收藏人数:
购买源码授权版(
试用
赞赏(0)
下载 1418
赞赏 4
下载 12509473
赞赏 1943
赞赏
京公网安备:11010802035340号