# 网络

# Api域:

const native = kreator.native;

# native.getCommonHeaders(options)

异步获取当前App中请求头信息

# 入参格式:

参数名 类型 描述
options NativeApiBaseRequest 基础入参类型

# 返回值:

全部请求头信息。为对象类型。详见: C端客户端通用Header字段 (opens new window)

native.getCommonHeaders({
  success(res){
    // 获取请求头信息...
  }
}).then(res=>{
  // 获取请求头信息...
})

# native.getCommonHeadersSync()

同步获取当前App中请求头信息

# 返回值

返回全部请求头信息。

const header = native.getCommonHeadersSync()

# native.isNetworkAvailableSync()

同步判断当前网络状况

# 返回值

boolean 网络连接状态,为false意为网络已断开。

const status = native.isNetworkAvailableSync();

# native.isNetworkAvailable(options)

异步判断当前网络状况。

参数名 类型 描述
options NativeApiBaseRequest 入参类型

# 返回值

boolean 网络连接状态,为false意为网络已断开。

native.isNetworkAvailableSync().then(res=>{
    console.warn(res)
});

# native.selectAndUploadPicture(options)

调用原生控件上传图片。
一次只能上传一张图片。

参数名 类型 描述
options SelectAndUploadPictureRequest 调用入参

# SelectAndUploadPictureRequest类型:

参数名 类型 描述
tips string 上传弹框的提示语

# 返回值:

string 返回图片上传到服务器上的httpUrl链接

native.selectAndUploadPicture({
    tips: '测试上传描述',
}).then((res) => {
    console.log(res);
});

# native.selectMediaAndUpload(options)

调用原生控件上传多媒体文件。
支持多选。

参数名 类型 描述
options SelectMediaAndUploadRequestInterface 调用入参

# SelectMediaAndUploadRequestInterface类型:

参数名 类型 描述
tips string 上传弹框的提示语
mediaType string 多媒体文件类型。
1,仅图片,2:仅视频 3:图片和视频

# 返回值:

SelectMediaAndUploadResponseInterface[] 多媒体文件上传至服务器上的链接与文件格式数组

# SelectMediaAndUploadResponseInterface类型:

参数名 类型 描述
type string 文件类型
url string 文件在服务器上的HTTP链接
native.selectMediaAndUpload({
    tips: '提示语,例如:可选3张图片,可选视频和图片',
    mediaType: '3',
}).then((res) => {
    console.log(res);
});

# getNetworkMonitorInfo(options)

获取网络检测结果文件

参数名 类型 描述
options NativeApiBaseRequest 调用入参

# 返回值

NetworkMonitorInfoResponse 日志文件相关信息

参数名 类型 描述
logUrl string 日志文件地址
zipPwd string 压缩包解压密码
native.getNetworkMonitorInfo().then((res) => {
    console.log(res);
});

# native.generateSignKeyForWeb(options)

根据请求functionId与入参生成请求接口的秘钥值。
通常当你与支付系统交互时为了避免接口被攻击,一定程度上这一步是必须的。

参数名 类型 描述
options NativeGenerateSignKeyRequestInterface 调用入参

# NativeGenerateSignKeyRequestInterface类型:

参数名 类型 描述
functionId string 接口functionId
params object 请求参数,如果没有可以不传

# 返回值:

string 秘钥字符串

native.generateSignKeyForWeb({
    functionId: ’test‘
}).then((res) => {
    console.log(res);
});

# native.getCurrentRequestPrefix()

获取当前环境的请求域名前缀。
该方法为同步方法。

# 返回值

string 域名环境前缀。
例如返回值为https://或https://test或https://dev。

const prefix = native.getCurrentRequestPrefix()

# native.getCurrentLocationHref()

获取当前页面url。

# 返回值

string 当前页面url

const href = native.getCurrentLocationHref();