@shencom/api
Version:
shencom api group
382 lines (319 loc) • 11.1 kB
text/typescript
import type { OneOf, Unfurl } from '@shencom/typing';
import { getInitializedApiConfig } from '../config';
import { Jsencrypt, unToken } from '../utils/utils';
type ResUserInfo = Unfurl<SC.User.RootInfo>;
export interface ResAdditionalUserInfo {
additionalInformation: ResUserInfo;
}
/** 获取sccode */
export const ApiGetScCode = () => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sc/auth/code`;
return http.get<{ code: string }>(api);
};
/** sccode 登录 */
export const ApiScCodeLogin = (code: string, headers?: Record<string, any>) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sc/auth/code/login`;
return http.get<ResUserInfo>(api, { code }, { headers: { Authorization: null, ...headers } });
};
type ReqPhoneAndPassword = Unfurl<{ phone: string; password: string }>;
export const ApiPhoneAndPasswordLogin = (
body: ReqPhoneAndPassword,
headers?: Record<string, any>,
) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/auth/phone-password/login`;
body.password = Jsencrypt(body.password);
return http.post<ResUserInfo>(api, body, {
headers: { Authorization: null, ...headers },
});
};
type ReqScOAuthSecuser = Unfurl<{
/** 应用ID */
appId: string;
/** 应用密钥 */
appSecret?: string;
/** 向量 */
iv?: string;
/** aesKey */
key?: string;
/** 跳转租户的 scid,若需要自动创建新用户时自动关联指定权限,才传此参数 */
scid?: string;
}>;
export const ApiScOAuthSecuser = (params: ReqScOAuthSecuser, headers?: Record<string, any>) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sc/auth/secuser`;
return http.post<ReqScOAuthSecuser>(api, params, headers);
};
type ReqScOAuthToken = Unfurl<{
/** 应用ID */
appid: string;
/** 随机值 */
content: string;
/** 签名 */
nonce: string;
/** 时间戳 */
signature: string;
/** 内容 */
timestamp: string;
}>;
export const ApiScOAuthLogin = (params: ReqScOAuthToken, headers?: Record<string, any>) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sc/auth/secuser/login`;
return http.get<ResUserInfo>(api, params, {
headers: { Authorization: null, ...headers },
});
};
/** refreshToken续期token */
export const ApiRefreshToken = (refreshToken: string, headers?: Record<string, any>) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/auth/token-user/refresh`;
return http.post<ResUserInfo>(
api,
{ refreshToken },
{ headers: { Authorization: null, ...headers } },
);
};
interface ImageCode {
/** 图形验证码 */
imageCode: string;
/** 图形验证码的校验码 */
uuid: string;
}
interface SmsCode {
/** 短信验证码 */
code: string;
}
type ReqPhoneOrUsernameAndPasswordAndCode = OneOf<ImageCode, SmsCode> & {
username: string;
password: string;
};
/**
* 租户端
* - 手机号 + 密码 + 验证码
* - 用户名 + 密码 + 验证码
* - 手机号 + 密码 + 图形验证码
* - 用户名 + 密码 + 图形验证码
*
* @description 短信验证需要使用有权限的接口发送
*/
export const ApiPhoneOrUsernameAndPasswordAndCodeLogin = (
body: ReqPhoneOrUsernameAndPasswordAndCode,
headers?: Record<string, any>,
) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sys/user/login`;
body.password = Jsencrypt(body.password);
return http.post<ResAdditionalUserInfo>(api, body, unToken(headers));
};
/**
* 平台端
* - 手机号 + 密码 + 验证码
* - 用户名 + 密码 + 验证码
* - 手机号 + 密码 + 图形验证码
* - 用户名 + 密码 + 图形验证码
*
* @description 短信验证需要使用平台端的接口发送
*/
export const ApiPhoneOrUsernameAndPasswordAndCodeLoginPlatform = (
body: ReqPhoneOrUsernameAndPasswordAndCode,
headers?: Record<string, any>,
) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-platform-uaa/sys/user/login`;
body.password = Jsencrypt(body.password);
return http.post<ResAdditionalUserInfo>(api, body, unToken(headers));
};
interface ResPhoneOrUsernameAndPassword {
/** 手机号 | 用户名 */
username: string;
/** 密码 */
password: string;
}
/**
* 手机号或用户名 + 密码登录
* - 手机号 + 密码
* - 用户名 + 密码
*/
export const ApiPhoneOrUsernameAndPasswordLogin = (
body: ResPhoneOrUsernameAndPassword,
headers?: Record<string, any>,
) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/user/login`;
if (body.password) body.password = Jsencrypt(body.password);
return http.post<ResAdditionalUserInfo>(api, body, unToken(headers));
};
/** 租户端-更新系统用户信息 */
export const ApiSysUpdateInfo = (
body: Unfurl<SC.User.UpdateSysInfo>,
headers: Record<string, any> = {},
) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sys/user/update`;
return http.post<SC.User.Info>(api, body, { headers });
};
/** 平台端-更新系统用户信息 */
export const ApiSysUpdateInfoPlatform = (
body: Unfurl<SC.User.UpdateSysInfo>,
headers: Record<string, any> = {},
) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-platform-uaa/platform/sys/user/update`;
return http.post<SC.User.Info>(api, body, { headers });
};
interface ReqPhoneAndCodeLoginOrRegister {
/** 手机号 */
phone: string;
/** 验证码 */
code: string;
}
/** 手机号验证码登录
* @description 未注册的手机号,会自动注册
*/
export const ApiPhoneAndCodeLoginOrRegister = (
body: ReqPhoneAndCodeLoginOrRegister,
headers: Record<string, any> = {},
) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/auth/registry-login/phone`;
return http.post<ResUserInfo>(api, body, unToken(headers));
};
interface ReqPhoneAndCodeLogin {
/** 手机号 */
phone: string;
/** 验证码 */
code: string;
}
/** 手机号验证码登录 */
export const ApiPhoneAndCodeLogin = (
body: ReqPhoneAndCodeLogin,
headers: Record<string, any> = {},
) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/mobile/user/login`;
return http.post<ResUserInfo>(api, body, unToken(headers));
};
/** 获取明文的当前系统用户信息 */
export const ApiGetPlaintextUserInfo = () => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sys/user/current`;
return http.get<SC.User.Info>(api);
};
interface ReqUserSysUpdate {
/** userId */
id: string;
/** 旧密码 */
oldPassword: string;
/** 新密码 */
password: string;
}
/** 租户端-系统用户自行更改密码 */
export const ApiUserSysUpdate = (body: ReqUserSysUpdate, headers: Record<string, any> = {}) => {
if (body.password) body.password = Jsencrypt(body.password);
if (body.oldPassword) body.oldPassword = Jsencrypt(body.oldPassword);
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sys/user/self/update/pwd`;
return http.post<boolean>(api, body, headers);
};
/** 平台端-系统用户自行更改密码 */
export const ApiUserSysUpdatePlatform = (
body: ReqUserSysUpdate,
headers: Record<string, any> = {},
) => {
if (body.password) body.password = Jsencrypt(body.password);
if (body.oldPassword) body.oldPassword = Jsencrypt(body.oldPassword);
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-platform-uaa/platform/sys/user/self/update/pwd`;
return http.post<boolean>(api, body, headers);
};
interface ReqResetPwd {
/** 手机号或用户名 */
param: string;
/** 验证码 */
code: string;
/** 新密码 */
password: string;
}
/** 租户端-通过手机号或用户名找回密码 */
export const ApiResetPwd = (body: ReqResetPwd, headers: Record<string, any> = {}) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sys/user/update/pwd`;
if (body.password) body.password = Jsencrypt(body.password);
return http.post<void>(api, body, unToken(headers));
};
/** 平台端-通过手机号或用户名找回密码 */
export const ApiResetPwdPlatform = (body: ReqResetPwd, headers: Record<string, any> = {}) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-platform-uaa/platform/sys/user/update/pwd`;
if (body.password) body.password = Jsencrypt(body.password);
return http.post<void>(api, body, unToken(headers));
};
export interface ResNeedChangePassword {
/** 是否需要修改密码 */
needChange: boolean;
/** 上次修改密码时间 */
lastChangePwdTime: string;
/** 1 为首次密码变更 2 为定期密码更新 */
changeType?: number;
/** 变更频率 */
frequencyOfPwdChanges?: number;
}
/** 是否需要修改密码 */
export const ApiNeedChangePwd = (headers: Record<string, any> = {}) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sys/user/need-change-pwd`;
return http.get<ResNeedChangePassword>(api, headers);
};
interface ReqNeedGraphic {
/** 手机号或用户名 */
username: string;
}
/**
* 判断当前租户发送短信是否需要图形验证
* @deprecated 获取验证码接口已经做了图形验证
* @return {boolean} 是否需要验证码
*/
export const ApiNeedGraphic = (body: ReqNeedGraphic, headers: Record<string, any> = {}) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sys/user/need/graphic`;
return http.post<boolean>(api, body, unToken(headers));
};
/** 手机号或用户名 */
type ReqValidateImage = OneOf<{ username?: string }, OneOf<{ param?: string }, { phone?: string }>>;
export interface ResValidateImage {
image: string;
}
/** 获取图形验证码 */
export const ApiValidateImage = (body: ReqValidateImage, headers: Record<string, any> = {}) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/validate/image`;
return http.get<ResValidateImage>(api, body, unToken(headers));
};
/** 登出 */
export const ApiLogOut = (headers: Record<string, any> = {}) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/user/logout`;
return http.post(api, headers);
};
interface ReqIlhLogin {
appid: string;
content: string;
nonce: string;
timestamp: string;
signature: string;
}
export interface ResIlhOauthLogin {
openid: string;
phoneNumber: string;
oAuth2AccessToken: SC.User.RootInfo;
tokenid: string;
creditableLevelOfAccount: string;
}
// i罗湖一级平台登录
export const ApiIlhOauthLogin = (body: ReqIlhLogin, headers: Record<string, any> = {}) => {
const { http, url } = getInitializedApiConfig();
const api = `${url}/service-uaa/sys/user/lh/one/level/login`;
return http.get<ResIlhOauthLogin>(api, body, unToken(headers));
};