- wx-open-launch-app 在真机上点击无效?
在微信开发者工具调试是可以提示打开应用弹窗,使用debug查看也是正确注册的了,在真机上也显示按钮了 就是点击后无反应: 真机debug显示 [图片][图片] 这是在开发者工具中显示的 [图片] 部分代码如下 import { signature } from '@/api/shop'; import '@/components/OpenAppButton/index.scss'; import { Button, View } from '@tarojs/components'; import Taro from '@tarojs/taro'; import { useEffect, useState } from 'react'; import wx from 'weixin-js-sdk-ts'; // 🧭 App 唤起相关链接配置 const httpUrl = location.origin || location.host; const universalLink = `${httpUrl}/home/consume`; // Universal Link / App Link const fallbackDownloadUrl = `${httpUrl}/download`; // 未安装 App 的跳转地址 // ✅ 判断设备 / 环境 const isWeChat = () => /micromessenger/i.test(navigator.userAgent); const OpenAppButton = () => { const [wxReady, setWxReady] = useState(false); useEffect(() => { if (!isWeChat()) return; const url = window.location.href.split('#')[0]; // ✳️ 请求后端接口,获取微信 JS-SDK 签名参数 signature(encodeURIComponent(url)) .then(res => { let data = res.data; wx.config({ debug: true, appId: data.appId, timestamp: data.timestamp, nonceStr: data.nonceStr, signature: data.signature, jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage'], openTagList: ['wx-open-launch-app'], }); wx.ready(() => { console.log('✅ wx.ready'); setWxReady(true); }); wx.error(err => { console.error('❌ wx.config error', err); }); }) .catch(err => { console.error('❌ 获取微信签名失败', err); }); }, []); // 非微信环境下打开 App const handleOpenApp = () => { if (isWeChat()) { Taro.showToast({ title: '请点击下方按钮打开 App', icon: 'none' }); return; } // 👇 尝试唤起 App,若失败则跳转 fallback 下载地址 const timer = setTimeout(() => { window.location.href = fallbackDownloadUrl; }, 2000); window.location.href = universalLink; // ⚠️ 清理定时器(理论上如果跳转成功,这行执行不到) window.addEventListener('visibilitychange', () => { if (document.hidden) clearTimeout(timer); }); }; return ( <View className="openAppButton"> {isWeChat() && wxReady ? ( // ✅ 微信卡片内生效:wx-open-launch-app <wx-open-launch-app appid="xxxxxxxx" extinfo={`productId=125`} id="launch-btn" onerror={() => Taro.showToast({ title: '打开失败,请使用浏览器', icon: 'none' })} onlaunch={() => console.log('📲 App 已唤起')} > <script type="text/wxtag-template" dangerouslySetInnerHTML={{ __html: ` <div class="btn">打开xx优选 App</div> `, }} /> </wx-open-launch-app> ) : ( // ✅ 普通浏览器点击按钮跳转 App <Button onClick={handleOpenApp}>打开xx优选</Button> )} </View> ); }; export default OpenAppButton;
06-27 - 微信公众号H5网页,单页面应用刷新后分享失效?
微信公众号H5网页,vue写的单页面应用。 问题1: ios在进入当前页时(可以分享),点击3个点里的刷新后(不能分享了,无法唤起分享),再点击一次刷新(第二次刷新就又可以了)。 问题2:Android进入当前页时(可以分享),点击3个点里的刷新后(可以分享,但是自定义分享的标题图片全部没有了)。 如何这些页面不点击刷新,均可正常分享。
2020-10-12