Pu Zhibing
7 天以前 41d7465a87e2a52740936a5969c5b182e5eb09b3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.supersavedriving.user.modular.system.util;
 
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;
 
/**
 * 用户工具类
 * @author zhibing.pu
 * @Date 2025/8/4 15:45
 */
@Slf4j
public class AppUserUtil {
    
    private static String url = "http://127.0.0.1:8080/user-server";
    
    
    /**
     * 发送短信验证码
     * @param phone
     * @return
     * @throws Exception
     */
    public static String queryCaptcha(String phone) throws Exception{
        HttpRequest post = HttpUtil.createPost(url + "/base/queryCaptcha");
        post.form("phone", phone);
        HttpResponse execute = post.execute();
        if(200 != execute.getStatus()){
            log.error("打车系统-发送验证码失败:{}", execute.body());
            return null;
        }
        return execute.body();
    }
    
    /**
     * 验证短信验证码
     * @param phone
     * @param code
     * @return
     * @throws Exception
     */
    public static Boolean checkCaptcha(String phone, String code) throws Exception{
        HttpRequest post = HttpUtil.createPost(url + "/base/user/checkCaptcha");
        post.header("device", "driving");
        post.form("phone", phone);
        post.form("code", code);
        HttpResponse execute = post.execute();
        if(200 != execute.getStatus()){
            log.error("打车系统-验证短信验证码:{}", execute.body());
            return null;
        }
        return Boolean.valueOf(execute.body());
    }
    
    
    /**
     * 添加用户
     * @param phone
     * @return
     * @throws Exception
     */
    public static String addUser(String phone, String code, String areaCode) throws Exception{
        HttpRequest post = HttpUtil.createPost(url + "/base/user/addAppUser");
        post.form("phone", phone);
        post.form("code", code);
        post.form("areaCode", areaCode);
        HttpResponse execute = post.execute();
        if(200 != execute.getStatus()){
            log.error("打车系统-注册用户失败:{}", execute.body());
            return null;
        }
        return execute.body();
    }
}