feat: 使用get模拟batchGet
This commit is contained in:
parent
6c8b16a2af
commit
4bd0e26455
@ -27,7 +27,7 @@ const code2Login = async (code: string, isSeek = false) => {
|
||||
* @param user_id
|
||||
* @returns
|
||||
*/
|
||||
const get = async (user_id: string, isSeek = false) => {
|
||||
const get = async (user_id: string, user_id_type: string, isSeek = false) => {
|
||||
const URL = `https://open.f.mioffice.cn/open-apis/contact/v3/users/${user_id}`;
|
||||
const headers = isSeek
|
||||
? {
|
||||
@ -37,38 +37,62 @@ const get = async (user_id: string, isSeek = false) => {
|
||||
return larkNetTool.get<LarkServer.UserInfoRes>(
|
||||
URL,
|
||||
{
|
||||
user_id_type: "user_id",
|
||||
user_id_type,
|
||||
},
|
||||
headers
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* 批量获取用户信息
|
||||
* @param user_ids
|
||||
* @returns
|
||||
* 使用get接口模拟批量获取用户信息
|
||||
*/
|
||||
const batchGet = async (
|
||||
user_ids: string[],
|
||||
user_id_type: "open_id" | "user_id",
|
||||
isSeek = false
|
||||
) => {
|
||||
const URL = `https://open.f.mioffice.cn/open-apis/contact/v3/users/batch`;
|
||||
const headers = isSeek
|
||||
? {
|
||||
Authorization: `Bearer ${await db.tenantAccessToken.getSeek()}`,
|
||||
}
|
||||
: {};
|
||||
return larkNetTool.get<LarkServer.BatchUserInfoRes>(
|
||||
URL,
|
||||
{
|
||||
user_ids,
|
||||
user_id_type,
|
||||
const requestMap = user_ids.map((user_id) => {
|
||||
return get(user_id, user_id_type, isSeek);
|
||||
});
|
||||
const responses = await Promise.all(requestMap);
|
||||
const items = responses.map((res) => {
|
||||
return res.data.user;
|
||||
});
|
||||
return {
|
||||
code: 0,
|
||||
data: {
|
||||
items,
|
||||
},
|
||||
headers
|
||||
);
|
||||
msg: "success",
|
||||
};
|
||||
};
|
||||
|
||||
// /**
|
||||
// * 批量获取用户信息
|
||||
// * @param user_ids
|
||||
// * @returns
|
||||
// */
|
||||
// const batchGet = async (
|
||||
// user_ids: string[],
|
||||
// user_id_type: "open_id" | "user_id",
|
||||
// isSeek = false
|
||||
// ) => {
|
||||
// const URL = `https://open.f.mioffice.cn/open-apis/contact/v3/users/batch`;
|
||||
// const headers = isSeek
|
||||
// ? {
|
||||
// Authorization: `Bearer ${await db.tenantAccessToken.getSeek()}`,
|
||||
// }
|
||||
// : {};
|
||||
// return larkNetTool.get<LarkServer.BatchUserInfoRes>(
|
||||
// URL,
|
||||
// {
|
||||
// user_ids,
|
||||
// user_id_type,
|
||||
// },
|
||||
// headers
|
||||
// );
|
||||
// };
|
||||
|
||||
const user = {
|
||||
code2Login,
|
||||
batchGet,
|
||||
|
@ -1,11 +1,15 @@
|
||||
const res = await fetch("https://egg.imoaix.cn/micro_app/egg/batch_user", {
|
||||
const localUrl = "http://localhost:3000/micro_app/seek/batch_user";
|
||||
const prodUrl = "https://egg.imoaix.cn/micro_app/seek/batch_user";
|
||||
|
||||
const res = await fetch(localUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify({
|
||||
user_ids: ["libo12"],
|
||||
user_ids: ["libo12", "zhaoyingbo"],
|
||||
user_id_type: "user_id",
|
||||
}),
|
||||
});
|
||||
console.log(await res.json());
|
||||
|
||||
console.log(JSON.stringify(await res.json()));
|
||||
|
Loading…
x
Reference in New Issue
Block a user