学无先后,达者为师

网站首页 编程语言 正文

微信小程序 - requestSubscribeMessage:fail can only be invoked by user TAP gesture.

作者:王佳斌 更新时间: 2022-02-27 编程语言

前言

使用 wx.requestSubscribeMessage() API,调起客户端小程序订阅消息界面,一直报错:

requestSubscribeMessage:fail can only be invoked by user TAP gesture.
# requestSubscribeMessage:fail只能通过用户点击手势调用。

且无任何错误码,如下图所示:
在这里插入图片描述

解决方案

实际上,就是因为该 API 您放置在了 回调函数 中,放置在外部即可。

例如,我的错误代码示例,就是因为放在了回调函数中,如下代码所示:

// 我是因为需要调用接口,取到模板id,所以才套在了回调函数中。
$http.fly.get('index.php', data).then((res) => {
   // wx.requestSubscribeMessage({})
})

只要移到回调函数外即可,如下代码所示:

$http.fly.get('index.php', data).then((res) => {
   // ...
})

// 放在外部
wx.requestSubscribeMessage({
	// ...
})

原文链接:https://wangjiabin.blog.csdn.net/article/details/122929171

栏目分类
最近更新