跳到主要内容

其他云端能力

$w.cloud.getTempFileURL

$w.cloud.getTempFileURL(params: string | string[]): Promise<string | string[]>

功能描述

获取云存储文件的临时访问链接, 即将 cloud://xxxx 协议的私有地址转换为 http 协议的正常地址

注意: cloud://xxx 协议地址错误或者无访问权限等, 该方法将不会返回地址

入参

入参可以是字符串或字符串数组。值为临时访问链接。具体见示例

出参

返回转换后的 http 地址。

入参为字符串,返回值也是字符串;

入参为数组,返回值是对象:{key: value}。key 为入参 cloud://,value 为对应转换值

具体见示例

示例

// 入参为字符串,返回值是字符串
$w.cloud
.getTempFileURL(
"cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001714-162653863412dd.jpg"
)
.then((url) => console.log("请求结果", url));
// 请求结果
// https://6c4f-lowcode-9gu72kpiac8de2d6-1252394733.tcb.qcloud.la/-预约-press@2x.png_1629354746149.png

// 入参为数组,返回值是数组
$w.cloud
.getTempFileURL([
"cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001714-162653863412dd.jpg",
"cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001935-16159115757f04.jpg",
])
.then((res) => {
console.log("请求结果", res);
});

// 请求结果
// {
// 'cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001714-162653863412dd.jpg': 'https://6c4f-lowcode-9gu72kpiac8de2d6-1252394733.tcb.qcloud.la/-预约-press@2x.png_1629354746149.png',
// 'cloud://tcb-demo-10cf5b.7463-tcb-demo-10cf5b-1302484483/images/pic_netbian_com/001935-16159115757f04.jpg': 'https://6c5f-lowcode-9gu72kpiac8de2d6-1252394733.tcb.qcloud.la/-预约-press@2x.png_1629354767798.png'
// }

$w.cloud.getCloudInstance

$w.cloud.getCloudInstance(): Promise<CloudInstance>

功能描述

返回云开发 web-sdk 初始化后的实例(无需关心 tcb 环境信息及认证登录的处理), 即 tcb.init 后返回的对象, 可用该对象直接调用 tcb 的各种能力

云开发 web-sdk 的详细用法可参考 web-sdk 文档

入参

出参

Promise<CloudInstance>

示例

$w.cloud.getCloudInstance().then((app) => {
// 调用云函数
app
.callFunction({
name: "test",
data: { a: 1 },
})
.then((res) => {
const result = res.result; //云函数执行结果
});
});

$w.cloud.callFunction

调用云开发的云函数, 与 $w.cloud.getCloudInstance 示例中的效果大体一致.

(params: ICallFunctionParams, parseOptions?: IParseOptions) => Promise<any>

入参

ICallFunctionParams 调用云函数的参数

属性类型默认值必填说明
namestringTCB 云函数名称
dataany云函数接收的参数,根据自己创建的云函数入参而定

IParseOptions 解析云开发云函数调用结果配置

属性类型默认值必填说明
unwrapResultboolean解析 云开发云函数的通用 response 包装。为 true, 则返回 res.result, 此时会丢失 res.requestId 信息
parseBusinessInfoboolean解析业务信息,需配合 unwrapResult 使用。为 true 时, res.result.code 非 0 抛出错误, 为 0 则返回 res.result.data

出参

依据用户自己定义的云函数返回而定

示例

$w.cloud
.callFunction({
name: "test",
data: { a: 1 },
})
.then((res) => {
const result = res; //云函数执行结果
});

$w.cloud.getUrlWithOpenidToken

$w.cloud.getUrlWithOpenidToken(src: string): Promise<string>

功能描述

在登录认证源设置中,h5 开启"微信小程序 OPENID 登录"后,使用此函数可以返回带有微信小程序授权登录 token 参数的 h5 跳转链接,可以用于微信小程序 webview 中的 h5 页面 openid 静默授权登录

入参

属性类型默认值必填说明
srcstring微信小程序 webview 跳转地址

出参

Promise<string>

示例

$w.cloud.getUrlWithOpenidToken(src).then((url) => {
const result = url; // 带有微信小程序授权登录token参数的h5跳转链接
});