zj
2025-01-06 0e7b38c2b3af72ea2a7f8a2fcbaad4d78e2c1977
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.gear.customer.swx.controller;
 
import com.alibaba.fastjson2.JSONObject;
import com.gear.common.exception.CustomerException;
import com.gear.common.utils.http.HttpUtils;
import com.gear.common.vo.Result;
import com.gear.customer.swx.biz.SwxBizUserLogin;
import com.gear.customer.swx.utils.GoogleTokenDto;
import com.gear.customer.swx.vo.request.SendCodeVo;
import com.gear.customer.swx.vo.request.SwxUserLoginVo;
import com.gear.customer.swx.vo.request.SwxUserRegisterVo;
import com.gear.customer.swx.vo.response.SwxUserInfoVo;
import com.google.api.client.auth.oauth2.TokenResponse;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import org.apache.http.client.utils.HttpClientUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.http.converter.json.GsonFactoryBean;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import reactor.netty.http.client.HttpClient;
import reactor.netty.transport.ProxyProvider;
 
import java.io.IOException;
import java.security.GeneralSecurityException;
import java.util.Arrays;
import java.util.Collections;
 
@RestController
@RequestMapping("/swx/customer/login")
public class SwxUserLoginController {
    @Autowired
    private SwxBizUserLogin swxBizUserLogin;
 
    @PostMapping("/register")
    public Result<String> register(@RequestBody SwxUserRegisterVo swxUserRegisterVo){
        try {
            return Result.OK(swxBizUserLogin.register(swxUserRegisterVo));
        }catch (CustomerException e){
            return Result.error(e.getMessage());
        }
 
    }
 
 
    @GetMapping("/checkUserNameOrPhone")
    public Result<Boolean> checkUserNameOrPhone(@RequestParam("type")Integer type,@RequestParam("value")String value){
       return Result.OK(swxBizUserLogin.checkUserNameOrPhone(type,value));
    }
 
 
 
    @PostMapping("/login")
    public Result<?> login(@RequestBody SwxUserLoginVo vo){
        try {
            return Result.OK(swxBizUserLogin.login(vo));
        }catch (CustomerException e){
            return Result.error(e.getMessage());
        }
    }
 
    @PostMapping("/sendCode")
    public Result<String> sendCode(@RequestBody SendCodeVo vo){
        try {
            return Result.OK(swxBizUserLogin.sendCode(vo));
        }catch (CustomerException e){
            return Result.error(e.getMessage());
        } catch (IOException e) {
            return Result.error(e.getMessage());
        }
    }
 
 
    @PostMapping("/loginByGoogle")
    public Result<SwxUserInfoVo> loginByGoogle(@RequestBody SwxUserRegisterVo swxUserRegisterVo){
        try {
            return Result.OK(swxBizUserLogin.loginByGoogle(swxUserRegisterVo));
        }catch (CustomerException e){
            return Result.error(e.getMessage());
        }
    }
 
}