返回 AiToEarn
user.ts
1 /*
2 * @Author: nevin
3 * @Date: 2025-01-17 20:21:07
4 * @LastEditTime: 2025-03-03 14:13:26
5 * @LastEditors: nevin
6 * @Description: 用户
7 */
8 import http from './request';
9 import { IRefreshToken, IUserInfo, PhoneLoginParams } from '@/api/types/user-t';
10
11 export interface GzhLoginTyp {
12 phone: string;
13 token: string;
14 openId: string;
15 exp: number;
16 userInfo: IUserInfo;
17 status: -1 | 0 | 1; // 失败 登录中 登录成功
18 }
19
20 export const userApi = {
21 // 手机号验证码登录
22 phoneLogin(data: PhoneLoginParams) {
23 return http.post<IRefreshToken>('/user/login/code/phone', data, {
24 isToken: false,
25 });
26 },
27
28 // 获取用户信息
29 getUserInfo() {
30 return http.get<IUserInfo>('/user/mine');
31 },
32
33 // 更新用户信息
34 updateUserInfo(data: any) {
35 return http.put<IUserInfo>('/user/info/update', data);
36 },
37
38 // 更新用户自动赚钱配置
39 setUserEarnInfo(data: {
40 readonly status: 0 | 1,
41 readonly cycleInterval: number;
42 }) {
43 return http.put<IUserInfo>('/user/config/earn', data);
44 },
45
46 // token刷新
47 refreshToken() {
48 return http.post<IRefreshToken>('/user/token/refresh');
49 },
50
51 // 发送手机号code
52 getUserCode(data: { phone: string }) {
53 return http.post<string>('/user/code', data, {
54 isToken: false,
55 });
56 },
57
58 // 获取登录的二维码
59 getWxLoginQrcode(data: any) {
60 return http.get<{ ticket: string; key: string }>('/user/gzh/qrcode/get', {
61 isToken: false,
62 });
63 },
64
65 // 轮询登录
66 wxGzhQrcodelogin(data: { ticket: string; key: string }) {
67 return http.post<GzhLoginTyp>('/user/gzh/qrcode/login', data, {
68 isToken: false,
69 });
70 },
71
72 // 公众号手机号登录
73 phoneGzhLogin(data: PhoneLoginParams) {
74 return http.post<IRefreshToken>('/user/login/gzh/code/phone', data, {
75 isToken: false,
76 });
77 },
78
79 // 用户设置或绑定手机号
80 upUserPhone(data: { phone: string; code: string }) {
81 return http.put<string>('/user/updatePhone', data, {
82 isToken: true,
83 });
84 },
85
86 // 绑定手机号
87 bindPhone(data: { phone: string; code: string; userId: string }) {
88 return http.post('/api/user/bind-phone', data);
89 },
90
91 // 获取我的邀请码
92 getMinePopularizeCode() {
93 return http.get<string>('user/pop/code');
94 },
95 };
96
96 lines TYPESCRIPT