puzhibing
2023-05-18 53562814add61acfdc02d6b25dae6324f6fd5f92
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
package com.stylefeng.guns.modular.api;
 
import com.alibaba.fastjson.JSONObject;
import com.google.code.kaptcha.Constants;
import com.stylefeng.guns.core.common.constant.JwtConstants;
import com.stylefeng.guns.core.common.exception.InvalidKaptchaException;
import com.stylefeng.guns.core.support.HttpKit;
import com.stylefeng.guns.core.util.ToolUtil;
import com.stylefeng.guns.modular.system.model.UserInfo;
import com.stylefeng.guns.modular.system.service.IReportLossService;
import com.stylefeng.guns.modular.system.service.ISmsrecordService;
import com.stylefeng.guns.modular.system.service.IUserInfoService;
import com.stylefeng.guns.modular.system.service.IVerifiedService;
import com.stylefeng.guns.modular.system.util.*;
import com.stylefeng.guns.modular.system.warpper.LoginWarpper;
import com.stylefeng.guns.modular.system.warpper.UserInfoWarpper;
import com.stylefeng.guns.modular.system.warpper.UserInviteInfoWarpper;
import com.stylefeng.guns.modular.system.warpper.VerifiedWarpper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
 
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.util.*;
 
/**
 * 用户控制器
 */
@Api
@CrossOrigin
@RestController
@RequestMapping("")
public class UserInfoController {
 
    @Autowired
    private IUserInfoService userInfoService;
 
    @Autowired
    private IVerifiedService verifiedService;
 
    @Autowired
    private ISmsrecordService smsrecordService;
 
    @Autowired
    private RedisUtil redisUtil;
 
    @Autowired
    private IReportLossService reportLossService;
 
    @Value("${spring.mail.template-path}")
    private String templatePath;
 
 
 
 
    @ResponseBody
    @PostMapping("/base/isEnterEmergencyContact")
    @ApiOperation(value = "是否输入紧急联系人", tags = {"用户端-登录"}, notes = "")
    public ResultUtil isEnterEmergencyContact(){
        try {
            Integer type = userInfoService.getAppOpenInfo(2);
            Map<String,Object> map = new HashMap<>();
            map.put("isEnterEmergencyContact",type==1);
            return ResultUtil.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    /**
     * 获取短信验证码
     * @param phone
     * @return
     */
    @ResponseBody
    @PostMapping("/base/authentication")
    @ApiOperation(value = "实名认证", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "身份证号", name = "idCard", required = true, dataType = "String")
    })
    public ResultUtil authentication(String phone, String idCard){
        if(ToolUtil.isNotEmpty(phone)){
            try {
                //return ResultUtil.success(aLiApiUtil.authentication(phone,idCard));
                return ResultUtil.success(true);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
            }
        }else{
            return ResultUtil.paranErr();
        }
    }
 
 
 
