zhaoyingbo 9545670a51
All checks were successful
Egg Server CI/CD / build-image (push) Successful in 45s
Egg Server CI/CD / refresh-image (push) Successful in 12s
Egg Server CI/CD / fast-deploy (push) Successful in 2s
feat: 支持清洗历史数据
2024-10-15 01:20:21 +00:00

73 lines
1.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { LarkServer } from "../../types/larkServer"
import LarkBaseService from "./base"
class LarkUserService extends LarkBaseService {
/**
* 登录凭证校验
* @param code 登录凭证
* @returns
*/
async code2Login(code: string) {
const path = `/mina/v2/tokenLoginValidate`
return this.post<LarkServer.UserSessionRes>(path, { code })
}
/**
* 获取用户信息
* @param userId 用户ID
* @param userIdType 用户ID类型
* @returns
*/
async getOne(userId: string, userIdType: "open_id" | "user_id") {
const path = `/contact/v3/users/${userId}`
return this.get<LarkServer.UserInfoRes>(path, {
user_id_type: userIdType,
})
}
/**
* 批量获取用户信息
* @param userIds 用户ID数组
* @param userIdType 用户ID类型
* @returns
*/
async batchGet(
userIds: string[],
userIdType: "open_id" | "user_id" = "open_id"
) {
const path = `/contact/v3/users/batch`
// 如果user_id长度超出50需要分批请求,
const userCount = userIds.length
const maxLen = 50
const requestMap = Array.from(
{ length: Math.ceil(userCount / maxLen) },
(_, index) => {
const start = index * maxLen
const getParams = `${userIds
.slice(start, start + maxLen)
.map((id) => `user_ids=${id}`)
.join("&")}&user_id_type=${userIdType}`
return this.get<LarkServer.BatchUserInfoRes>(path, getParams)
}
)
const responses = await Promise.all(requestMap)
const items = responses.flatMap((res) => {
return res.data?.items || []
})
return {
code: 0,
data: {
items,
},
message: "success",
}
}
}
export default LarkUserService