分享
share(content)
Section titled “share(content)”调用系统分享功能。
SuperSDK.share('分享内容文本');requestShortUrl(url, baseUrl?)
Section titled “requestShortUrl(url, baseUrl?)”生成短链。将长链接转换为短链,便于分享。
// 使用默认前缀const shortUrl = await SuperSDK.requestShortUrl('https://example.com/very/long/path?param=value');console.log(shortUrl);// "https://s.supersdk.com/AbCd12"
// 使用自定义前缀const shortUrl2 = await SuperSDK.requestShortUrl('https://example.com/very/long/path', 'https://s.a.com/');console.log(shortUrl2);// "https://s.a.com/AbCd12"参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| url | string | 是 | 原始长链接 |
| baseUrl | string | 否 | 自定义短链前缀,如 https://s.a.com/。不传使用默认值 |
返回值: Promise<string> - 短链字符串
特性:
- 相同 URL 重复调用返回相同短链(幂等)
- 短链永久有效
- 超时时间 10 秒
错误处理:
try { const shortUrl = await SuperSDK.requestShortUrl('https://example.com/page'); // 使用短链} catch (error) { console.error('生成短链失败:', error.message); // 可能的错误:URL is required, 网络异常, appbridge not available}requestShortUrlWithHtml(html, baseUrl?)
Section titled “requestShortUrlWithHtml(html, baseUrl?)”通过 HTML 内容生成短链。访问生成的短链时直接渲染 HTML 页面,不做 302 跳转。适用于生成动态分享页面、活动海报等场景。
// 使用默认前缀const shortUrl = await SuperSDK.requestShortUrlWithHtml('<html><body><h1>Hello World</h1></body></html>');console.log(shortUrl);// "https://s.supersdk.com/XyZ789"
// 使用自定义前缀const shortUrl2 = await SuperSDK.requestShortUrlWithHtml('<h1>活动页面</h1>', 'https://s.a.com/');console.log(shortUrl2);// "https://s.a.com/XyZ789"参数说明:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| html | string | 是 | HTML 内容(完整文档或片段) |
| baseUrl | string | 否 | 自定义短链前缀,如 https://s.a.com/。不传使用默认值 |
返回值: Promise<string> - 短链字符串
特性:
- 每次调用生成新短链(不做幂等去重)
- 短链永久有效
- HTML 内容大小限制 1MB
- 超时时间 10 秒
错误处理:
try { const shortUrl = await SuperSDK.requestShortUrlWithHtml('<h1>活动页面</h1><p>活动详情...</p>'); // 使用短链分享} catch (error) { console.error('生成短链失败:', error.message); // 可能的错误:HTML content is required, 内容超过大小限制, 网络异常}