更新记录
0.0.1(2026-02-11)
- init
平台兼容性
uni-app(4.72)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | - | - | - | - | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
syh-xhsshare 小红书功能集成
syh-xhsshare UTS插件集成小红书核心功能(分享单图、多图、视频等)的接口使用方法,适用于Android/iOS。
特性
- ✅ 支持单图分享
- ✅ 支持多图分享(图片路径数组)
- ✅ 支持Base64图片数据分享(二进制数据直传)
- ✅ 支持视频分享
- ✅ 同时支持 Android 和 iOS
- ✅ 完善的错误码和回调机制
安装
插件市场导入,在页面引入,修改各平台的文件后,自定义基座
请在试用后,确定需要后才购买。
Android
在 uni_modules/syh-xhsshare/utssdk/app-android/AndroidManifest.xml文档中将所有填写真实包名换成你的应用包名
iOS
在 uni_modules/syh-xhsshare/utssdk/app-ios/Info.plist文档将填写小红书AppKey换成你的小红书AppKey
代码演示
初始化小红书配置
import {useXhsShare, type SyhXhsShareConfig} from '@/uni_modules/syh-xhsshare';
const xhsUtils = useXhsShare({
appKey: "小红书开放平台AppKey", // 小红书开放平台AppKey
universalLink: "https://yourdomain.com/universal-link/", // iOS Universal Link
success: (res) => console.log("初始化成功", res),
fail: (err) => console.error("初始化失败", err)
} as SyhXhsShareConfig);
SyhXhsShareConfig
| 参数名 | 类型 | 必填 | 说明 | 平台差异 | 默认值 |
|---|---|---|---|---|---|
| appKey | string | 是 | 小红书开放平台注册的AppKey | Android/iOS 均需 | 无 |
| universalLink | string | iOS必填 | iOS Universal Link(用于小红书分享等功能) | 仅iOS生效 | 无 |
| success | (res: SyhXhsSuccessCallbackResult) => void | 否 | 初始化成功的回调(返回状态码及消息) | 无 | 无 |
| fail | (res: SyhXhsFail) => void | 否 | 初始化失败的回调(包含错误码及错误信息) | 无 | 无 |
| complete | (res: any) => void | 否 | 接口调用完成的回调(无论成功/失败均触发) | 无 | 无 |
小红书客户端检查
// 是否存在小红书客户端
xhsUtils.isInstalled()
打开小红书活动页
xhsUtils.openUrl("https://www.xiaohongshu.com/activity-page")
分享单图
import { type SyhXhsShareOptions} from '@/uni_modules/syh-xhsshare';
xhsUtils.share({
type: 'image',
imageUrl: 'https://example.com/share-image.jpg',
thumb: 'https://example.com/thumbnail.jpg', // 建议提供缩略图
title: '分享标题',
summary: '分享描述'
} as SyhXhsShareOptions);
分享多图(路径数组)
import { type SyhXhsShareOptions} from '@/uni_modules/syh-xhsshare';
xhsUtils.share({
type: 'image',
imageUrls: [
'https://example.com/image1.jpg',
'https://example.com/image2.jpg',
'https://example.com/image3.jpg'
],
title: '多图分享标题',
summary: '一次分享多张精美图片'
} as SyhXhsShareOptions);
分享多图(Base64 数据)
import { type SyhXhsShareOptions} from '@/uni_modules/syh-xhsshare';
// 适用于动态生成的图片(如画布截图、图片处理后的结果)
xhsUtils.share({
type: 'image',
imageData: [
'iVBORw0KGgoAAAANSUhEUgAA...', // Base64编码的图片数据1
'iVBORw0KGgoAAAANSUhEUgBB...', // Base64编码的图片数据2
],
title: 'Base64多图分享',
summary: '支持直接传入图片二进制数据'
} as SyhXhsShareOptions);
分享视频
import { type SyhXhsShareOptions} from '@/uni_modules/syh-xhsshare';
// 分享示例
xhsUtils.share({
type: 'video',
title: '精彩视频',
summary: '这是一段精彩的视频',
videoUrl: 'https://example.com/movie-trailer.mp4',
thumb: 'https://example.com/video-thumb.jpg' // 建议提供缩略图
} as SyhXhsShareOptions);
SyhXhsShareOptions 参数说明表
| 参数名 | 类型 | 必填条件 | 说明 | 适用分享类型 | 示例值 |
|---|---|---|---|---|---|
| type | string | 必填 | 分享类型:image(图片) 或 video(视频) |
所有类型 | "image" |
| title | string | 否 | 分享标题 | image/video | "限时特惠" |
| summary | string | 否 | 分享描述 | image/video | "点击领取新人礼包" |
| thumb | string | 建议提供 | 缩略图URL(建议<32KB) | image/video | "https://example.com/thumb.jpg" |
| imageUrl | string | image类型单图分享时填写 | 单张图片资源地址(支持本地路径和网络路径) | image | "/static/share.jpg" |
| imageUrls | string[] | image类型多图分享时填写 | 多图路径数组(与 imageUrl 互斥,优先级更高) | image | ["img1.jpg", "img2.jpg"] |
| imageData | string[] | image类型Base64分享时填写 | 多图Base64编码数据数组(优先级最高) | image | ["iVBORw0K...", "iVBORw0K..."] |
| videoUrl | string | video类型必填 | 视频URL | video | "https://example.com/video.mp4" |
| success | (res: SyhXhsSuccessCallbackResult) => void | 否 | 分享成功的回调 | 无 | 无 |
| fail | (res: SyhXhsFail) => void | 否 | 分享失败的回调(包含错误码及错误信息) | 无 | 无 |
| complete | (res: any) => void | 否 | 接口调用完成的回调(无论成功/失败均触发) | 无 | 无 |
图片参数优先级
当同时传入多个图片参数时,优先级为:
- imageData(Base64 数据)— 最高优先级
- imageUrls(多图路径数组)— 次优先级
- imageUrl(单图路径)— 最低优先级
分享相关错误码表
| 错误码 | 说明 | 常见原因 | 处理建议 |
|---|---|---|---|
| 9010001 | 小红书未安装 | 用户设备未安装小红书App | 提示用户安装小红书App |
| 9010002 | 小红书版本号太低 | 用户设备小红书版本过低 | 提示用户升级小红书App |
| 9010003 | 资源缺失 | 图片或视频资源未提供 | 检查imageUrl/imageUrls/imageData或videoUrl参数 |
| 9010004 | 图片或者视频文件不存在 | 提供的文件路径无效 | 检查文件路径是否正确 |
| 9010005 | 文件处理失败 | 文件格式不支持或损坏 | 检查文件格式是否正确 |
| 9010008 | 鉴权失败 | AppKey无效或未正确配置 | 检查AppKey和universalLink配置 |
| 9010009 | 打开分享页面失败 | 小红书App响应异常 | 检查小红书App是否正常运行 |
| 9010010 | 传递数据有误 | 参数格式错误 | 检查分享参数格式 |
| 9010022 | 用户取消发布 | 用户主动取消分享操作 | 属于正常用户行为,可以引导用户重新分享 |

收藏人数:
购买普通授权版(
试用
赞赏(0)
下载 0
赞赏 0
下载 11222103
赞赏 1859
赞赏
京公网安备:11010802035340号