You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

49 lines
1.1 KiB
JavaScript

import utils from "@/utils/utils.js";
import wxConfig from '@/utils/wxConfig.js';
export const h5init = () => {
const originalUrl = location.href
// 微信 h5 登录
if (utils.isInWeChatBrowser()) {
// 匹配链接中的参数部分和路径部分
const regex = /(https:\/\/[^\/]+\/[^?]+)\?code=([^&]+)&state=([^#]+)(#\/.*)?/;
const matches = originalUrl.match(regex);
if (matches) {
// 提取前缀、参数值和路径部分
const prefix = matches[1];
const code = matches[2];
const state = matches[3];
const path = matches[4] || ''; // 路径部分,如果不存在则为空字符串
// 构建新的链接
const newUrl = `${prefix}${path}?wxcode=${code}&state=${state}`;
location.href = newUrl
} else {
console.log('');
}
}
function getStoreID() {
const url = originalUrl;
var regex = /store_id=(\d+)/;
var match = url.match(regex);
if (match) {
var storeId = match[1];
if (storeId) {
uni.setStorageSync("storeId", storeId); // 存储storeId
}
}
}
getStoreID()
// JS SDK
if (utils.isInWeChatBrowser()) {
// wxConfig.init(['updateAppMessageShareData', 'updateTimelineShareData']);
}
}