This commit is contained in:
hackrobot
2024-04-11 09:33:44 +08:00
parent 7a493f8320
commit 6af9642ceb

View File

@@ -53,43 +53,43 @@ const Index = () => {
wxaccount: null, wxaccount: null,
}); });
// // 获取用户标识符
// useEffect(() => {
// // 获取路由参数
// const params = Taro.getCurrentInstance().router.params;
// console.log("params", params);
// let localwxid = window.localStorage.getItem("wxid");
// let localh5openid = window.localStorage.getItem("h5openid");
// 获取用户标识符 // if (
useEffect(() => { // params?.wxid &&
// 获取路由参数 // (!localh5openid ||
const params = Taro.getCurrentInstance().router.params; // localh5openid == "undefined" ||
console.log("params", params); // localh5openid == "null")
let localwxid = window.localStorage.getItem("wxid"); // ) {
let localh5openid = window.localStorage.getItem("h5openid"); // // 本地存储
// window.localStorage.setItem("wxid", params?.wxid ?? "");
if (params?.wxid || localwxid) { // // alert(params?.wxid);
// 本地存储 // setwxid(params?.wxid);
window.localStorage.setItem("wxid", params?.wxid ?? ""); // getopenId();
// alert(params?.wxid); // }
setwxid(params?.wxid); // }, []);
if (
!localh5openid ||
localh5openid == "undefined" ||
localh5openid == "null"
) {
getopenId();
} else {
h5openidUser();
}
}
}, []);
const onBridgeReady = () => { const onBridgeReady = () => {
WeixinJSBridge.call("hideOptionMenu"); WeixinJSBridge.call("hideOptionMenu");
}; };
useEffect(()=>{
getopenId()
},[])
const h5openidUser = () => { const h5openidUser = () => {
try { try {
const params = Taro.getCurrentInstance().router.params; const params = Taro.getCurrentInstance().router.params;
let hashopenid = window.localStorage.getItem("h5openid"); let hashopenid = window.localStorage.getItem("h5openid");
let localwxid = window.localStorage.getItem("wxid"); let localwxid = window.localStorage.getItem("wxid");
alert ("hashopenid",hashopenid) alert("hashopenid", hashopenid);
alert ("localwxid",localwxid) alert("localwxid", localwxid);
//发起网络请求 //发起网络请求
Taro.request({ Taro.request({
@@ -136,10 +136,24 @@ const Index = () => {
// 查询用户信息 // 查询用户信息
h5openidUser(); h5openidUser();
} else { } else {
let nowUrl = window.location.href; // 获取路由参数
// alert(nowUrl); const params = Taro.getCurrentInstance().router.params;
let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`; console.log("params", params);
window.location.href = payUrl;
if (params?.wxid) {
// 本地存储
window.localStorage.setItem("wxid", params?.wxid ?? "");
// alert(params?.wxid);
setwxid(params?.wxid);
let nowUrl = window.location.href;
// alert(nowUrl);
let payUrl = `https://payjs.cn/api/openid?mchid=1561724891&callback_url=${nowUrl}`;
window.location.href = payUrl;
}else{
alert('没有wxid')
}
} }
}; };