feat: token改为本地缓存
All checks were successful
Egg CI/CD / build-image (push) Successful in 21s
Egg CI/CD / deploy (push) Successful in 18s

This commit is contained in:
zhaoyingbo 2024-03-05 08:21:43 +00:00
parent 36b602da61
commit 38342e15f3
2 changed files with 30 additions and 18 deletions

View File

@ -1,11 +1,14 @@
import pbClient from "../pbClient";
let token = "";
/**
* token
* @param {string} value token
*/
const update = async (value: string) => {
await pbClient.collection("config").update("ugel8f0cpk0rut6", { value });
token = value;
console.log("reset access token success", value);
};
@ -14,6 +17,7 @@ const update = async (value: string) => {
* @returns {string} token
*/
const get = async () => {
if (token) return token;
const { value } = await pbClient
.collection("config")
.getOne("ugel8f0cpk0rut6");

View File

@ -21,27 +21,35 @@ export const sendMsg = async (
Authorization: `Bearer ${tenant_access_token}`,
};
const body = { receive_id, msg_type, content };
const res = await fetch(URL, {
method: "POST",
headers: header,
body: JSON.stringify(body),
});
const data = (await res.json()) as any;
if (data.code !== 0) {
console.log("sendMsg error", data);
try {
const res = await fetch(URL, {
method: "POST",
headers: header,
body: JSON.stringify(body),
});
const data = (await res.json()) as any;
if (data.code !== 0) {
console.log("sendMsg error", data);
return {
code: data.code,
msg: data.msg,
};
}
console.log("sendMsg success", data);
return {
code: data.code,
msg: data.msg,
code: 0,
msg: "success",
data: {
message_id: data.data.message_id,
},
};
} catch (error) {
console.log("sendMsg error", error);
return {
code: 1,
msg: "fetch error",
};
}
console.log("sendMsg success", data);
return {
code: 0,
msg: "success",
data: {
message_id: data.data.message_id,
},
};
};
// sendMsg('user_id', 'liuke9', 'text', JSON.stringify({text: '这是测试消息,不要回复'}))