更新记录
1.0.0(2025-04-30)
支持iOS、安卓APP调用微信SDK功能
平台兼容性
uni-app x(4.31)
Chrome |
Safari |
Android |
iOS |
鸿蒙 |
微信小程序 |
- |
- |
5.0 |
12 |
× |
× |
开始
使用过程建议结合微信官方集成文档
项目工程配置
iOS平台 在Info.plist中配置UrlScheme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>LSApplicationQueriesSchemes</key>
<array>
<string>weixin</string>
</array>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>weixin</string>
<key>CFBundleURLSchemes</key>
<array>
<string>此处填写您在微信开放平台申请的appid</string>
</array>
</dict>
</array>
</dict>
</plist>
iOS平台 配置通用链接
参考uni官方文档-通用链接
引用
<script>
import * as wxsdk from "@/uni_modules/tt-wechat-pro";
export default {
data() {
return {
weChat: null as wxsdk.TTWeChatSDK | null,
}
}
}
</script>
获取对象
this.weChat = wxsdk.getTTWeChatSDK()
初始化SDK
this.weChat?.register({
appid: "填写您的appid",
universalLink: "填写iOS通用链接",
success: (e) => {
console.log("初始化成功");
},
fail: (err) => {
console.log(err);
}
} as wxsdk.TTWeChatRegisterOptions);
检测是否安装微信
this.weChat?.isInstall()
授权登录(可选)
第一步:请求 CODE
参数说明
入参TTWeChatLoginOptions
参数名称 |
类型 |
是否必传 |
描述 |
state |
string |
否 |
用来标识请求的唯一性,最后跳转回第三方程序时,由微信终端回传,字符串长度不能超过1K |
返回值TTWeChatLoginSuccess
参数名称 |
作用 |
code |
用户换取 access_token 的 code |
示例代码
this.weChat?.login({
state: "1",
success: (e) => {
console.log("成功");
//使用返回的code调用微信接口获取access_token等信息
},
fail: (error) => {
console.log(error);
}
} as wxsdk.TTWeChatLoginOptions)
第二步:参考微信官方文档获取access_token以及用户个人信息
参考授权后接口调用
分享
参数说明
TTWeChatShareOptions
参数 |
类型 |
是否必传 |
描述 |
type |
number |
是 |
分享类型 (0文本、1图片、2视频、3web、4小程序、5音乐) |
scene |
number |
是 |
分享场景 (0聊天界面、1朋友圈、2收藏) |
title |
string |
否 |
分享内容的标题(type=0时必传) |
desc |
string |
否 |
分享内容的摘要 |
imageUrl |
string |
否 |
分享图片地址(type=1时必传,仅支持本地路径) |
videoUrl |
string |
否 |
分享音视频地址(type=2时必传) |
musicUrl |
string |
否 |
分享音乐地址(type=5时必传) |
href |
string |
否 |
分享网址(type=3时必传) |
miniProgram |
TTWeChatShareMiniProgramOptions |
否 |
分享到小程序(type=4时必传) |
TTWeChatShareMiniProgramOptions
参数 |
类型 |
是否必传 |
描述 |
userName |
string |
是 |
小程序id |
path |
string |
是 |
小程序页面路径 |
webpageUrl |
string |
是 |
兼容低版本网页的URL |
miniProgramType |
number |
否 |
版本类型,可取值: 0-正式版; 1-开发版; 2-体验版。 默认值为0 |
示例代码
this.weChat?.share({
type: 0,
scene: 0,
title: '测试标题',
desc: '测试描述',
imageUrl: '/static/logo.png', //分享的图片地址
videoUrl: "视频地址", // 网络视频
musicUrl: "音乐地址", // 网络音乐
href: "网址", // 网页链接
miniProgram: {
userName: "123",
path: "",
webpageUrl: "",
miniProgramType: 0
} as wxsdk.TTWeChatShareMiniProgramOptions,
success: (res) => {
console.log('分享成功')
},
fail: (error) => {
console.log(error)
}
} as wxsdk.TTWeChatShareOptions)
支付
参数说明
TTWeChatPayOptions
参数 |
类型 |
是否必传 |
描述 |
partnerId |
string |
是 |
商家向财付通申请的商家id |
prepayId |
string |
是 |
预支付订单id |
nonceStr |
string |
是 |
随机字符串,不长于32位。该值建议使用随机数算法生成 |
timeStamp |
number |
是 |
时间戳,防重发 |
package |
string |
是 |
商家根据财付通文档填写的数据和签名 |
sign |
string |
是 |
商家根据微信开放平台文档对数据做的签名 |
示例代码
this.weChat?.pay({
partnerId: '',
prepayId: '',
nonceStr: '',
package: '',
timeStamp: 1746002056000,
sign: '',
success: (res) => {
console.log("支付成功");
},
fail: (error) => {
console.log(error);
}
} as wxsdk.TTWeChatPayOptions)
打开微信小程序
参数说明
TTWeChatLaunchMiniProgramOptions
参数 |
类型 |
是否必传 |
描述 |
userName |
string |
是 |
小程序id |
path |
string |
是 |
小程序页面路径 |
miniProgramType |
number |
否 |
版本类型,可取值: 0-正式版; 1-开发版; 2-体验版。 默认值为0 |
示例代码
this.weChat?.launchMiniProgram({
userName:"",
path:"",
miniProgramType:0,
success: (e) => {
console.log("成功");
},
fail: (err) => {
console.log(err);
}
} as wxsdk.TTWeChatLaunchMiniProgramOptions);
打开微信客服
参数说明
TTWeChatOpenCustomerServiceOptions
参数 |
类型 |
是否必传 |
描述 |
corpId |
string |
是 |
企业id |
url |
string |
是 |
客服url |
示例代码
this.weChat?.openCustomerService({
corpId:'',
url:'',
success: (e) => {
console.log("成功");
},
fail: (err) => {
console.log(err);
}
} as wxsdk.TTWeChatOpenCustomerServiceOptions);