1
zj
2026-03-10 6cdaf4889c27cad69071d49dfa494434ff27d826
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
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
package com.yami.trading.api.controller;
 
import cn.hutool.core.util.StrUtil;
import com.yami.trading.api.dto.UserDto;
import com.yami.trading.api.model.SetSafewordModel;
import com.yami.trading.api.service.UserCacheService;
import com.yami.trading.bean.model.HighLevelAuthRecord;
import com.yami.trading.bean.model.Log;
import com.yami.trading.bean.model.RealNameAuthRecord;
import com.yami.trading.bean.model.User;
import com.yami.trading.bean.model.UserRecom;
import com.yami.trading.bean.model.UserSimRelation;
import com.yami.trading.bean.model.UserSafewordApply;
import com.yami.trading.bean.syspara.domain.Syspara;
import com.yami.trading.common.constants.Constants;
import com.yami.trading.common.domain.Result;
import com.yami.trading.common.exception.BusinessException;
import com.yami.trading.common.exception.YamiShopBindException;
import com.yami.trading.common.util.DateUtils;
import com.yami.trading.common.util.GoogleAuthenticator;
import com.yami.trading.common.util.IPHelper;
import com.yami.trading.common.util.ImageVerificationCodeUtil;
import com.yami.trading.common.util.ImageVerificationEndecrypt;
import com.yami.trading.common.util.IpUtil;
import com.yami.trading.common.util.LockFilter;
import com.yami.trading.common.util.RegexUtil;
import com.yami.trading.common.util.StringUtils;
import com.yami.trading.common.util.Strings;
import com.yami.trading.common.util.UUIDGenerator;
import com.yami.trading.security.common.bo.UserInfoInTokenBO;
import com.yami.trading.security.common.enums.SysTypeEnum;
import com.yami.trading.security.common.manager.TokenStore;
import com.yami.trading.security.common.util.SecurityUtils;
import com.yami.trading.security.common.vo.TokenInfoVO;
import com.yami.trading.service.HighLevelAuthRecordService;
import com.yami.trading.service.IdentifyingCodeTimeWindowService;
import com.yami.trading.service.QRGenerateService;
import com.yami.trading.service.RealNameAuthRecordService;
import com.yami.trading.service.syspara.SysparaService;
import com.yami.trading.service.system.LogService;
import com.yami.trading.service.system.TipService;
import com.yami.trading.service.user.UserRecomService;
import com.yami.trading.service.user.UserSafewordApplyService;
import com.yami.trading.service.user.UserService;
import com.yami.trading.service.user.UserSimRelationService;
import com.yami.trading.service.WalletService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
@RestController
@CrossOrigin
@RequestMapping("api/user")
@Api(tags = "用户")
@Slf4j
public class ApiUserController {
    @Autowired
    UserCacheService userCacheService;
    @Autowired
    UserService userService;
    @Autowired
    PasswordEncoder passwordEncoder;
    @Autowired
    RealNameAuthRecordService realNameAuthRecordService;
    @Autowired
    UserSafewordApplyService userSafewordApplyService;
    @Autowired
    RedisTemplate<String, Object> redisTemplate;
    @Autowired
    TipService tipService;
    @Autowired
    IdentifyingCodeTimeWindowService identifyingCodeTimeWindowService;
    @Autowired
    SysparaService sysparaService;
    @Autowired
    UserRecomService userRecomService;
    @Autowired
    HighLevelAuthRecordService highLevelAuthRecordService;
    @Autowired
    TokenStore tokenStore;
    @Autowired
    UserSimRelationService userSimRelationService;
    @Autowired
    WalletService walletService;
    @Autowired
    LogService logService;
    @Autowired
    QRGenerateService qrGenerateService;
 
    /**
     * 用户名登录接口
     */
    @GetMapping("login")
    public Result login(String username, String password) {
        if (StringUtils.isEmptyString(username)) {
            throw new YamiShopBindException("用户名不能为空");
        }
        if (StringUtils.isEmptyString(password)) {
            throw new YamiShopBindException("登录密码不能为空");
        }
//        if (password.length() < 6 || password.length() > 12) {
//            throw new YamiShopBindException("登录密码必须6-12位");
//        }
        String ip = IPHelper.getIpAddr();
        if (!IpUtil.isCorrectIpRegular(ip)) {
            log.error("校验IP不合法,参数{}", ip);
            throw new YamiShopBindException("校验IP不合法");
        }
 
        Date now = new Date();
        // 黑名单限制
        Syspara syspara = sysparaService.find("blacklist_ip");
        String blackUsers = syspara.getSvalue();
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(blackUsers)) {
            String[] ips = blackUsers.split(",");
            if (Arrays.asList(ips).contains(ip.trim())) {
                throw new YamiShopBindException("当前用户在黑名单中");
            }
        }
 
        User secUser = userService.login(username, password);
        UserInfoInTokenBO userInfoInToken = new UserInfoInTokenBO();
        userInfoInToken.setUserId(secUser.getUserId());
        userInfoInToken.setSysType(SysTypeEnum.ORDINARY.value());
        userInfoInToken.setEnabled(secUser.getStatus() == 1);
        secUser.setUserLastip(IPHelper.getIpAddr());
        secUser.setUserLasttime(now);
        // 登录时清除主账户与模拟账户的旧 token(若有关联)
        tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), String.valueOf(secUser.getUserId()));
        String simUserId = userSimRelationService.getSimUserId(secUser.getUserId());
        if (simUserId != null) {
            tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), simUserId);
        }
 
        // 存储token返回vo
        TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
        tokenInfoVO.setToken(tokenInfoVO.getAccessToken());
        userService.online(secUser.getUserId());
        Map<String, Object> data = new HashMap<>();
        data.put("token", tokenInfoVO.getAccessToken());
        data.put("username", secUser.getUserName());
        data.put("usercode", secUser.getUserCode());
        data.put("accountType", secUser.getAccountType() != null ? secUser.getAccountType() : 0);
        data.put("mainUserId", userSimRelationService.getMainUserId(secUser.getUserId()));
        data.put("simUserId", simUserId);
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_SECURITY);
        log.setLog("用户登录,ip[" + IPHelper.getIpAddr() + "]");
        log.setUserId(secUser.getUserId());
        log.setUsername(username);
        logService.save(log);
        secUser.setUserLastip(IPHelper.getIpAddr());
        secUser.setUserLasttime(now);
        secUser.setUpdateTime(now);
 
        userService.updateById(secUser);
 
        return Result.succeed(data);
    }
 
    @GetMapping("switchAccount")
    @ApiOperation("切换主账户/模拟账户")
    public Result switchAccount() {
        String currentUserId = SecurityUtils.getUser().getUserId();
        User currentUser = userService.getById(currentUserId);
        if (currentUser == null) {
            throw new YamiShopBindException("用户不存在");
        }
        Integer accountType = currentUser.getAccountType() != null ? currentUser.getAccountType() : 0;
        String targetUserId;
        Integer targetAccountType;
        if (accountType == 1) {
            // 当前是模拟账户,切换到主账户
            UserSimRelation relation = userSimRelationService.findBySimUserId(currentUserId);
            if (relation == null) {
                throw new YamiShopBindException("未找到关联的主账户");
            }
            targetUserId = relation.getMainUserId();
            targetAccountType = 0;
        } else {
            // 当前是主账户,切换到模拟账户:没有则先创建,再切换
            String simId = userSimRelationService.getSimUserId(currentUserId);
            if (simId == null) {
                userService.createSimAccountIfAbsent(currentUserId);
                simId = userSimRelationService.getSimUserId(currentUserId);
            }
            if (simId == null) {
                throw new YamiShopBindException("创建模拟账户失败");
            }
            targetUserId = simId;
            targetAccountType = 1;
        }
        User targetUser = userService.getById(targetUserId);
        if (targetUser == null || targetUser.getStatus() != 1) {
            throw new YamiShopBindException("目标账户不可用");
        }
        tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), currentUserId);
        tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), targetUserId);
        UserInfoInTokenBO userInfoInToken = new UserInfoInTokenBO();
        userInfoInToken.setUserId(targetUserId);
        userInfoInToken.setSysType(SysTypeEnum.ORDINARY.value());
        userInfoInToken.setEnabled(targetUser.getStatus() == 1);
        TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
        tokenInfoVO.setToken(tokenInfoVO.getAccessToken());
        userService.online(targetUserId);
        Map<String, Object> data = new HashMap<>();
        data.put("token", tokenInfoVO.getAccessToken());
        data.put("userId", targetUserId);
        data.put("accountType", targetAccountType);
        data.put("username", targetUser.getUserName());
        data.put("usercode", targetUser.getUserCode());
        String mainId = userSimRelationService.getMainUserId(targetUserId);
        data.put("mainUserId", mainId);
        data.put("simUserId", targetAccountType == 0 ? userSimRelationService.getSimUserId(targetUserId) : targetUserId);
        return Result.succeed(data);
    }
 
    @PostMapping("resetSimFunds")
    @ApiOperation("重置模拟账户资金(仅模拟账户可用)")
    public Result resetSimFunds() {
        String userId = SecurityUtils.getUser().getUserId();
        User user = userService.getById(userId);
        if (user == null || user.getAccountType() == null || user.getAccountType() != 1) {
            throw new YamiShopBindException("仅模拟账户可重置资金");
        }
        double amount = 100000;
        Syspara virtualGift = sysparaService.find("virtual_register_gift_coin");
        if (virtualGift != null) {
            amount = virtualGift.getDouble();
        }
        walletService.resetSimWallet(userId, amount);
        Map<String, Object> data = new HashMap<>();
        data.put("message", "重置成功");
        data.put("balance", amount);
        return Result.succeed(data);
    }
 
    private String validateParam(String username, String verifcode, String password, String type) {
 
        if (StringUtils.isEmptyString(username)) {
            return "用户名不能为空";
        }
//        if (StringUtils.isEmptyString(verifcode)) {
//            return "验证码不能为空";
//        }
        if (StringUtils.isEmptyString(password)) {
            return "登录密码不能为空";
        }
        int min = 6;
        int max = 12;
        if (!RegexUtil.length(password, min, max)) {
            return "登陆密码长度不符合设定";
        }
//        if (!RegexUtil.isDigits(this.password)) {
//            // 只能输入数字
//            return "登陆密码不符合设定";
//        }
//        if (StringUtils.isEmptyString(this.usercode)) {
//            return "推荐码不能为空";
//        }
        if (StringUtils.isEmptyString(type) || !Arrays.asList("1", "2").contains(type)) {
            return "类型不能为空";
        }
        return null;
    }
 
    /**
     * 手机/邮箱注册接口
     */
    @RequestMapping("register")
    public Object register(String username, String password, String safeword, String verifcode, String usercode, String type) {
        // 注册类型:1/手机;2/邮箱;
        String error = this.validateParam(username, verifcode, password, type);
        if (!StringUtils.isNullOrEmpty(error)) {
            throw new YamiShopBindException(error);
        }
//        if (StringUtils.isEmptyString(safeword)) {
//            throw new YamiShopBindException("资金密码不能为空");
//        }
//        if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
//            throw new YamiShopBindException("资金密码不符合设定");
//        }
        userService.saveRegister(username, password, usercode, safeword, verifcode, type);
        User secUser = userService.findByUserName(username);
        Log log = new Log();
        log.setCategory(Constants.LOG_CATEGORY_SECURITY);
        log.setLog("用户注册,ip[" + IPHelper.getIpAddr() + "]");
        log.setUserId(secUser.getUserId());
        log.setUsername(username);
        logService.save(log);
 
        UserInfoInTokenBO userInfoInToken = new UserInfoInTokenBO();
        userInfoInToken.setUserId(secUser.getUserId());
        userInfoInToken.setSysType(SysTypeEnum.ORDINARY.value());
        userInfoInToken.setEnabled(secUser.getStatus() == 1);
        tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), String.valueOf(secUser.getUserId()));
        TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
        this.userService.online(secUser.getUserId());
        Map<String, Object> data = new HashMap<String, Object>();
        data.put("token", tokenInfoVO.getAccessToken());
        data.put("username", secUser.getUserName());
        data.put("usercode", secUser.getUserCode());
        secUser.setUserLastip(IPHelper.getIpAddr());
        secUser.setUserLastip(IPHelper.getIpAddr());
        secUser.setUserLasttime(new Date());
        userService.updateById(secUser);
        return Result.succeed(data);
    }
 
    /**
     * 设置资金密码(注册时)
     */
    @PostMapping("/setSafewordReg")
    @ApiOperation(value = "设置资金密码(注册时)")
    public Result setSafeword(@Valid SetSafewordModel model) {
        String safeword = model.getSafeword();
        if (StringUtils.isEmptyString(model.getSafeword())) {
            throw new YamiShopBindException("The fund password cannot be blank");
        }
        if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
            throw new YamiShopBindException("资金密码不符合设定");
        }
        userService.setSafeword(SecurityUtils.getUser().getUserId(), passwordEncoder.encode(model.getSafeword()));
        return Result.succeed(null);
    }
 
    /**
     * token获取验证方式
     */
    @PostMapping("getVerifTarget")
    @ApiOperation("token获取验证方式")
    public Result<?> getVerifTarget(HttpServletRequest request) {
        String verifcode_type = request.getParameter("verifcode_type");
        Map<String, Object> data = new HashMap<>();
        User user = userCacheService.currentUser();
        // verifcode_type未明确指定,返回所有的方式
        if (StringUtils.isEmptyString(verifcode_type) || !Arrays.asList("1", "2", "3").contains(verifcode_type)) {
            data.put("phone", StringUtils.isEmptyString(user.getUserMobile()) || false == user.isUserMobileBind() ? "" : user.getUserMobile());
            data.put("phone_filled", StringUtils.isEmptyString(user.getUserMobile()) ? "" : user.getUserMobile());
            data.put("phone_authority", user.isUserMobileBind());
            data.put("email", StringUtils.isEmptyString(user.getUserMail()) || false == user.isMailBind() ? "" : user.getUserMail());
            data.put("email_filled", StringUtils.isEmptyString(user.getUserMail()) ? "" : user.getUserMail());
            data.put("email_authority", user.isMailBind());
            data.put("google_auth_secret", StringUtils.isEmptyString(user.getGoogleAuthSecret()) || false == user.isGoogleAuthBind() ? "" : user.getGoogleAuthSecret());
            data.put("google_auth_secret_filled", StringUtils.isEmptyString(user.getGoogleAuthSecret()) ? "" : user.getGoogleAuthSecret());
            data.put("google_auth_bind", user.isGoogleAuthBind());
        } else {
            // verifcode_type: 1/手机;2/邮箱;3/谷歌验证器;
            if ("1".equals(verifcode_type)) {
                data.put("phone", StringUtils.isEmptyString(user.getUserMobile()) || false == user.isUserMobileBind() ? "" : user.getUserMobile());
                data.put("phone_filled", StringUtils.isEmptyString(user.getUserMobile()) ? "" : user.getUserMobile());
                data.put("phone_authority", user.isUserMobileBind());
            } else if ("2".equals(verifcode_type)) {
                data.put("email", StringUtils.isEmptyString(user.getUserMail()) || false == user.isMailBind() ? "" : user.getUserMail());
                data.put("email_filled", StringUtils.isEmptyString(user.getUserMail()) ? "" : user.getUserMail());
                data.put("email_authority", user.isMailBind());
            } else if ("3".equals(verifcode_type)) {
                data.put("google_auth_secret", StringUtils.isEmptyString(user.getGoogleAuthSecret()) || false == user.isGoogleAuthBind() ? "" : user.getGoogleAuthSecret());
                data.put("google_auth_secret_filled", StringUtils.isEmptyString(user.getGoogleAuthSecret()) ? "" : user.getGoogleAuthSecret());
                data.put("google_auth_bind", user.isGoogleAuthBind());
            }
        }
 
        return Result.succeed(data);
    }
 
    @RequestMapping("getImageCode")
    public Result getImageCode() {
        Map<String, Object> data = new HashMap<String, Object>();
        String key = UUIDGenerator.getUUID();
        ImageVerificationCodeUtil iv = new ImageVerificationCodeUtil();
        data.put("code", iv.getBase64());
        data.put("key", key);
        redisTemplate.opsForValue().set(key, iv.getText());
        return Result.succeed(data);
    }
 
    /**
     * 退出登录
     */
    @RequestMapping("logout")
    public Result logout(HttpServletRequest request) {
        String accessToken = request.getHeader("token");
        String token = request.getParameter("token");
        if (StrUtil.isBlank(accessToken)) {
            accessToken = token;
        }
        if (StrUtil.isBlank(accessToken)) {
            return Result.succeed();
        }
        userService.logout(SecurityUtils.getUser().getUserId());
        // 删除该用户在该系统当前的token
        tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), String.valueOf(SecurityUtils.getUser().getUserId()));
        return Result.succeed();
    }
 
    /**
     * 重置登录密码
     */
    @PostMapping("resetPsw")
    public Object resetpsw(HttpServletRequest request) {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        String verifcode_type = request.getParameter("verifcode_type");
        String verifcode = request.getParameter("verifcode");
        if (StringUtils.isEmptyString(username)) {
            throw new YamiShopBindException("用户名不能为空");
        }
        if (StringUtils.isEmptyString(password)) {
            throw new YamiShopBindException("密码不能为空");
        }
        if (password.length() < 6 || password.length() > 12) {
            throw new YamiShopBindException("密码必须6-12位");
        }
        if (StringUtils.isEmptyString(verifcode_type)) {
            throw new YamiShopBindException("验证类型不能为空");
        }
        if (StringUtils.isEmptyString(verifcode)) {
            throw new YamiShopBindException("验证码不能为空");
        }
        User party = userService.findByUserName(username);
        if (null == party) {
            throw new YamiShopBindException("用户名不存在");
        }
        // 根据验证类型获取验证key verifcode_type: 1/手机;2/邮箱;3/谷歌验证器;
        String key = "";
        String errMsg = "";
        if ("1".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile();
            errMsg = "未绑定手机号";
        } else if ("2".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail();
            errMsg = "未绑定邮箱";
        } else if ("3".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret();
            errMsg = "未绑定谷歌验证器";
        }
        if (StringUtils.isEmptyString(key)) {
            throw new YamiShopBindException(errMsg);
        }
        // 验证
        boolean passed = false;
        if ("1".equals(verifcode_type) || "2".equals(verifcode_type)) {
            String authcode = this.identifyingCodeTimeWindowService.getAuthCode(key);
            if ((null != authcode) && (authcode.equals(verifcode))) {
                passed = true;
                this.identifyingCodeTimeWindowService.delAuthCode(key);
            }
        } else if ("3".equals(verifcode_type)) {
            GoogleAuthenticator ga = new GoogleAuthenticator();
            ga.setWindowSize(5);
            long t = System.currentTimeMillis();
            boolean flag = ga.check_code(party.getGoogleAuthSecret(), Long.valueOf(verifcode), t);
            if (flag) {
                passed = true;
            }
        }
        // 如果是演示用户,则不判断验证码
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if (!passed) {
                throw new YamiShopBindException("验证码不正确");
            }
        }
        party.setLoginPassword(passwordEncoder.encode(password));
        // 更新密码
        userService.updateById(party);
        return Result.succeed();
    }
 
    /**
     * 用户名获取验证方式
     */
    @RequestMapping("getUserNameVerifTarget")
    public Result<Map<String, Object>> getUserNameVerifTarget(String username, String verifcode_type) {
 
        Map<String, Object> data = new HashMap<>();
        if (StringUtils.isEmptyString(username)) {
            throw new YamiShopBindException("用户名参数为空");
        }
        User party = userService.findByUserName(username);
        if (null == party) {
            throw new YamiShopBindException("用户名不存在");
        }
        // verifcode_type未明确指定,返回所有的方式
        if (StringUtils.isEmptyString(verifcode_type) || !Arrays.asList("1", "2", "3").contains(verifcode_type)) {
            data.put("phone", StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile());
            data.put("phone_filled", StringUtils.isEmptyString(party.getUserMobile()) ? "" : party.getUserMobile());
            data.put("phone_authority", party.isUserMobileBind());
            data.put("email", StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail());
            data.put("email_filled", StringUtils.isEmptyString(party.getUserMail()) ? "" : party.getUserMail());
            data.put("email_authority", party.isMailBind());
            data.put("google_auth_secret", StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret());
            data.put("google_auth_secret_filled", StringUtils.isEmptyString(party.getGoogleAuthSecret()) ? "" : party.getGoogleAuthSecret());
            data.put("google_auth_bind", party.isGoogleAuthBind());
        } else {
            // verifcode_type: 1/手机;2/邮箱;3/谷歌验证器;
            if ("1".equals(verifcode_type)) {
                data.put("phone", StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile());
                data.put("phone_filled", StringUtils.isEmptyString(party.getUserMobile()) ? "" : party.getUserMobile());
                data.put("phone_authority", party.isUserMobileBind());
            } else if ("2".equals(verifcode_type)) {
                data.put("email", StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail());
                data.put("email_filled", StringUtils.isEmptyString(party.getUserMail()) ? "" : party.getUserMail());
                data.put("email_authority", party.isMailBind());
            } else if ("3".equals(verifcode_type)) {
                data.put("google_auth_secret", StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret());
                data.put("google_auth_secret_filled", StringUtils.isEmptyString(party.getGoogleAuthSecret()) ? "" : party.getGoogleAuthSecret());
                data.put("google_auth_bind", party.isGoogleAuthBind());
            }
        }
 
        return Result.succeed(data);
    }
 
    /**
     * 查看用户接口
     */
    @GetMapping("/getInfo")
    @ApiOperation(value = "查看用户信息")
    public Result<UserDto> getInfo(HttpServletRequest request) {
        String userId = SecurityUtils.getUser().getUserId();
        User user = userService.getById(userId);
        String token = request.getHeader("token");
        UserDto userDto = new UserDto();
        BeanUtils.copyProperties(user, userDto);
        userDto.setUsercode(user.getUserCode());
        userDto.setUsername(user.getUserName());
        userDto.setToken(token);
        userDto.setIdentityverif(user.isRealNameAuthority());
        userDto.setAdvancedverif(user.isHighlevelAuthority());
        userDto.setName(user.getRealName());
        RealNameAuthRecord realNameAuthRecord = realNameAuthRecordService.getByUserId(user.getUserId());
        if (realNameAuthRecord != null) {
            userDto.setNationality(realNameAuthRecord.getNationality());
            userDto.setKyc_status(realNameAuthRecord.getStatus());
        }
        HighLevelAuthRecord highLevelAuthRecord = highLevelAuthRecordService.findByUserId(userId);
        if (highLevelAuthRecord != null) {
            userDto.setKyc_high_level_status(highLevelAuthRecord.getStatus());
        }
        return Result.succeed(userDto);
    }
 
    /**
     * 获取个人信息
     */
    @RequestMapping("get")
    public Object get(HttpServletRequest request) {
 
        String loginPartyId = SecurityUtils.getCurrentUserId();
        User party = userService.getById(loginPartyId);
        RealNameAuthRecord kyc = realNameAuthRecordService.getByUserId(party.getUserId());
        HighLevelAuthRecord kycHighLevel = highLevelAuthRecordService.findByUserId(party.getUserId());
        Map<String, Object> map = new HashMap<String, Object>();
        // 十进制个位表示系统级别:1/新注册;2/邮箱谷歌手机其中有一个已验证;3/用户实名认证;4/用户高级认证;
        // 十进制十位表示自定义级别:对应在前端显示为如VIP1 VIP2等级、黄金 白银等级;
        // 如:级别11表示:新注册的前端显示为VIP1;
        map.put("user_level", (int) (party.getUserLevel() % 10));
        map.put("user_level_custom", (int) Math.floor(party.getUserLevel() / 10));
        map.put("credit_score", party.getCreditScore() != null ? party.getCreditScore() : 100);
        map.put("username", party.getUserName());
        map.put("userrole", party.getRoleName());
        map.put("usercode", party.getUserCode());
        map.put("phone", party.getUserMobile());
        map.put("phoneverif", party.isUserMobileBind());
        map.put("email", party.getUserMail());
        map.put("emailverif", party.isMailBind());
        map.put("google_auth_secret", party.getGoogleAuthSecret());
        map.put("googleverif", party.isGoogleAuthBind());
        map.put("identityverif", party.isRealNameAuthority());
        map.put("advancedverif", party.isHighlevelAuthority());
        map.put("lastlogintime", party.getUserLasttime());
        map.put("lastloginip", party.getUserLastip());
        // 实名认证通过返回真实姓名
        if (party.isRealNameAuthority()) {
            map.put("name", kyc != null ? kyc.getName() : party.getUserName());
        }
        if (null != kyc) {
            map.put("nationality", kyc.getNationality());
            map.put("kyc_status", kyc.getStatus());
        }
        if (null != kycHighLevel) {
            map.put("kyc_high_level_status", kycHighLevel.getStatus());
        }
        if (Constants.SECURITY_ROLE_TEST.equals(party.getRoleName())) {
            map.put("test", true);
        } else {
            // 关闭后,正式用户进入推广页面的时候,接口就不返回内容
            boolean member_promote_button = this.sysparaService.find("member_promote_button").getBoolean();
            if (Constants.SECURITY_ROLE_MEMBER.equals(party.getRoleName()) && !member_promote_button) {
                map.put("url", "");
                map.put("usercode_qr", "");
            } else {
                map.put("url", Constants.WEB_URL + "/register.html?usercode=" + party.getUserCode());
                // 生成二维码图片
                qrGenerateService.generate(party.getUserCode());
                map.put("usercode_qr", Constants.WEB_URL + "/public/showimg!showImg.action?imagePath=/qr/" + party.getUserCode() + ".png");
            }
        }
        UserRecom userRecom = this.userRecomService.findByPartyId(party.getUserId());
        if (null == userRecom || null == userRecom.getRecomUserId()) {
            map.put("usercode_parent", "");
        } else {
            User party_reco = userService.getById(userRecom.getRecomUserId());
            if (null == party_reco || null == party_reco.getUserCode() || StringUtils.isEmptyString(party_reco.getUserCode().toString())) {
                map.put("usercode_parent", "");
            } else {
                map.put("usercode_parent", party_reco.getUserCode());
            }
        }
        // 时间分隔点:新用户需要注册后填手机号和邀请码
        map.put("register_need_phone_usercode", false);
        String register_need_phone_usercode_time = this.sysparaService.find("register_need_phone_usercode_time").getSvalue();
        if (!StringUtils.isEmptyString(register_need_phone_usercode_time)) {
            // 结合盘:只有新用户需要注册后填手机号和邀请码
            Date dateFixed = DateUtils.toDate(register_need_phone_usercode_time, DateUtils.NORMAL_DATE_FORMAT);
            if (party.getCreateTime().getTime() > dateFixed.getTime()) {
                map.put("register_need_phone_usercode", true);
            } else {
                map.put("register_need_phone_usercode", false);
            }
        }
 
        // 承兑商类型:0不是承兑商/1后台承兑商/2用户承兑商
        map.put("c2c_user_type", party.getC2cUserType());
        return Result.succeed(map);
    }
 
    /**
     *
     */
    @ApiOperation("电话绑定")
    @PostMapping("savePhone")
    public Result save_phone(String phone, String verifcode,
                             String usercode) {
//            if (StringUtils.isEmptyString(phone) || !Strings.isNumber(phone) || phone.length() > 15) {
        if (StringUtils.isEmptyString(phone) || phone.length() > 20) {
            throw new YamiShopBindException("请填写正确的电话号码");
        }
        String loginPartyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(loginPartyId);
//        if (null != party.getUserMobile() && party.getUserMobile().equals(phone) && true == party.isUserMobileBind()) {
//            throw new YamiShopBindException("电话号码已绑定");
//        }
        User partyPhone = userService.findPartyByVerifiedPhone(phone);
        if (null != partyPhone && !partyPhone.getUserId().toString().equals(loginPartyId)) {
            throw new YamiShopBindException("电话号码已绑定其他用户");
        }
        String authcode = identifyingCodeTimeWindowService.getAuthCode(phone);
        String bind_phone_email_ver = this.sysparaService.find("bind_phone_email_ver").getSvalue();
        String bind_usercode = this.sysparaService.find("bind_usercode").getSvalue();
        // 如果是演示用户,则不判断验证码
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if ("1".contentEquals(bind_phone_email_ver)) {
                if (StringUtils.isEmptyString(verifcode)) {
                    throw new YamiShopBindException("请填写正确的验证码");
                }
                if ((null == authcode) || (!authcode.equals(verifcode))) {
                    throw new YamiShopBindException("验证码不正确");
                }
            }
            if ("1".contentEquals(bind_usercode)) {
                if (StringUtils.isEmptyString(usercode)) {
                    throw new YamiShopBindException("请输入推荐码");
                }
                User party_reco = userService.findUserByUserCode(usercode);
                if (null == party_reco || party_reco.getStatus() != 1) {
                    throw new YamiShopBindException("推荐人无权限推荐");
                }
                UserRecom userRecom = this.userRecomService.findByPartyId(party.getUserId());
                if (null == userRecom) {
                    userRecom = new UserRecom();
                    userRecom.setUserId(party.getUserId());
                    userRecom.setRecomUserId(party_reco.getUserId());
                    this.userRecomService.save(userRecom);
                } else {
//                        this.userRecomService.update(party.getId(), party_reco.getId());
                }
            }
        }
        // 电话绑定成功
        party.setUserMobile(phone);
        party.setUserMobileBind(true);
        // 获取用户系统等级:1/新注册;2/邮箱谷歌手机其中有一个已验证;3/用户实名认证; 4/用户高级认证;
        int userLevelSystem = userService.getUserLevelByAuth(party);
        // 十进制个位表示系统级别:1/新注册;2/邮箱谷歌手机其中有一个已验证;3/用户实名认证;4/用户高级认证;
        // 十进制十位表示自定义级别:对应在前端显示为如VIP1 VIP2等级、黄金 白银等级;
        // 如:级别11表示:新注册的前端显示为VIP1;
        int userLevel = party.getUserLevel();
//        party.setUserLevel(((int) Math.floor(userLevel / 10)) * 10 + userLevelSystem);
        userService.updateById(party);
        return Result.succeed(null);
    }
 
    /**
     * 邮箱绑定
     */
    @PostMapping("saveEmail")
    @ApiOperation("邮箱绑定")
    public Result<?> save_email(String email, String verifcode) {
 
        if (StringUtils.isEmptyString(email) || !Strings.isEmail(email)) {
            throw new YamiShopBindException("请填写正确的邮箱地址");
        }
        String loginPartyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(loginPartyId);
        if (null != party.getUserMail() && party.getUserMail().equals(email) && true == party.isMailBind()) {
            throw new YamiShopBindException("邮箱已绑定");
        }
        User partyEmail = userService.findPartyByVerifiedEmail(email);
        if (null != partyEmail && !partyEmail.getUserId().toString().equals(loginPartyId)) {
            throw new YamiShopBindException("邮箱已绑定其他用户");
        }
        String authcode = this.identifyingCodeTimeWindowService.getAuthCode(email);
        String bind_phone_email_ver = sysparaService.find("bind_phone_email_ver").getSvalue();
        // 如果是演示用户,则不判断验证码
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if ("1".contentEquals(bind_phone_email_ver)) {
                if (StringUtils.isEmptyString(verifcode)) {
                    throw new YamiShopBindException("请填写正确的验证码");
                }
                if ((null == authcode) || (!authcode.equals(verifcode))) {
                    throw new YamiShopBindException("验证码不正确");
                }
            }
        }
        // 邮箱绑定成功
        party.setUserMail(email);
        party.setMailBind(true);
        // 获取用户系统等级:1/新注册;2/邮箱谷歌手机其中有一个已验证;3/用户实名认证; 4/用户高级认证;
        int userLevelSystem = userService.getUserLevelByAuth(party);
        // 十进制个位表示系统级别:1/新注册;2/邮箱谷歌手机其中有一个已验证;3/用户实名认证;4/用户高级认证;
        // 十进制十位表示自定义级别:对应在前端显示为如VIP1 VIP2等级、黄金 白银等级;
        // 如:级别11表示:新注册的前端显示为VIP1;
        int userLevel = party.getUserLevel();
//        party.setUserLevel(((int) Math.floor(userLevel / 10)) * 10 + userLevelSystem);
        userService.updateById(party);
        return Result.succeed(null);
    }
 
    /**
     * 修改登录密码 用验证码
     */
    @RequestMapping("updatePsw")
    public Object updatepsw(HttpServletRequest request) {
 
        String password = request.getParameter("password");
        String verifcode_type = request.getParameter("verifcode_type");
        String verifcode = request.getParameter("verifcode");
        if (StringUtils.isEmptyString(password)) {
            throw new BusinessException("密码不能为空");
        }
        if (password.length() < 6 || password.length() > 12) {
            throw new BusinessException("密码必须6-12位");
        }
        if (StringUtils.isEmptyString(verifcode_type)) {
            throw new BusinessException("验证类型不能为空");
        }
        if (StringUtils.isEmptyString(verifcode)) {
            throw new BusinessException("验证码不能为空");
        }
        String loginPartyId = SecurityUtils.getCurrentUserId();
        User party = userService.getById(loginPartyId);
        // 根据验证类型获取验证key verifcode_type: 1/手机;2/邮箱;3/谷歌验证器;
        String key = "";
        String errMsg = "";
        if ("1".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile();
            errMsg = "未绑定手机号";
        } else if ("2".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail();
            errMsg = "未绑定邮箱";
        } else if ("3".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret();
            errMsg = "未绑定谷歌验证器";
        }
        if (StringUtils.isEmptyString(key)) {
            throw new BusinessException(errMsg);
        }
        // 验证
        boolean passed = false;
        if ("1".equals(verifcode_type) || "2".equals(verifcode_type)) {
            String authcode = this.identifyingCodeTimeWindowService.getAuthCode(key);
            if ((null != authcode) && (authcode.equals(verifcode))) {
                passed = true;
                this.identifyingCodeTimeWindowService.delAuthCode(key);
            }
        } else if ("3".equals(verifcode_type)) {
            GoogleAuthenticator ga = new GoogleAuthenticator();
            ga.setWindowSize(5);
            long t = System.currentTimeMillis();
            boolean flag = ga.check_code(party.getGoogleAuthSecret(), Long.valueOf(verifcode), t);
            if (flag) {
                passed = true;
            }
        }
        // 如果是演示用户,则不判断验证码
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if (!passed) {
                throw new BusinessException("验证码不正确");
            }
        }
        party.setLoginPassword(passwordEncoder.encode(password));
        // 更新密码
        userService.updateById(party);
        return Result.succeed();
    }
 
    /**
     *
     */
    @PostMapping("updateOldAndNewPsw")
    @ApiOperation("修改登录密码 用旧密码")
    public Result updateOldAndNewPsw(String old_password, String password, String re_password) {
 
        if (StringUtils.isEmptyString(old_password)) {
            throw new YamiShopBindException("旧密码不能为空");
        }
        if (StringUtils.isEmptyString(password)) {
            throw new YamiShopBindException("新密码不能为空");
        }
        if (StringUtils.isEmptyString(re_password)) {
            throw new YamiShopBindException("新密码确认不能为空");
        }
        if (old_password.length() < 6 || old_password.length() > 12 || password.length() < 6 || password.length() > 12) {
            throw new YamiShopBindException("密码必须6-12位");
        }
        User secUser = userService.getById(SecurityUtils.getUser().getUserId());
        if (!passwordEncoder.matches(old_password, secUser.getLoginPassword())) {
            throw new YamiShopBindException("旧密码不正确!");
        }
        if (!password.equals(re_password)) {
            throw new YamiShopBindException("新密码不一致");
        }
        secUser.setLoginPassword(passwordEncoder.encode(re_password));
        userService.updateById(secUser);
        return Result.succeed(null);
    }
 
    /**
     * 修改资金密码 用验证码
     */
    @PostMapping("setSafeword")
    @ApiOperation("修改资金密码 用验证码")
    public Result setSafeword(String safeword, String verifcode_type, String verifcode) {
 
        if (StringUtils.isEmptyString(safeword)) {
            throw new YamiShopBindException("资金密码不能为空");
        }
        if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
            throw new YamiShopBindException("资金密码不符合设定");
        }
        if (StringUtils.isEmptyString(verifcode_type)) {
            throw new YamiShopBindException("验证类型不能为空");
        }
        if (StringUtils.isEmptyString(verifcode)) {
            throw new YamiShopBindException("验证码不能为空");
        }
        String loginPartyId = SecurityUtils.getUser().getUserId();
        User party = userService.getById(loginPartyId);
        // 根据验证类型获取验证key verifcode_type: 1/手机;2/邮箱;3/谷歌验证器;
        String key = "";
        String errMsg = "";
        if ("1".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getUserMobile()) || false == party.isUserMobileBind() ? "" : party.getUserMobile();
            errMsg = "未绑定手机号";
        } else if ("2".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getUserMail()) || false == party.isMailBind() ? "" : party.getUserMail();
            errMsg = "未绑定邮箱";
        } else if ("3".equals(verifcode_type)) {
            key = StringUtils.isEmptyString(party.getGoogleAuthSecret()) || false == party.isGoogleAuthBind() ? "" : party.getGoogleAuthSecret();
            errMsg = "未绑定谷歌验证器";
        }
        if (StringUtils.isEmptyString(key)) {
            throw new YamiShopBindException(errMsg);
        }
        // 验证
        boolean passed = false;
        if ("1".equals(verifcode_type) || "2".equals(verifcode_type)) {
            String authcode = this.identifyingCodeTimeWindowService.getAuthCode(key);
            if ((null != authcode) && (authcode.equals(verifcode))) {
                passed = true;
                this.identifyingCodeTimeWindowService.delAuthCode(key);
            }
        } else if ("3".equals(verifcode_type)) {
            long t = System.currentTimeMillis();
            GoogleAuthenticator ga = new GoogleAuthenticator();
            ga.setWindowSize(5);
            boolean flag = ga.check_code(party.getGoogleAuthSecret(), Long.valueOf(verifcode), t);
            if (flag) {
                passed = true;
            }
        }
        // 如果是演示用户,则不判断验证码
        if (!"GUEST".contentEquals(party.getRoleName())) {
            if (!passed) {
                throw new YamiShopBindException("验证码不正确");
            }
        }
        party.setSafePassword(passwordEncoder.encode(safeword));
        // 更新密码
        userService.updateById(party);
        return Result.succeed(null);
    }
 
    /**
     * 人工重置申请  操作类型 operate:     0/修改资金密码;1/取消谷歌绑定;2/取消手机绑定;3/取消邮箱绑定;
     */
    @PostMapping("setSafewordApply")
    @ApiOperation(" 人工重置申请")
    public Result set_safeword_apply(String idcard_path_front, String idcard_path_back,
                                     String idcard_path_hold, String safeword,
                                     String safeword_confirm, String operate,
                                     String remark) {
 
        if (StringUtils.isNullOrEmpty(operate)) {
            throw new YamiShopBindException("操作类型为空");
        }
        if (!StringUtils.isInteger(operate)) {
            throw new YamiShopBindException("操作类型不是整数");
        }
        if (Integer.valueOf(operate).intValue() < 0) {
            throw new YamiShopBindException("操作类型不能小于0");
        }
 
        if (!StrUtil.isEmpty(remark)) {
            if (remark.length() > 250) {
                throw new YamiShopBindException("备注长度超过250");
            }
        }
        Integer operate_int = Integer.valueOf(operate);
        this.userSafewordApplyService.saveApply(SecurityUtils.getUser().getUserId(), idcard_path_front, idcard_path_back, idcard_path_hold, safeword, safeword_confirm, operate_int, remark);
        return Result.succeed(null);
    }
 
    @ApiOperation("获取 人工重置 信息")
    @GetMapping("getSafewordApply")
    public Result getSafewordApply() {
        List<Map<String, Object>> retList = new ArrayList<Map<String, Object>>();
        List<UserSafewordApply> list = this.userSafewordApplyService.findByUserId(SecurityUtils.getUser().getUserId());
        for (int i = 0; i < list.size(); i++) {
            retList.add(this.userSafewordApplyService.bindOne(list.get(i)));
        }
 
        return Result.ok(retList);
    }
 
    /**
     * 交易所用户注册(验证码方式)
     * 备注:可以用,但是目前没用到
     */
    @RequestMapping("registerUsername")
    public Object register_username(HttpServletRequest request) {
        String username = null;
        try {
            username = request.getParameter("username").replace(" ", "");
            String password = request.getParameter("password").replace(" ", "");
            String safeword = request.getParameter("safeword").replace(" ", "");
            String usercode = request.getParameter("usercode");
            String code = request.getParameter("code");
            String key = request.getParameter("key");
            if (!LockFilter.add(username)) {
                return Result.failed("重复提交");
            }
            String error = validateParamUsername(username, password);
            if (!StringUtils.isNullOrEmpty(error)) {
                return Result.failed(error);
            }
            if (StringUtils.isEmptyString(safeword)) {
                throw new YamiShopBindException("资金密码不能为空");
            }
            if (safeword.length() != 6 || !Strings.isNumber(safeword)) {
                throw new YamiShopBindException("资金密码不符合设定");
            }
            boolean register_image_code_button = sysparaService.find("register_image_code_button").getBoolean();
            if (register_image_code_button) {
                if (StringUtils.isEmptyString(code) || StringUtils.isEmptyString(key)) {
                    throw new BusinessException("验证码不能为空");
                } else {
                    String codeText = redisTemplate.opsForValue().get(key).toString();
                    String decryptCode = ImageVerificationEndecrypt.decryptDES(code, key + "key");
                    if (!decryptCode.equalsIgnoreCase(codeText)) {
                        log.info("ip:{" + IPHelper.getIpAddr() + "},图片验证码不正确,paramcode:{" + decryptCode + "},truecode:{"
                                + codeText + "}");
                        throw new BusinessException("验证码错误");
                    }
                }
            }
            User secUser = userService.saveRegisterUsername(username, password, usercode, safeword);
//            User secUser = userService.findByUserName(username);
            Log log = new Log();
            log.setCategory(Constants.LOG_CATEGORY_SECURITY);
            log.setLog("用户无验证码注册,ip[" + IPHelper.getIpAddr() + "]");
            log.setUserId(secUser.getUserId());
            log.setUsername(username);
            logService.save(log);
 
            // 注册完直接登录返回token
            UserInfoInTokenBO userInfoInToken = new UserInfoInTokenBO();
            userInfoInToken.setUserId(secUser.getUserId());
            userInfoInToken.setSysType(SysTypeEnum.ORDINARY.value());
            userInfoInToken.setEnabled(secUser.getStatus() == 1);
            tokenStore.deleteAllToken(String.valueOf(SysTypeEnum.ORDINARY.value()), String.valueOf(secUser.getUserId()));
            TokenInfoVO tokenInfoVO = tokenStore.storeAndGetVo(userInfoInToken);
            tokenInfoVO.setToken(tokenInfoVO.getAccessToken());
            userService.online(secUser.getUserId());
 
            Map<String, Object> data = new HashMap<>();
            data.put("token", tokenInfoVO.getAccessToken());
            data.put("username", secUser.getUserName());
            data.put("usercode", secUser.getUserCode());
            secUser.setUserLastip(IPHelper.getIpAddr());
            secUser.setUserLasttime(new Date());
            userService.updateById(secUser);
            return Result.succeed(data);
        } catch (Exception e) {
            log.error("registerUsername error", e);
            return Result.failed(e.getMessage());
        } finally {
            if (username != null) {
                LockFilter.remove(username);
            }
        }
    }
 
    /**
     * 获取我的分享信息
     */
    @RequestMapping("getShare.action")
    public Result getShare() {
 
        User party = userService.getById(SecurityUtils.getCurrentUserId());
        // 关闭后,正式用户进入推广页面的时候,接口就不返回内容
        RealNameAuthRecord kyc = realNameAuthRecordService.getByUserId(party.getUserId());
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("username", party.getUserName());
        map.put("userrole", party.getRoleName());
        map.put("usercode", party.getUserCode());
        // 十进制个位表示系统级别:1/新注册;2/邮箱谷歌手机其中有一个已验证;3/用户实名认证;4/用户高级认证;
        // 十进制十位表示自定义级别:对应在前端显示为如VIP1 VIP2等级、黄金 白银等级;
        // 如:级别11表示:新注册的前端显示为VIP1;
        map.put("user_level", (int) (party.getUserLevel() % 10));
        map.put("user_level_custom", (int) Math.floor(party.getUserLevel() / 10));
        map.put("user_level_custom_display", "VIP");
        String user_level_custom_config = this.sysparaService.find("user_level_custom_config").getSvalue();
        String[] levelArray = user_level_custom_config.split(",");
        for (int i = 0; i < levelArray.length; i++) {
            String[] level = levelArray[i].split("-");
            if (level[0].equals(map.get("user_level_custom").toString())) {
                map.put("user_level_custom_display", level[1]);
                break;
            }
        }
        if (party.isRealNameAuthority()) {
            map.put("name", kyc.getName());
        }
        if (Constants.SECURITY_ROLE_TEST.equals(party.getRoleName())) {
            map.put("test", true);
        }
        return Result.succeed(map);
    }
 
    private String validateParamUsername(String username, String password) {
 
        if (StringUtils.isNullOrEmpty(username)) {
            return "用户名不能为空";
        }
        if (StringUtils.isNullOrEmpty(password)) {
            return "登录密码不能为空";
        }
        if (!RegexUtil.isUSername(username)) {
            return "用户名必须由数字和英文字母组成";
        }
        int min = 6;
        int max = 12;
        int max_name = 24;
        if (!RegexUtil.length(username, min, max_name)) {
            return "用户名不符合设定";
        }
        if (!RegexUtil.length(password, min, max)) {
            return "登陆密码长度不符合设定";
        }
        return null;
    }
 
}