    /**
     * 获取短信验证码
     * @param phone
     * @return
     */
    @ResponseBody
    @PostMapping("/base/queryCaptcha")
    @ApiOperation(value = "获取短信验证码", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "图片验证码", name = "kaptcha", required = true, dataType = "String"),
            @ApiImplicitParam(value = "场景类型(1=身份验证,2=登录确认,3=用户注册,4=修改密码)", name = "type", required = true, dataType = "String")
    })
    public ResultUtil queryCaptcha(HttpServletRequest request,String phone, Integer type,String kaptcha, Integer language){
        if(ToolUtil.isNotEmpty(phone)){
            try {
               /* HttpSession session = request.getSession();
                String code = (String)session.getAttribute(Constants.KAPTCHA_SESSION_KEY);*/
                String code = redisUtil.getValue(phone+"_Code");
                System.out.println("缓存中验证码为:"+code);
                if (ToolUtil.isEmpty(kaptcha) || !kaptcha.equalsIgnoreCase(code)) {
                    return ResultUtil.error(language == 1 ? "图形验证码错误" : language == 2 ? "The graphic verification code is incorrect" : "Code de vérification graphique incorrect");
                }
                return userInfoService.queryCaptcha(phone, type);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
            }
        }else{
            return ResultUtil.paranErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/base/queryCaptcha1")
    @ApiOperation(value = "获取短信验证码", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "场景类型(1=身份验证,2=登录确认,3=用户注册,4=修改密码)", name = "type", required = true, dataType = "String")
    })
    public ResultUtil queryCaptcha1(String phone, Integer type){
        if(ToolUtil.isNotEmpty(phone)){
            try {
                return userInfoService.queryCaptcha(phone, type);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
            }
        }else{
            return ResultUtil.paranErr();
        }
    }
 
 
 
 
 
    @ResponseBody
    @PostMapping("/base/sedEmail")
    @ApiOperation(value = "获取邮箱验证码【1.0】", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "邮箱地址", name = "email", required = true, dataType = "String")
    })
    public ResultUtil sedEmail(String email, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(ToolUtil.isEmpty(email)){
                return ResultUtil.error(language == 1 ? "邮箱不能为空" : language == 2 ? "The mailbox cannot be empty" : "L’email ne peut pas être vide");
            }
            Random random = new Random();
            StringBuffer sb = new StringBuffer();
            for(int i = 0; i < 4; i++){
                sb.append((int) (random.nextDouble() * 10));
            }
            String authCode = sb.toString();
            redisUtil.setStrValue(email, authCode, 5 * 60);
 
            UserInfo userInfo = userInfoService.selectById(uid);
            String nickName = "";
            if(null != userInfo){
                nickName = userInfo.getNickName();
            }
 
            if(ToolUtil.isNotEmpty(email)){
                String path = templatePath +  "user/mainbox.html";
                Document document = Jsoup.parse(new File(path), "UTF-8");
                if(1 == language){
                    document.getElementById("english").attr("style", "display: none;");
                    document.getElementById("french").attr("style", "display: none;");
                    Element user_chinese = document.getElementById("user_chinese");
                    user_chinese.text("您好 " + nickName + ",");
                    Element content_chinese = document.getElementById("content_chinese");
                    content_chinese.text(authCode);
                }
                if(2 == language){
                    document.getElementById("chinese").attr("style", "display: none;");
                    document.getElementById("french").attr("style", "display: none;");
                    Element user_chinese = document.getElementById("user_english");
                    user_chinese.text("Hello " + nickName + ",");
                    Element content_chinese = document.getElementById("content_english");
                    content_chinese.text(authCode);
                }
                if(3 == language){
                    document.getElementById("chinese").attr("style", "display: none;");
                    document.getElementById("english").attr("style", "display: none;");
                    Element user_french = document.getElementById("user_french");
                    user_french.text("Bonjour " + nickName + ",");
                    Element content_french = document.getElementById("content_french");
                    content_french.text(authCode);
                }
 
                EmailUtil.send(email, language == 1 ? "验证码" : language == 2 ? "Verification code" : "Code de vérification",  document.html());
            }
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
    /**
     * 手机验证码登录
     * @param phone
     * @param code
     * @param registIp
     * @return
     */
    @ResponseBody
    @PostMapping("/base/user/captchaLogin")
    @ApiOperation(value = "手机验证码登录", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"),
            @ApiImplicitParam(value = "ip地址", name = "registIp", required = false, dataType = "String"),
            @ApiImplicitParam(value = "纬度", name = "lat", required = false, dataType = "double"),
            @ApiImplicitParam(value = "经度", name = "lng", required = false, dataType = "double")
    })
    public ResultUtil<LoginWarpper> captchaLogin(String phone, String code, String registIp, Double lat, Double lng, Integer language){
        try {
            return userInfoService.captchaLogin(phone, code, registIp, lat, lng,null,null,null,language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    /**
     * 手机验证码登录
     * @param phone
     * @param code
     * @return
     */
    @ResponseBody
    @PostMapping("/base/user/captchaLogin_")
    @ApiOperation(value = "手机验证码登录", tags = {"分享专用"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "String"),
            @ApiImplicitParam(value = "分享的用户id", name = "uid", required = true, dataType = "int"),
            @ApiImplicitParam(value = "用户类型(1=用户,2=司机)", name = "type", required = true, dataType = "int"),
            @ApiImplicitParam(value = "注册类型(1=司机注册,2=用户注册)", name = "userType", required = true, dataType = "int")
    })
    public ResultUtil<LoginWarpper> captchaLogin_(String phone, String code, Integer uid, Integer type, Integer userType, Integer language){
        try {
            return userInfoService.captchaLogin(phone, code, uid, type, userType, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
 
    /**
     * 账号密码登录
     * @param phone
     * @param password
     * @return
     */
    @ResponseBody
    @PostMapping("/base/user/userLogin")
    @ApiOperation(value = "账号密码登录", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "登录密码", name = "password", required = true, dataType = "String")
    })
    public ResultUtil<LoginWarpper> userLogin(String phone, String password, Integer language){
        if(ToolUtil.isNotEmpty(phone) && ToolUtil.isNotEmpty(password)){
            try {
                return userInfoService.userLogin(phone, password, language);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
            }
        }else{
            return ResultUtil.paranErr();
        }
    }
 
 
    /**
     * 忘记密码
     * @param phone
     * @param code
     * @param password
     * @return
     */
    @ResponseBody
    @PostMapping("/base/user/forgetPassword")
    @ApiOperation(value = "忘记密码操作", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "手机号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "String"),
            @ApiImplicitParam(value = "新密码", name = "password", required = true, dataType = "String")
    })
    public ResultUtil forgetPassword(String phone, String code, String password, Integer language){
        if(ToolUtil.isNotEmpty(phone) && ToolUtil.isNotEmpty(code) && ToolUtil.isNotEmpty(password)){
            try {
                return userInfoService.forgetPassword(phone, code, password, language);
            }catch (Exception e){
                e.printStackTrace();
                return ResultUtil.runErr();
            }
        }else{
            return ResultUtil.paranErr();
        }
    }
 
 
    /**
     * 微信授权登录
     * @param type              登录端口(1:APP登录,2:小程序)
     * @param openid            微信openid
     * @param unionid           微信unionid
     * @param jscode            小程序登录时的jscode临时凭证
     * @param registIp          ip地址
     * @param registAreaCode    当前定位区县行政编号(6位)
     * @return
     */
    @ResponseBody
    @PostMapping("/base/user/wxLogin")
    @ApiOperation(value = "微信授权登录", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "登录端口(1:APP,2:小程序)", name = "type", required = true, dataType = "int"),
            @ApiImplicitParam(value = "微信openid(APP登录上传)", name = "openid", required = false, dataType = "String"),
            @ApiImplicitParam(value = "encryptedData", name = "encryptedData", required = false, dataType = "String"),
            @ApiImplicitParam(value = "iv", name = "iv", required = false, dataType = "String"),
            @ApiImplicitParam(value = "微信unionid(APP登录上传)", name = "unionid", required = false, dataType = "String"),
            @ApiImplicitParam(value = "微信jscode(小程序登录上传)", name = "jscode", required = false, dataType = "String"),
            @ApiImplicitParam(value = "ip地址", name = "registIp", required = false, dataType = "String"),
            @ApiImplicitParam(value = "当前定位区县行政编号", name = "registAreaCode", required = true, dataType = "String"),
            @ApiImplicitParam(value = "头像", name = "avatar", required = false, dataType = "String"),
            @ApiImplicitParam(value = "昵称", name = "nickName", required = false, dataType = "String"),
            @ApiImplicitParam(value = "登录端口-小程序传Applets", name = "loginType", required = false, dataType = "String"),
            @ApiImplicitParam(value = "分享的用户id", name = "uid", required = false, dataType = "int"),
            @ApiImplicitParam(value = "性别(1=男,2=女)", name = "sex", required = false, dataType = "int")
    })
    public ResultUtil<LoginWarpper> wxLogin(Integer uid,String encryptedData, String iv,Integer type, String openid, String unionid, String jscode, String registIp,
                                            String registAreaCode, Integer sex, String nickName, String avatar,String loginType, Integer language){
        try {
            return userInfoService.wxLogin(type, openid, unionid, jscode, registIp, registAreaCode, sex, nickName, avatar,loginType,encryptedData,iv,uid,language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    @ResponseBody
    @PostMapping("/base/user/wxIsLogin")
    @ApiOperation(value = "微信小程序是否登录", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "微信jscode(小程序登录上传)", name = "jscode", required = false, dataType = "String")
    })
    public ResultUtil<LoginWarpper> wxIsLogin( String jscode){
        try {
            return userInfoService.wxIsLogin(jscode);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/user/facebookLogin")
    @ApiOperation(value = "FaceBook授权登录【1.0】", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "FaceBook用户id", name = "id", required = true, dataType = "String"),
            @ApiImplicitParam(value = "FaceBook用户名称", name = "name", required = true, dataType = "String"),
            @ApiImplicitParam(value = "FaceBook绑定的email", name = "email", required = false, dataType = "String"),
            @ApiImplicitParam(value = "头像", name = "avatar", required = false, dataType = "String"),
            @ApiImplicitParam(value = "性别(1=男,2=女)", name = "sex", required = false, dataType = "int"),
            @ApiImplicitParam(value = "纬度", name = "lat", required = false, dataType = "double"),
            @ApiImplicitParam(value = "经度", name = "lng", required = false, dataType = "double"),
            @ApiImplicitParam(value = "分享的用户id", name = "uid", required = false, dataType = "int"),
    })
    public ResultUtil facebookLogin(String id, String name, String email, Double lat, Double lng, Integer uid, Integer language){
        try {
            return userInfoService.facebookLogin(id, name, email, lat, lng, uid, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
 
    /**
     * 设置电话号码
     * @param phone
     * @param code
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/bindingPhone")
    @ApiOperation(value = "设置电话号码", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(value = "验证码", name = "code", required = false, dataType = "String"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<LoginWarpper> bindingPhone(String phone, String code, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userInfoService.bindingPhone(uid, phone, code, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/user/bindingEmail")
    @ApiOperation(value = "设置邮箱地址【1.0】", tags = {"用户端-登录"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "绑定类型(1=注册账号绑定,2=个人中心绑定)", name = "type", required = true, dataType = "int"),
            @ApiImplicitParam(value = "邮箱地址", name = "email", required = true, dataType = "String"),
            @ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "String"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<LoginWarpper> bindingEmail(Integer type, String email, String code, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userInfoService.bindingEmail(uid, type, email, code, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 获取用户个人信息
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/queryUserInfo")
    @ApiOperation(value = "获取用户详情【1.0】", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<UserInfoWarpper> queryUserInfo(HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            Map<String, Object> map = userInfoService.queryUserInfo(uid);
            return ResultUtil.success(UserInfoWarpper.getUserInfoWarpper(map));
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 手机号码获取用户
     * @param phone
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/queryUser")
    @ApiOperation(value = "手机号码获取用户", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil<Object> queryUser(String phone){
        try {
            Map<String, Object> map = userInfoService.queryUser(phone);
            if(null != map){
                return ResultUtil.success(UserInfoWarpper.getUserInfoWarpper(map));
            }
            return ResultUtil.success(new JSONObject());
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 实名认证操作
     * @param verifiedWarpper
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/verified")
    @ApiOperation(value = "实名认证操作", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil verified(VerifiedWarpper verifiedWarpper, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return verifiedService.verified(VerifiedWarpper.getVerified(verifiedWarpper), uid);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 设置紧急联系人
     * @param name
     * @param phone
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/setUrgentUser")
    @ApiOperation(value = "设置紧急联系人", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "姓名,没有传空字符串", name = "name", required = true, dataType = "String"),
            @ApiImplicitParam(value = "电话号码,没有传空字符串", name = "phone", required = true, dataType = "String"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil setUrgentUser(String name, String phone, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            userInfoService.setUrgentUser(name, phone, uid);
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 用户充值余额
     * @param payType
     * @param money
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/depositBalance")
    @ApiOperation(value = "余额充值", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "支付方式(1=线上支付)", name = "payType", required = true, dataType = "int"),
            @ApiImplicitParam(value = "充值金额", name = "money", required = true, dataType = "double"),
            @ApiImplicitParam(value = "支付端(1=用户APP端,2=司机APP端,3=用户小程序端)", name = "type", required = false, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil depositBalance(Integer payType, Double money, Integer type, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userInfoService.depositBalance(payType, "user_" + uid, money, uid, type, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 修改手机号码
     * @param code
     * @param phone
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/updatePhone")
    @ApiOperation(value = "修改手机号码", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "验证码", name = "code", required = true, dataType = "string"),
            @ApiImplicitParam(value = "新手机号", name = "phone", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil updatePhone(String code, String phone, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userInfoService.updatePhone(code, phone, uid, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    @ResponseBody
    @PostMapping("/api/user/checkCaptcha")
    @ApiOperation(value = "验证短信验证码", tags = {"用户端-个人中心"}, notes = "1=正确,0=错误")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "电话号码", name = "phone", required = true, dataType = "string"),
            @ApiImplicitParam(value = "短信验证码", name = "code", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil checkCaptcha(String phone, String code, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            UserInfo userInfo = userInfoService.selectById(uid);
            smsrecordService.saveData(4, userInfo.getPhone(), code, "短信验证码【" + code + "】已发到您的手机,验证码将在5分钟后失效,请及时登录!");
            boolean b = userInfoService.checkCaptcha(phone, code);
            Map<String, Object> map = new HashMap<>();
            map.put("ok", b ? 1 : 0);
            return ResultUtil.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    /**
     * 修改登录密码
     * @param password
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/updatePassword")
    @ApiOperation(value = "修改登录密码", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "新密码", name = "password", required = true, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil updatePassword(String password, Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            return userInfoService.updatePass(password, uid, language);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 修改个人信息
     * @param avatar
     * @param nickname
     * @param sex
     * @param birthday
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/updateInfo")
    @ApiOperation(value = "修改个人信息", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "头像", name = "avatar", required = false, dataType = "string"),
            @ApiImplicitParam(value = "昵称", name = "nickname", required = false, dataType = "string"),
            @ApiImplicitParam(value = "性别(1=男,2=女)", name = "sex", required = false, dataType = "int"),
            @ApiImplicitParam(value = "生日(2020-06-15)", name = "birthday", required = false, dataType = "string"),
            @ApiImplicitParam(value = "邮箱", name = "email", required = false, dataType = "string"),
            @ApiImplicitParam(value = "姓氏", name = "lastName", required = false, dataType = "string"),
            @ApiImplicitParam(value = "名字", name = "firstName", required = false, dataType = "string"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil updateInfo(String avatar, String nickname, Integer sex, Date birthday, String email, String lastName, String firstName, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            userInfoService.updateInfo(avatar, nickname, sex, birthday, email, lastName, firstName, uid);
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/api/user/queryRealName")
    @ApiOperation(value = "获取实名认证的数据", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil queryRealName(HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            Map<String, Object> map = userInfoService.queryRealName(uid);
            return ResultUtil.success(null != map ? map : new HashMap<>());
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 后台调用禁用用户
     * @param uid
     * @return
     */
    @ResponseBody
    @PostMapping("/base/user/freeze")
    public ResultUtil freeze(Integer uid){
        try {
            UserInfo userInfo = userInfoService.selectById(uid);
            String value = redisUtil.getValue(userInfo.getPhone());
            redisUtil.remove(value);
            redisUtil.remove(userInfo.getPhone());
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    /**
     * 仿socket接口(单点登录)
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/comparisonToken")
    @ApiOperation(value = "单点登录", tags = {"用户端-仿socket接口"}, notes = "match=1(匹配),match=2(不匹配)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil comparisonToken(HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            String requestHeader = request.getHeader(JwtConstants.AUTH_HEADER);
            requestHeader = requestHeader.substring(requestHeader.indexOf(" ") + 1);
            String value = redisUtil.getValue("USER_" + uid);
            Map<String, Object> map = new HashMap<>();
            map.put("match", requestHeader.equals(value) ? 1 : 2);
            return ResultUtil.success(map);
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    /**
     * 注销账号
     * @param request
     * @return
     */
    @ResponseBody
    @PostMapping("/api/user/cancellation")
    @ApiOperation(value = "注销账号", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil cancellation(HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            UserInfo userInfo = userInfoService.selectById(uid);
            userInfo.setState(2);
            userInfoService.updateById(userInfo);
            //开始验证当前账号是否在别处登录
            String value = redisUtil.getValue("USER_" + uid);
            if(ToolUtil.isNotEmpty(value)){//将另外设备上的强迫下线
                //开始清除redis中无效的数据
                String key = redisUtil.getValue("USER_" + userInfo.getPhone());
                redisUtil.remove(key);//删除个人信息数据
                redisUtil.remove("USER_" + userInfo.getPhone());//删除后台冻结相关缓存
                redisUtil.remove("USER_" + uid);//清除存储的token
            }
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
    @ResponseBody
    @PostMapping("/api/user/getInviteList")
    @ApiOperation(value = "获取邀请司机/乘客列表", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "类型[1:乘客,2:司机]", name = "type", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页码,首页1", name = "pageNum", required = true, dataType = "int"),
            @ApiImplicitParam(value = "页条数", name = "size", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil getInviteList(Integer type,Integer pageNum, Integer size, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            List<Map<String,Object>> list = userInfoService.queryMyInviteList(type,uid, pageNum, size);
            return ResultUtil.success(UserInviteInfoWarpper.getDriverInviteInfoWarpper(list));
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
 
    @ResponseBody
    @PostMapping("/api/user/editLanguage")
    @ApiOperation(value = "修改多语言配置", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "1=中文,2=英文,3=法语", name = "language", required = true, dataType = "int"),
            @ApiImplicitParam(name = "Authorization", value = "Bearer +token", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....")
    })
    public ResultUtil editLanguage(Integer language, HttpServletRequest request){
        try {
            Integer uid = userInfoService.getUserIdFormRedis(request);
            if(null == uid){
                return ResultUtil.tokenErr();
            }
            UserInfo userInfo = userInfoService.selectById(uid);
            userInfo.setLanguage(language);
            userInfoService.updateById(userInfo);
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
 
 
    @ResponseBody
    @PostMapping("/base/user/addReportLoss")
    @ApiOperation(value = "提交报失", tags = {"用户端-个人中心"}, notes = "")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "订单类型(1=专车,2=出租车,3=跨城出行,4=同城小件物流,5=跨城小件物流)", name = "orderType", required = true, dataType = "int"),
            @ApiImplicitParam(value = "订单id", name = "orderId", required = true, dataType = "int"),
            @ApiImplicitParam(value = "提交内容", name = "remark", required = true, dataType = "int"),
            @ApiImplicitParam(value = "提交图片", name = "image", required = true, dataType = "int"),
    })
    public ResultUtil addReportLoss(Integer orderType, Integer orderId, String remark, String image){
        try {
            reportLossService.addReportLoss(orderType, orderId, remark, image);
            return ResultUtil.success();
        }catch (Exception e){
            e.printStackTrace();
            return ResultUtil.runErr();
        }
    }
}