# 数据预拉取和数据周期性更新

调试诊断

接口应在服务器端调用,不可在前端(小程序、网页、APP等)直接调用,具体可参考接口调用指南

接口英文名:getFetchdataSetting

  • 调用本接口可以获取数据预拉取和数据周期性更新配置、设置预拉取数据、设置周期性拉取数据。
  • 使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

# 1. 调用方式

# HTTPS 调用

POST https://api.weixin.qq.com/wxa/fetchdatasetting?access_token=ACCESS_TOKEN

# 云调用

  • 本接口不支持云调用

# 第三方调用

  • 本接口支持第三方平台代商家调用。

  • 该接口所属的权限集 id 为:18

  • 服务商获得其中之一权限集授权后,可通过使用 authorizer_access_token 代商家进行调用,具体可查看 第三方调用 说明文档。

# 2. 请求参数

# 查询参数 Query String parameters

参数名类型必填说明
access_tokenstring接口调用凭证,可使用 authorizer_access_token

# 请求体 Request Payload

参数名类型必填说明
actionstring可填"get"、“ set_pre_fetch”、"set_period_fetch"
is_pre_fetch_openboolean数据预拉取是否开启,action=set_pre_fetch时,必填
pre_fetch_typenumber数据来源,0: 开发者服务器;1:云函数。action=set_pre_fetch时,必填
pre_fetch_urlstring数据下载地址,当pre_fetch_type=0必填。 说明,1、需要将域名先添加到第三方平台的业务域名;2、然后将该域名添加到小程序业务域名;才可以成功设置
pre_envstring环境ID,当pre_fetch_type=1必填
pre_function_namestring函数名,当pre_fetch_type=1必填
is_period_fetch_openboolean周期性拉取数据是否开启,true开启,false关闭。action= set_period_fetch时,必填
period_fetch_typenumber数据来源,0: 开发者服务器;1:云函数。action= set_period_fetch时,必填
period_fetch_urlstring数据下载地址,当period_fetch_type=0必填; 1、需要将域名先添加到第三方平台的业务域名;2、然后将该域名添加到小程序业务域名;才可以成功设置
period_envstring环境ID,当period_fetch_type=1必填
period_function_namestring函数名,当period_fetch_type=1必填

# 3. 返回参数

# 返回体 Response Payload

参数名类型说明
errcodenumber返回码
errmsgstring错误信息
is_pre_fetch_openboolean数据预拉取是否开启
pre_fetch_typenumber数据来源,0: 开发者服务器;1:云函数
pre_fetch_urlstring数据下载地址,当pre_fetch_type=0有效
pre_envstring环境ID,当pre_fetch_type=1有效
pre_function_namestring函数名,当pre_fetch_type=1有效
is_period_fetch_openboolean数据周期性更新是否开启
period_fetch_typenumber0: 开发者服务器;1:云函数
period_fetch_urlstring数据下载地址当period_fetch_type=0有效
period_envstring环境ID,当period_fetch_type=1有效
period_function_namestring函数名,当period_fetch_type=1有效

# 4. 注意事项

  • 该接口有三个功能,通过action的值进行区分,请详细按照接口文档调用接口。
  • pre_fetch_url或者period_fetch_url的域名需要配置为小程序的业务域名

# 5. 代码示例

# 5.1 获取数据预拉取和数据周期性更新配置

请求示例

{
  "action": "get"
}

返回示例

{
  "errcode": 0,
  "errmsg": "ok",
  "is_pre_fetch_open": true,
  "pre_fetch_type": 1,
  "pre_env": "test-pfyol",
  "pre_function_name": "test_func",
  "is_period_fetch_open": true,
  "period_fetch_type": 0,
  "period_fetch_url": "https://111.qq.com"
}

# 5.2 设置预拉取数据

请求示例

{
  "action": "set_pre_fetch",
  "is_pre_fetch_open": true,
  "pre_fetch_type": 0,
  "pre_fetch_url": "https://fff.com"
}

返回示例

{
  "errcode": 0,
  "errmsg": "ok"
}

# 5.3 设置周期性拉取数据

请求示例

{
  "action": "set_period_fetch",
  "is_period_fetch_open": true,
  "period_fetch_type": 1,
  "period_env": "test-pfyol",
  "period_function_name": "login"
}

返回示例

{
  "errcode": 0,
  "errmsg": "ok"
}

# 6. 错误码

以下是本接口的错误码列表,其他错误码可参考 通用错误码;调用接口遇到报错,可使用官方提供的 API 诊断工具 辅助定位和分析问题。

错误码错误描述解决方案
-1system error系统繁忙,此时请开发者稍候再试
40166invalid weapp appid非小程序发起调用
9410013无效action无效action
9410016存在无效域名。具体原因见errmsg(可能有多种原因)。

# 7. 适用范围

本接口支持「第三方平台」账号类型代调用,权限集请参考「调用方式」部分。其他账号类型如无特殊说明,均不可调用。