分享链接防微信封
This commit is contained in:
parent
c5af23a155
commit
c5dbb6794c
app/zone/share/[user_id]
|
@ -10,8 +10,26 @@ export default function Share({ params }) {
|
|||
//获取页面数据、生成二维码
|
||||
const [data, setData] = useState({});
|
||||
const [qrcodeUrl, setQrcodeUrl] = useState("");
|
||||
const [shareWebUrl, setShareWebUrl] = useState("https://tiefen.fun");
|
||||
const [isFetching, setIsFetching] = useState(true);
|
||||
|
||||
function generateRandomString(length = 10) {
|
||||
const characters =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
let result = "";
|
||||
for (let i = 0; i < length; i++) {
|
||||
result += characters.charAt(
|
||||
Math.floor(Math.random() * characters.length)
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
function getRandomUrl(urls) {
|
||||
return urls[Math.floor(Math.random() * urls.length)];
|
||||
}
|
||||
|
||||
const getData = async () => {
|
||||
try {
|
||||
const base = baseRequest();
|
||||
|
@ -40,9 +58,28 @@ export default function Share({ params }) {
|
|||
return;
|
||||
}
|
||||
setData(detailData.data.streamer_ext);
|
||||
|
||||
const urlsResponse = await fetch(`/api/config/cold_config`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({ ...base }),
|
||||
});
|
||||
const urlsData = await urlsResponse.json();
|
||||
if (urlsData.ret === -1) {
|
||||
Toast.show({
|
||||
content: urlsData.msg,
|
||||
});
|
||||
return;
|
||||
}
|
||||
const randomUrl = getRandomUrl(urlsData.data.share_redirect_urls);
|
||||
setShareWebUrl(randomUrl);
|
||||
const randomStr = generateRandomString();
|
||||
|
||||
var QRCode = require("qrcode");
|
||||
QRCode.toDataURL(
|
||||
`https://tiefen.fun/zone/${params.user_id}`,
|
||||
`${randomUrl}/zone/${params.user_id}/${randomStr}`,
|
||||
function (err, url) {
|
||||
setQrcodeUrl(url);
|
||||
}
|
||||
|
@ -153,10 +190,11 @@ export default function Share({ params }) {
|
|||
|
||||
//复制链接
|
||||
const copyUrl = () => {
|
||||
const randomStr = generateRandomString();
|
||||
window.ReactNativeWebView.postMessage(
|
||||
JSON.stringify({
|
||||
type: "COPY_URL",
|
||||
data: `https://tiefen.fun/zone/${params.user_id}`,
|
||||
data: `${shareWebUrl}/zone/${params.user_id}/${randomStr}`,
|
||||
})
|
||||
);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue