wx.openOfficialAccountArticle(Object object)

基础库 3.4.8 开始支持,低版本需做兼容处理。

以 Promise 风格 调用:不支持

微信小程序插件:支持,需要微信小程序基础库版本不低于 3.15.1

微信 鸿蒙 OS 版:支持

功能描述

通过微信小程序打开任意公众号文章(不包括临时链接等异常状态下的公众号文章),必须有点击行为才能调用成功。

参数

Object object

属性 类型 默认值 必填 说明
url string 需要打开的公众号地址
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

object.success 回调函数

参数
Object res
属性 类型 说明
cancel boolean 为 true 时,表示用户点击了取消(用于 Android 系统区分点击蒙层关闭还是点击取消按钮关闭)
confirm boolean 为 true 时,表示用户点击了确定按钮

object.fail 回调函数

参数
Object err
属性 类型 说明
errMsg string 错误信息
errCode number 错误码

示例代码

  wx.openOfficialAccountArticle({
         url:'', // 此处填写公众号文章连接
         success: res => {
         },
         fail: res => {
         }
     })

wx.openOfficialAccountChat(Object object)

基础库 3.10.0 开始支持,低版本需做兼容处理。

以 Promise 风格 调用:不支持

微信小程序插件:不支持

功能描述

通过微信小程序打开公众号会话界面

参数

Object object

属性 类型 默认值 必填 说明
username string 需要打开的公众号的微信号
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

  wx.openOfficialAccountChat({
         username: '', // 此处填写公众号的微信号
         success: res => {
         },
         fail: res => {
         }
     })

Tips

  1. 跳转的公众号需与微信小程序为同主体或关联主体
  2. 如果用户没有关注则进行回退,跳转到公众号主页

wx.openOfficialAccountProfile(Object object)

基础库 3.7.10 开始支持,低版本需做兼容处理。

以 Promise 风格 调用:不支持

微信小程序插件:支持,需要微信小程序基础库版本不低于 3.11.2

微信 鸿蒙 OS 版:支持

功能描述

通过微信小程序打开公众号主页

参数

Object object

属性 类型 默认值 必填 说明
username string 需要打开的公众号的原始 ID
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

示例代码

  wx.openOfficialAccountProfile({
         username: '', // 此处填写公众号的原始 ID
         success: res => {
         },
         fail: res => {
         }
     })

Tips

  1. 跳转的公众号需与微信小程序为同主体或关联主体

wx.restartMiniProgram(Object object)

基础库 3.0.1 开始支持,低版本需做兼容处理。

以 Promise 风格 调用:不支持

微信小程序插件:不支持

微信 鸿蒙 OS 版:支持

功能描述

重启当前微信小程序

参数

Object object

属性 类型 默认值 必填 说明
path string 打开的页面路径,path 中 ? 后面的部分会成为 query
success function 接口调用成功的回调函数
fail function 接口调用失败的回调函数
complete function 接口调用结束的回调函数(调用成功、失败都会执行)

router.addRouteBuilder(string routeType, function routeBuilder)

微信小程序插件:不支持

相关文档: 自定义路由

功能描述

添加自定义路由配置

参数

string routeType

路由类型

function routeBuilder

路由动画定义函数

自定义路由示例

在开发者工具中预览效果

// 定义自定义效果,从右侧推入
const slideRouteBuilder = (customRouteContext) => {
  const { primaryAnimation } = customRouteContext
  const handlePrimaryAnimation = () => {
    'worklet'
    const transX = windowWidth * (1 - primaryAnimation.value)
       return {
           transform: `translateX(${transX}px)`,
       }
  }
  return {
    handlePrimaryAnimation
  }
}

wx.router.addRouteBuilder('slide', slideRouteBuilder)

// 使用自定义路由
wx.navigateTo({
  url: 'xxx',
  routeType: 'slide'
})

wx.router

基础库 2.29.2 开始支持,低版本需做兼容处理。

相关文档: 自定义路由

router 对象,可以通过 wx.router 获取。

方法

router.addRouteBuilder(string routeType, CustomRouteBuilder routeBuilder)

添加自定义路由配置

router.removeRouteBuilder(string routeType)

移除自定义路由配置

router.getRouteContext(Object this)

获取页面对应的自定义路由上下文对象