"use client"; import React, { useState, useEffect } from "react"; import Image from "next/image"; import webviewBaseRequest from "@/utils/webviewBaseRequest"; export default function Weixin({ params }) { //生成二维码 const [qrcodeUrl, setQrcodeUrl] = useState(""); const [device, setDevice] = useState(0); const [isLoading, setIsLoading] = useState(true); useEffect(() => { var QRCode = require("qrcode"); QRCode.toDataURL( `https://tiefen.fun/pay/jsapi/${params.weixin}`, function (err, url) { setQrcodeUrl(url); } ); //确认设备类型 const base = webviewBaseRequest(); if (base?.b_dt === 1) setDevice(1); setIsLoading(false); }, []); //保存二维码 const saveQrcode = async () => { window.ReactNativeWebView.postMessage( JSON.stringify({ type: "SAVE_IMAGE", data: qrcodeUrl, }) ); }; //android打开微信,ios打开微信扫一扫,0:android,1:ios const openWechat = () => { if (device === 0) { window.open("weixin://", "_blank"); return; } window.open("weixin://scanqrcode", "_blank"); }; if (isLoading) { return ( ); } return ( 请保存二维码到相册后 打开微信扫码支付 支付成功后返回APP关闭页面即可 {device === 0 ? "① 点此保存二维码" : "点此保存二维码"} {device === 0 && ( {device === 0 ? "② 点此打开微信" : "② 点此打开微信扫一扫"} )} {qrcodeUrl && ( )} ); }
支付成功后返回APP关闭页面即可