admin
2024-01-23 81da61b828e29b7745e1382dfbbaeb685dc083ef
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
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
package com.yeshi.fanli.controller.client.v1;
 
import com.alipay.api.AlipayApiException;
import com.google.gson.Gson;
import com.ks.push.service.BDeviceTokenService;
import com.yeshi.fanli.dto.wx.WXAccountInfoDTO;
import com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.*;
import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum;
import com.yeshi.fanli.entity.bus.user.UserInfoModifyRecord.ModifyTypeEnum;
import com.yeshi.fanli.entity.push.DeviceActive;
import com.yeshi.fanli.entity.system.BusinessSystem;
import com.yeshi.fanli.entity.taobao.ClientTBPid;
import com.yeshi.fanli.entity.taobao.PidUser;
import com.yeshi.fanli.entity.taobao.TBPid;
import com.yeshi.fanli.entity.taobao.TaoBaoUnionConfig;
import com.yeshi.fanli.exception.user.AlipayAccountException;
import com.yeshi.fanli.exception.user.AlipayTransferException;
import com.yeshi.fanli.exception.user.UserAccountException;
import com.yeshi.fanli.log.LogHelper;
import com.yeshi.fanli.service.inter.config.BusinessSystemService;
import com.yeshi.fanli.service.inter.config.ConfigService;
import com.yeshi.fanli.service.inter.homemodule.HomeNavbarUserService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
import com.yeshi.fanli.service.inter.money.extract.BindingAccountService;
import com.yeshi.fanli.service.inter.order.HongBaoV2Service;
import com.yeshi.fanli.service.inter.push.*;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.user.*;
import com.yeshi.fanli.util.*;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.wx.MyWXLoginUtil;
import com.yeshi.fanli.vo.user.QQUserInfoVO;
import net.sf.json.JSONObject;
import org.apache.dubbo.config.annotation.Reference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.yeshi.utils.JsonUtil;
import org.yeshi.utils.TimeUtil;
import org.yeshi.utils.encrypt.DESUtil;
import org.yeshi.utils.entity.ProxyIP;
import org.yeshi.utils.entity.wx.WeiXinUser;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.PrintWriter;
import java.math.BigDecimal;
 
/**
 * 账户系统
 *
 * @author Administrator
 */
@Controller
@RequestMapping("api/v1/user")
public class UserAccountController {
 
    private Logger logger = LoggerFactory.getLogger(UserAccountController.class);
 
    @Resource
    private UserInfoService userInfoService;
 
 
    @Resource
    private HongBaoV2Service hongBaoV2Service;
 
    @Resource
    private BindingAccountService bindingAccountService;
 
 
    @Resource
    private ConfigService configService;
 
    @Resource
    private BusinessSystemService businessSystemService;
 
 
    @Resource
    private UserAccountService userAccountService;
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private TBPidService tbPidService;
 
    @Resource
    private DeviceTokenHWService deviceTokenHWService;
 
    @Resource
    private DeviceTokenOPPOService deviceTokenOPPOService;
 
    @Resource
    private DeviceTokenXMService deviceTokenXMService;
 
    @Resource
    private DeviceTokenVIVOService deviceTokenVIVOService;
 
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
 
    @Resource
    private SpreadUserImgService spreadUserImgService;
 
    @Resource
    private UserShareGoodsRecordService userShareGoodsRecordService;
 
    @Resource
    private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
 
 
    @Resource
    private UserMoneyService userMoneyService;
 
 
    @Resource
    private HomeNavbarUserService homeNavbarUserService;
 
 
    @Resource
    private UserInfoModifyRecordService userInfoModifyRecordService;
 
    @Resource
    private DeviceActiveService deviceActiveService;
 
 
    @Reference(version = "1.0", check = false)
    private BDeviceTokenService bDeviceTokenService;
 
    private BusinessSystem getSystem(AcceptData acceptData) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages(), acceptData.getSystem());
        return system;
    }
 
    /**
     * @param acceptData
     * @param code
     * @param vcode
     * @param phone
     * @param wxinstall
     * @param tbOpenid
     * @param tbNickName
     * @param tbPortrait
     * @param tbSession(淘宝session数据,加密)
     * @param out
     */
    @RequestMapping(value = "login")
    public void login(AcceptData acceptData, String code, String vcode, String phone, boolean wxinstall,
                      String tbOpenid, String tbNickName, String tbPortrait, String tbSession, int loginType, Boolean first,
                      HttpSession session, HttpServletRequest request, PrintWriter out) {
 
        // 2.0以下版本不允许登录
        if (!VersionUtil.greaterThan_2_0(acceptData.getPlatform(), acceptData.getVersion())) {
            out.print("请升级到最新版本");
            return;
        }
 
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (loginType == 3 && !Constant.IS_TEST)// 验证短信验证码
        {
            // 苹果应用商店上线测试号码
            if ("17316780233".equalsIgnoreCase(phone) && "258168".equalsIgnoreCase(vcode)) {
                ;
            } else {
                String oldVcode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_LOGIN);
                if (StringUtil.isNullOrEmpty(oldVcode) || !oldVcode.equalsIgnoreCase(vcode)) {
                    out.print(JsonUtil.loadFalseResult(90001, "验证码错误"));
                    return;
                }
            }
 
            redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
        }
 
        UserInfo tbUserInfo = new UserInfo();
        if (!StringUtil.isNullOrEmpty(tbSession)) {
            try {
                tbSession = DESUtil.decode(tbSession.replace("\n", ""), StringUtil.getBase64String("YeShiFANLI889*+"),
                        StringUtil.getBase64String("*M#34f?,"));
            } catch (Exception e) {
                e.printStackTrace();
            }
            JSONObject tbs = JSONObject.fromObject(tbSession);
            tbOpenid = tbs.optString("openId");
            tbNickName = tbs.optString("nick");
            tbPortrait = tbs.optString("avatarUrl");
            // 淘宝ID
            tbUserInfo.setTaoBaoUid(tbs.optString("taobao_user_id"));
        }
 
        tbUserInfo.setOpenid(tbOpenid);
        tbUserInfo.setTbName(tbNickName);
        tbUserInfo.setTbPic(tbPortrait);
 
        try {
            LoginResult result = userAccountService.login(request, acceptData, first, system.getAppid(), code, phone,
                    tbUserInfo, wxinstall, loginType);
            if (result == null)
                LogHelper.error("login-result为空值");
 
            // if (result.getUser() != null)
            // userAccountService.clearUserPortrait(result.getUser().getId());
 
            JSONObject data = new JSONObject();
            data.put("user", GsonUtil.toJsonExpose(UserUtil.filterForClientUser(result.getUser())));
            if (result.getType() == LoginResult.TYPE_CONNECT) {
                data.put("mainUser", GsonUtil.toJsonExpose(UserUtil.filterForClientUser(result.getMainUser())));
                data.put("lessUser", GsonUtil.toJsonExpose(UserUtil.filterForClientUser(result.getLessUser())));
            }
            JSONObject root = new JSONObject();
            root.put("type", result.getType());
            root.put("data", data);
            out.print(JsonUtil.loadTrueResult(root));
 
            final UserInfo uuser = result.getUser();
            ThreadUtil.run(new Runnable() {
                public void run() {
                    try {
                        // 绑定oppo,vivo推送
                        DeviceActive active = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
                        if (active != null) {
                            deviceTokenOPPOService.bindUid(uuser.getId(), active.getId());
                            deviceTokenVIVOService.bindUid(uuser.getId(), active.getId());
                            deviceTokenXMService.bindUid(active.getId(), uuser.getId());
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            });
 
        } catch (UserAccountException e) {
            try {
                LogHelper.error("登录出错:" + e.getCode() + "-" + e.getMessage());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
 
    }
 
    /**
     * 账号注册
     *
     * @param acceptData
     * @param tbOpenid
     * @param tbNickName
     * @param tbPortrait
     * @param vcode
     * @param phone
     * @param session
     * @param out
     */
    @RequestMapping(value = "register")
    public void register(AcceptData acceptData, String tbOpenid, String tbNickName, String tbPortrait, String vcode,
                         String phone, HttpServletRequest request, HttpSession session, PrintWriter out) {
        // 2.0以下版本不允许登录
        if (!VersionUtil.greaterThan_2_0(acceptData.getPlatform(), acceptData.getVersion())) {
            out.print("请升级到最新版本");
            return;
        }
 
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (!StringUtil.isNullOrEmpty(phone))// 验证短信验证码
        {
            String oldVcode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_LOGIN);
            if (StringUtil.isNullOrEmpty(oldVcode) || !oldVcode.equalsIgnoreCase(vcode)) {
                out.print(JsonUtil.loadFalseResult(90001, "验证码错误"));
                return;
            }
 
            redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
        }
 
        if (StringUtil.isNullOrEmpty(phone) && StringUtil.isNullOrEmpty(tbOpenid)) {
            out.print(JsonUtil.loadFalseResult(5, "请上传注册信息"));
            return;
        }
 
        UserInfo user = new UserInfo();
        user.setOpenid(tbOpenid);
        user.setTbName(tbNickName);
        user.setTbPic(tbPortrait);
 
        user.setNickName(tbNickName);
        user.setPortrait(tbPortrait);
 
        user.setPhone(phone);
        user.setAppId(system.getAppid());
        user.setLastLoginIp(request.getRemoteHost());
        user.setLastLoginTime(java.lang.System.currentTimeMillis());
        if (!StringUtil.isNullOrEmpty(phone))
            user.setLoginType(3);
        else
            user.setLoginType(1);
        try {
            userAccountService.register(user);
            user = userInfoService.getUserByIdWithMybatis(user.getId());
            JSONObject data = new JSONObject();
            data.put("user", GsonUtil.toJsonExpose(UserUtil.filterForClientUser(user)));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
    }
 
    /**
     * 获取用户ID
     *
     * @param acceptData
     * @param code
     * @param tbOpenid
     * @param phone
     * @param out
     */
    @RequestMapping(value = "getuid")
    public void getUid(AcceptData acceptData, String code, String tbOpenid, String phone, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
        UserInfo user = null;
        if (!StringUtil.isNullOrEmpty(code)) {
            WXAccountInfoDTO accountInfo = Constant.getWXAccount(acceptData.getPlatform(), acceptData.getVersion());
 
            WeiXinUser weiXinUser = MyWXLoginUtil.getWeiXinUserWithSavePortrait(code, accountInfo.getAppId(),
                    accountInfo.getAppSecret());
            if (weiXinUser == null) {
                out.print(JsonUtil.loadFalseResult(1, "获取微信用户信息失败"));
                return;
            }
            try {
                user = userAccountService.getUserInfoByWXUnionId(SystemInfoUtil.getSystem(acceptData), weiXinUser.getUnionid());
            } catch (UserAccountException e) {
                try {
                    LogHelper.errorDetailInfo(e, null, "获取用户信息出错");
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        } else if (!StringUtil.isNullOrEmpty(tbOpenid)) {
            try {
                user = userAccountService.getUserInfoByTaoBaoOpenId(SystemInfoUtil.getSystem(acceptData), tbOpenid);
            } catch (UserAccountException e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        } else if (!StringUtil.isNullOrEmpty(phone)) {
            try {
                user = userAccountService.getUserInfoByPhone(SystemInfoUtil.getSystem(acceptData), phone);
            } catch (UserAccountException e) {
                try {
                    LogHelper.errorDetailInfo(e);
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        }
 
        if (user == null) {
            out.print(JsonUtil.loadFalseResult(2, "用户尚未绑定"));
            return;
        } else {
            JSONObject data = new JSONObject();
            data.put("uid", user.getId());
            out.print(JsonUtil.loadTrueResult(data));
            return;
        }
    }
 
    /**
     * 绑定电话号码
     *
     * @param acceptData
     * @param vcode
     * @param phone
     * @param out
     */
    @RequestMapping(value = "bindPhone")
    public void bindPhone(AcceptData acceptData, Long uid, String vcode, String phone, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(vcode)) {
            out.print(JsonUtil.loadFalseResult(3, "请上传验证码"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(phone)) {
            out.print(JsonUtil.loadFalseResult(3, "请上传电话号码"));
            return;
        }
 
        String oldVCode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_LOGIN);
 
        if (Constant.IS_OUTNET) {
            if (!vcode.equalsIgnoreCase(oldVCode)) {
                out.print(JsonUtil.loadFalseResult(90001, "验证码错误"));
                return;
            }
            redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_LOGIN);
        }
        try {
            userAccountService.bindPhone(uid, phone);
            UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
            // 判断电话号码是否已经封禁
            ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
                    .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, phone);
            if (ic != null && ic.getEffective() != null && ic.getEffective()) {
                out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
                // 封禁用户
                // 封禁绑定的正常用户
                if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
                    userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的电话号码");
                }
                return;
            }
 
            JSONObject data = new JSONObject();
            data.put("user", UserUtil.filterForClientUser(user));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
 
    }
 
    /**
     * 解绑电话号码
     *
     * @param acceptData
     * @param uid
     * @param phone
     * @param out
     */
    @RequestMapping(value = "unBindPhone")
    public void unBindPhone(AcceptData acceptData, Long uid, String phone, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(phone)) {
            out.print(JsonUtil.loadFalseResult(3, "请上传电话号码"));
            return;
        }
 
        try {
            userAccountService.unBindPhone(uid, phone);
            out.print(JsonUtil.loadTrueResult("解绑成功"));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
 
    }
 
    /**
     * 绑定淘宝
     *
     * @param acceptData
     * @param uid
     * @param tbOpenid
     * @param tbNickName
     * @param tbPortrait
     * @param tbSession  -淘宝授权session
     * @param out
     */
 
    @RequestMapping(value = "bindTaoBao")
    public void bindTaoBao(AcceptData acceptData, Long uid, String tbOpenid, String tbNickName, String tbPortrait,
                           String tbSession, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        String taoBaoUid = "";
 
        if (!StringUtil.isNullOrEmpty(tbSession)) {
            try {
                tbSession = DESUtil.decode(tbSession.replace("\n", ""), StringUtil.getBase64String("YeShiFANLI889*+"),
                        StringUtil.getBase64String("*M#34f?,"));
            } catch (Exception e) {
                e.printStackTrace();
            }
            JSONObject session = JSONObject.fromObject(tbSession);
            tbOpenid = session.optString("openId");
            tbNickName = session.optString("nick");
            tbPortrait = session.optString("avatarUrl");
            taoBaoUid = session.optString("taobao_user_id");
        }
 
        try {
            userAccountService.bindTaoBao(uid, tbOpenid, tbNickName, tbPortrait);
            UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
 
            // 判断taoBaoUid是否已经封禁
            if (!StringUtil.isNullOrEmpty(taoBaoUid)) {
                ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
                        .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.taobaoUid, taoBaoUid);
                if (ic != null && ic.getEffective() != null && ic.getEffective()) {
                    out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER,
                            Constant.FORBIDDEN_USER_REASON_DESC));
                    // 封禁用户
                    // 封禁绑定的正常用户
                    if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
                        userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的淘宝号");
                    }
                    return;
                }
            }
 
            JSONObject data = new JSONObject();
            data.put("user", UserUtil.filterForClientUser(user));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
    }
 
    /**
     * 解绑淘宝
     *
     * @param acceptData
     * @param uid
     * @param out
     */
    @RequestMapping(value = "unBindTaoBao")
    public void unBindTaoBao(AcceptData acceptData, Long uid, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        try {
            userAccountService.unBindTaoBao(uid);
            out.print(JsonUtil.loadTrueResult("解绑成功"));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
    }
 
    /**
     * 更改微信
     *
     * @param acceptData
     * @param uid
     * @param code
     * @param out
     */
    @RequestMapping(value = "changeWX")
    public void changeWX(AcceptData acceptData, Long uid, String code, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(code)) {
            out.print(JsonUtil.loadFalseResult(3, "请上传code"));
            return;
        }
 
        try {
            userAccountService.changeWXBind(acceptData, uid, code);
            UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
            // 判断taoBaoUid是否已经封禁
            ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
                    .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.wxUnionId, user.getWxUnionId());
            if (ic != null && ic.getEffective() != null && ic.getEffective()) {
                out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
                // 封禁用户
                // 封禁绑定的正常用户
                if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
                    userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的微信号");
                }
                return;
            }
 
            JSONObject data = new JSONObject();
            data.put("user", UserUtil.filterForClientUser(user));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
    }
 
    /**
     * 获取电话号码
     *
     * @param acceptData
     * @param uid
     * @param out
     */
    @RequestMapping(value = "getphone")
    public void getPhone(AcceptData acceptData, Long uid, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (uid == null || uid == 0) {
            out.print(JsonUtil.loadFalseResult(1, "请上传用户ID"));
            return;
        }
 
        UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
        user = UserUtil.filterForClientUser(user);
        JSONObject data = new JSONObject();
        data.put("phone", user.getPhone());
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    @RequestMapping(value = "verifyvcodeforbind")
    public void verifyVcodeForbind(AcceptData acceptData, Long uid, String vcode, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (uid == null || uid == 0) {
            out.print(JsonUtil.loadFalseResult(1, "请上传用户ID"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(vcode)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传验证码"));
            return;
        }
 
        UserInfo user = userInfoService.getUserById(uid);
 
        if (StringUtil.isNullOrEmpty(user.getPhone())) {
            out.print(JsonUtil.loadFalseResult(1, "没有绑定电话号码"));
            return;
        }
        if (!Constant.IS_TEST) {
            String code = redisManager.getSMSVCode(user.getPhone(), SMSHistory.TYPE_LOGIN);
            if (code == null || !code.equalsIgnoreCase(vcode)) {
                out.print(JsonUtil.loadFalseResult(90001, "验证码错误"));
                return;
            }
        }
        redisManager.clearSMSFrequencyLimit(user.getPhone(), SMSHistory.TYPE_LOGIN);
        redisManager.saveBindAlipayAccountSMSState(user.getPhone());
        out.print(JsonUtil.loadTrueResult(""));
    }
 
    /**
     * 支付宝绑定
     *
     * @param acceptData
     * @param uid-用户ID
     * @param name-支付宝实名名称
     * @param account      -支付宝账号
     * @param out
     */
    @RequestMapping(value = "bindalipay")
    public void bindAlipay(AcceptData acceptData, Long uid, String name, String account, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (uid == null || uid == 0) {
            out.print(JsonUtil.loadFalseResult(1, "请上传用户ID"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(name)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传支付宝实名名称"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(account)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传支付宝账号"));
            return;
        }
 
        UserInfo user = userInfoService.getUserById(uid);
 
        boolean bind = redisManager.isBindAlipayAccountSMSStateValid(user.getPhone());
        if (!bind) {
            out.print(JsonUtil.loadFalseResult(90002, "手机验证超时"));
            return;
        }
 
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.bindAlipay, uid + "");
        if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) {
            out.print(JsonUtil.loadFalseResult(2, "服务器繁忙,请稍后重试"));
            return;
        }
        redisManager.cacheCommonString(key, "1", 120);
        // 更换绑定
        try {
            BindingAccount bindingAccount = bindingAccountService.changeAlipayBinding(uid, name, account);
            out.print(JsonUtil.loadTrueResult(JsonUtil.getGson().toJson(bindingAccount)));
        } catch (Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            out.print(JsonUtil.loadFalseResult(3, "服务器内部错误"));
        } finally {
            redisManager.removeCommonString(key);
        }
    }
 
    @RequestMapping(value = "bindalipaywithverify")
    public void bindAlipayWithVerify(AcceptData acceptData, Long uid, String name, String account, PrintWriter out) {
 
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (uid == null || uid == 0) {
            out.print(JsonUtil.loadFalseResult(1, "请上传用户ID"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(name)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传支付宝实名名称"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(account)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传支付宝账号"));
            return;
        }
 
        UserInfo user = userInfoService.getUserById(uid);
 
        boolean bind = redisManager.isBindAlipayAccountSMSStateValid(user.getPhone());
        if (!bind) {
            out.print(JsonUtil.loadFalseResult(90002, "手机验证超时"));
            return;
        }
 
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.bindAlipay, uid + "");
        if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) {
            out.print(JsonUtil.loadFalseResult(1001, "服务器繁忙,请稍后重试"));
            return;
        }
        redisManager.cacheCommonString(key, "1", 120);
        // 可以展示给用户看的错误码
        String[] ALIPAY_CODES = new String[]{"SYSTEM_ERROR", "PERMIT_CHECK_PERM_LIMITED", "PERM_AML_NOT_REALNAME_REV",
                "PERM_AML_NOT_REALNAME_REV", "PAYEE_USER_INFO_ERROR", "PAYEE_ACC_OCUPIED",
                "PERMIT_CHECK_PERM_IDENTITY_THEFT", "PERMIT_NON_BANK_LIMIT_PAYEE", "EXCEED_LIMIT_UNRN_DM_AMOUNT"};
        try {
            BindingAccount bindingAccount = bindingAccountService.changeAlipayBindingWithVerify(uid, name, account);
            out.print(JsonUtil.loadTrue(0, JsonUtil.getGson().toJson(bindingAccount), "您的支付宝账号通过验证,可以正常提现"));
        } catch (AlipayTransferException e1) {
            if (e1.getSubCode().equalsIgnoreCase("PAYEE_NOT_EXIST")) {
                String msg = "无法搜索到该账号\n①请检查一下支付宝帐号和姓名是否填写正确。\n ②请在支付宝隐私设置中检查是否已开启“通过邮箱/手机号/会员名找到我”选项。";
                out.print(JsonUtil.loadFalseResult(1, msg));
            } else {
                for (String st : ALIPAY_CODES) {
                    if (st.equalsIgnoreCase(e1.getSubCode())) {
                        out.print(JsonUtil.loadFalseResult(2, e1.getMsg()));
                        return;
                    }
                }
                out.print(JsonUtil.loadFalseResult(3, "支付宝接口出错,验证失败,请联系客服。"));
                return;
            }
 
        } catch (AlipayApiException e2) {
            out.print(JsonUtil.loadFalseResult(4, e2.getErrMsg()));
            return;
        } catch (AlipayAccountException e3) {
            // 账户无余额
            if (e3.getCode() == AlipayAccountException.CODE_NO_MONEY) {
                out.print(JsonUtil.loadFalseResult(5, e3.getMsg()));
                return;
                // 提现次数限制
            } else if (e3.getCode() == AlipayAccountException.CODE_TIMES_LIMIT) {
                out.print(JsonUtil.loadFalseResult(6, e3.getMsg()));
                return;
            } else {
                out.print(JsonUtil.loadFalseResult(7, e3.getMsg()));
                return;
            }
 
        } catch (Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            out.print(JsonUtil.loadFalseResult(8, "服务器内部错误,验证失败,请联系客服。"));
        } finally {
            redisManager.removeCommonString(key);
        }
    }
 
    @RequestMapping(value = "bindalipaywithverifynew")
    public void bindAlipayWithVerifyNew(AcceptData acceptData, Long uid, String name, String account, PrintWriter out) {
 
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (uid == null || uid == 0) {
            out.print(JsonUtil.loadFalseResult(1, "请上传用户ID"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(name)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传支付宝实名名称"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(account)) {
            out.print(JsonUtil.loadFalseResult(1, "请上传支付宝账号"));
            return;
        }
 
        UserInfo user = userInfoService.getUserById(uid);
 
        boolean bind = redisManager.isBindAlipayAccountSMSStateValid(user.getPhone());
        if (!bind) {
            out.print(JsonUtil.loadFalseResult(90002, "手机验证超时"));
            return;
        }
 
        String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.bindAlipay, uid + "");
        if (!StringUtil.isNullOrEmpty(redisManager.getCommonString(key))) {
            out.print(JsonUtil.loadFalseResult(1001, "服务器繁忙,请稍后重试"));
            return;
        }
        redisManager.cacheCommonString(key, "1", 120);
 
        // 支付宝绑定
        ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
                .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.alipayAccount, account);
        if (ic != null && ic.getEffective() != null && ic.getEffective()) {
            out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
            // 封禁用户
            // 封禁绑定的正常用户
            if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
                userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的支付宝");
            }
            return;
        }
 
        // 可以展示给用户看的错误码
        String[] ALIPAY_CODES = new String[]{"SYSTEM_ERROR", "PERMIT_CHECK_PERM_LIMITED", "PERM_AML_NOT_REALNAME_REV",
                "PERM_AML_NOT_REALNAME_REV", "PAYEE_USER_INFO_ERROR", "PAYEE_ACC_OCUPIED",
                "PERMIT_CHECK_PERM_IDENTITY_THEFT", "PERMIT_NON_BANK_LIMIT_PAYEE", "EXCEED_LIMIT_UNRN_DM_AMOUNT"};
        BindingAccount oldBindingAccount = bindingAccountService.getBindingAccountByUidAndType(uid,
                BindingAccount.TYPE_ALIPAY);
        try {
            BigDecimal balance = user.getMyHongBao();
            BindingAccount bindingAccount = bindingAccountService.changeAlipayBindingWithVerify(uid, name, account);
            // 余额充足
            if (balance.compareTo(new BigDecimal("0.1")) >= 0)
                out.print(JsonUtil.loadTrue(0, JsonUtil.getGson().toJson(bindingAccount),
                        "系统已成功转账0.1元到提现账号中,提现账号验证通过,恭喜你!可以提现了。"));
            else
                out.print(JsonUtil.loadTrue(0, JsonUtil.getGson().toJson(bindingAccount),
                        "系统已成功转账0.1元到提现账号中,提现账号验证通过,恭喜你!可以提现了。注:此0.1元将会在后续产生的余额中合理扣除,敬请知晓。"));
 
            userInfoModifyRecordService.addModifyRecord(uid, ModifyTypeEnum.bindAlipay, account);
        } catch (AlipayTransferException e1) {
            LogHelper.error("支付宝验证出错:" + new Gson().toJson(e1));
            if (e1.getSubCode().equalsIgnoreCase("PAYEE_NOT_EXIST")) {
                String msg = "系统未能成功转账0.1元,提现账号信息有误,请核对后重新填写。";
                out.print(JsonUtil.loadFalseResult(1, msg));
            } else {
                for (String st : ALIPAY_CODES) {
                    if (st.equalsIgnoreCase(e1.getSubCode())) {
                        out.print(JsonUtil.loadFalseResult(2, e1.getMsg()));
                        return;
                    }
                }
                out.print(JsonUtil.loadFalseResult(3, "支付宝接口出错,验证失败,请联系客服。"));
                return;
            }
 
        } catch (AlipayApiException e2) {
            out.print(JsonUtil.loadFalseResult(4, e2.getErrMsg()));
            return;
        } catch (AlipayAccountException e3) {
            // 账户无余额
            if (e3.getCode() == AlipayAccountException.CODE_NO_MONEY) {
                if (oldBindingAccount != null) {
                    out.print(JsonUtil.loadFalseResult(5, "当前账户没有余额,无需修改,请有余额后修改"));
                } else {
                    out.print(JsonUtil.loadFalseResult(5, "当前账户没有余额,请有余额后绑定"));
                }
                return;
                // 提现次数限制
            } else if (e3.getCode() == AlipayAccountException.CODE_TIMES_LIMIT) {
                out.print(JsonUtil.loadFalseResult(6, "每月仅可修改1次提现账号,请下月再试吧。"));
                return;
            } else {
                out.print(JsonUtil.loadFalseResult(7, e3.getMsg()));
                return;
            }
 
        } catch (Exception e) {
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
            out.print(JsonUtil.loadFalseResult(8, "服务器内部错误,验证失败,请联系客服。"));
        } finally {
            redisManager.removeCommonString(key);
        }
    }
 
    /**
     * 获取用户资金详情
     *
     * @param acceptData
     * @param uid
     * @param out
     */
    @RequestMapping(value = "getusermoney")
    public void getMoneyDetail(AcceptData acceptData, Long uid, PrintWriter out) {
 
        UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
        if (user == null) {
            out.print(JsonUtil.loadFalseResult(2, "用户不存在"));
            return;
        }
        BigDecimal moneyToday = userMoneyService.getMoneyToday(uid);
        if (moneyToday == null) {
            moneyToday = new BigDecimal(0);
        }
        BigDecimal moneyMonth = userMoneyService.getMoneyMonth(uid);
        if (moneyMonth == null) {
            moneyMonth = new BigDecimal(0);
        }
 
        BigDecimal moneyLastMonth = userMoneyService.getMoneyLastMonth(uid);
        BigDecimal unOpenmoney = hongBaoV2Service.getUnRecievedFanLiMoney(uid);
        BigDecimal totalFanMoney = hongBaoV2Service.getTotalFanLiMoney(uid);
        JSONObject data = new JSONObject();
        int spreadImgCount = spreadUserImgService.countUserSpreadImg(uid);
        long shareCount = userShareGoodsRecordService.countShareRecordByUid(uid);
 
        // IOS端数字按照字符串处理
        if ("ios".equalsIgnoreCase(acceptData.getPlatform()) && Integer.parseInt(acceptData.getVersion()) > 33) {
            data.put("moneyToday", moneyToday.setScale(2, BigDecimal.ROUND_DOWN).toString());
            data.put("moneyMonth", moneyMonth.setScale(2, BigDecimal.ROUND_DOWN).toString());
            data.put("moneyLastMonth", moneyLastMonth.setScale(2, BigDecimal.ROUND_DOWN).toString());
            data.put("money", user.getMyHongBao().setScale(2, BigDecimal.ROUND_DOWN).toString());
            data.put("unGetMoney", unOpenmoney.setScale(2, BigDecimal.ROUND_DOWN).toString());
            data.put("totalFanLiMoney", totalFanMoney.setScale(2, BigDecimal.ROUND_DOWN).toString());// 累计返利
            data.put("totalTiChengMoney",
                    hongBaoV2Service.getTotalTiChengMoney(uid).setScale(2, BigDecimal.ROUND_DOWN).toString());// 累计提成
            data.put("totalUnGetTiChengMoney",
                    hongBaoV2Service.getUnGetTiChengMoney(uid).setScale(2, BigDecimal.ROUND_DOWN).toString()); // 未到账提成
            // 展示提成数据
            if (configService.iosOnLining(Integer.parseInt(acceptData.getVersion()), SystemInfoUtil.getSystem(acceptData)))
                data.put("showTiCheng", false);
            else
                data.put("showTiCheng", spreadImgCount + shareCount > 0);
        } else {
            data.put("moneyToday", moneyToday.setScale(2, BigDecimal.ROUND_DOWN));
            data.put("moneyMonth", moneyMonth.setScale(2, BigDecimal.ROUND_DOWN));
            data.put("moneyLastMonth", moneyLastMonth.setScale(2, BigDecimal.ROUND_DOWN));
            data.put("money", user.getMyHongBao().setScale(2, BigDecimal.ROUND_DOWN));
            data.put("unGetMoney", unOpenmoney.setScale(2, BigDecimal.ROUND_DOWN));
            data.put("totalFanLiMoney", totalFanMoney.setScale(2, BigDecimal.ROUND_DOWN));// 累计返利
            data.put("totalTiChengMoney",
                    hongBaoV2Service.getTotalTiChengMoney(uid).setScale(2, BigDecimal.ROUND_DOWN));// 累计提成
            data.put("totalUnGetTiChengMoney",
                    hongBaoV2Service.getUnGetTiChengMoney(uid).setScale(2, BigDecimal.ROUND_DOWN)); // 未到账提成
            // 展示提成数据
            data.put("showTiCheng", spreadImgCount + shareCount > 0);
        }
 
        user.setNoOpenHongBao(unOpenmoney);
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    /**
     * 获取用户的PID信息
     *
     * @param acceptData
     * @param uid
     * @param out
     */
    @RequestMapping(value = "gettbpidinfo")
    public void getUserPid(AcceptData acceptData, String uid, PrintWriter out) {
        ClientTBPid clientTBPid = null;
        // 用户已经登录
        if (!StringUtil.isNullOrEmpty(uid)) {
            TBPid tbPid = null;
            if (acceptData.getPlatform().equalsIgnoreCase("android")) {
                tbPid = tbPidService.getTBPid(Long.parseLong(uid), PidUser.TYPE_FANLI_ANDROID);
                if (tbPid != null) {
                    String siteId = tbPid.getPid().split("_")[2];
                    String adzoneId = tbPid.getPid().split("_")[3];
                    TaoBaoUnionConfig config = taoBaoUnionConfigService.getConfigByAppIdCache(siteId);
                    clientTBPid = new ClientTBPid(config.getAppKey(), tbPid.getPid(), siteId, adzoneId);
                } else {
                    clientTBPid = tbPidService.getAndroidDefault();
                }
 
            } else {
 
                clientTBPid = tbPidService.getIOSDefault();
 
            }
 
        } else {
            if (acceptData.getPlatform().equalsIgnoreCase("android"))
                clientTBPid = tbPidService.getAndroidDefault();
            else
                clientTBPid = tbPidService.getIOSDefault();
        }
 
        JSONObject data = new JSONObject();
        data.put("pidInfo", clientTBPid);
        out.print(JsonUtil.loadTrueResult(data));
    }
 
    /**
     * 退出登录
     *
     * @param acceptData
     * @param uid        -用户ID
     * @param out
     */
    @RequestMapping(value = "logout")
    public void logOut(AcceptData acceptData, Long uid, PrintWriter out) {
        if (uid == null || uid == 0)
            return;
        if ("android".equalsIgnoreCase(acceptData.getPlatform())) {
            DeviceActive deviceActive = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
 
            //新版推送解绑
            if (acceptData.getSystem().isNewPush()) {
                try {
                    bDeviceTokenService.unBindUid(acceptData.getSystem().name(), StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid());
                } catch (Exception e) {
                    logger.error("新版推送解绑出错:{}", uid, e);
                }
            } else {
                // 需要解绑HW推送的用户绑定
                deviceTokenHWService.unBindDeviceToken(acceptData.getDevice());
                if (deviceActive != null) {
                    // 解绑OPPO推送的用户绑定
                    deviceTokenOPPOService.unBindUid(uid, deviceActive.getId());
                    // 解绑VIVO推送的用户绑定
                    deviceTokenVIVOService.unBindUid(uid, deviceActive.getId());
                    // 解绑XM推送的用户绑定
                    deviceTokenXMService.unBindUid(deviceActive.getId());
                }
            }
 
        }
        out.print(JsonUtil.loadTrueResult(""));
    }
 
    /**
     * 新版登录 V1.5.3
     *
     * @param acceptData
     * @param vcode
     * @param phone
     * @param code
     * @param loginType  登录方式: 1-手机登录 2-微信登录
     * @param request
     * @param out
     */
    @RequestMapping(value = "loginNew", method = RequestMethod.POST)
    public void loginNew(AcceptData acceptData, String vcode, String phone, String code, String aliAccessToken, int loginType,
                         HttpServletRequest request, PrintWriter out) {
 
        // 2.0以下版本不允许登录
        if (!VersionUtil.greaterThan_2_0(acceptData.getPlatform(), acceptData.getVersion())) {
            out.print("请升级到最新版本");
            return;
        }
 
        if (!StringUtil.isNullOrEmpty(aliAccessToken)) {
            long now = System.currentTimeMillis();
            String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.oneKeyLoginCount, StringUtil.Md5(StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid()));
            redisManager.increase(key);
            int expire = (int) ((TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now + 1000 * 60 * 60 * 24L, "yyyyMMdd"), "yyyyMMdd") - now) / 1000);
            redisManager.expire(key, expire);
        }
 
        try {
            BusinessSystem system = getSystem(acceptData);
            if (system == null) {
                out.print(JsonUtil.loadFalseResult("系统不存在"));
                return;
            }
 
            UserInfo userInfo = null;
            // 手机登录
            if (loginType == 1) {
                userInfo = userAccountService.loginPhone(new ProxyIP(request.getRemoteHost(), request.getRemotePort()), loginType, vcode, phone, aliAccessToken, system);
            }
 
            // 微信登录
            if (loginType == 2) {
                userInfo = userAccountService.loginWeiXin(new ProxyIP(request.getRemoteHost(), request.getRemotePort()), loginType, code, system);
            }
 
            if (userInfo == null) {
                out.print(JsonUtil.loadFalseResult("登录失败"));
            } else {
                JSONObject data = new JSONObject();
                data.put("userInfo", UserUtil.filterForClientUser(userInfo));
                out.print(JsonUtil.loadTrueResult(data));
 
                final UserInfo uuser = userInfo;
                ThreadUtil.run(new Runnable() {
                    public void run() {
                        String device = acceptData.getDevice();
                        try {
                            // 同步自定义导航
                            homeNavbarUserService.synchroDeviceToUser(uuser.getId(), device);
                        } catch (Exception e) {
                            LogHelper.errorDetailInfo(e);
                        }
 
                        // 绑定oppo推送
                        DeviceActive active = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
                        if (active != null) {
                            deviceTokenOPPOService.bindUid(uuser.getId(), active.getId());
                            deviceTokenVIVOService.bindUid(uuser.getId(), active.getId());
                            deviceTokenXMService.bindUid(active.getId(), uuser.getId());
                        }
                    }
                });
            }
 
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
            try {
                LogHelper.error("登录出错:" + e.getCode() + "-" + e.getMessage());
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult("登录失败"));
            try {
                LogHelper.errorDetailInfo(e);
            } catch (Exception e1) {
                e1.printStackTrace();
            }
        }
    }
 
    /**
     * 绑定电话号码 V1.5.3
     *
     * @param acceptData
     * @param vcode
     * @param phone
     * @param out
     */
    @RequestMapping(value = "bindPhoneNew")
    public void bindPhoneNew(AcceptData acceptData, Long uid, String vcode, String phone, String aliAccessToken, PrintWriter out) {
 
        BusinessSystem system = getSystem(acceptData);
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (!StringUtil.isNullOrEmpty(aliAccessToken)) {
            long now = System.currentTimeMillis();
            String key = RedisKeyEnum.getRedisKey(RedisKeyEnum.oneKeyLoginCount, StringUtil.Md5(StringUtil.isNullOrEmpty(acceptData.getUtdid()) ? acceptData.getDevice() : acceptData.getUtdid()));
            redisManager.increase(key);
            int expire = (int) ((TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now + 1000 * 60 * 60 * 24L, "yyyyMMdd"), "yyyyMMdd") - now) / 1000);
            redisManager.expire(key, expire);
        }
 
        String mobile = null;
        try {
            mobile = userAccountService.getMobile(vcode, phone, aliAccessToken, acceptData.getSystem(), SMSHistory.TYPE_BIND);
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getMsg()));
            return;
        }
 
        try {
            // 绑定用户
            userAccountService.bindPhoneNew(uid, mobile);
 
            UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
            // 判断电话号码是否已经封禁
            ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
                    .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.phone, mobile);
            if (ic != null && ic.getEffective() != null && ic.getEffective()) {
                out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
                // 封禁用户
                // 封禁绑定的正常用户
                if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
                    userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的电话号码");
                }
                return;
            }
 
            JSONObject data = new JSONObject();
            data.put("userInfo", UserUtil.filterForClientUser(user));
            out.print(JsonUtil.loadTrueResult(data));
 
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult(1, "绑定失败"));
        }
    }
 
    /**
     * 更改微信
     *
     * @param acceptData
     * @param uid
     * @param code
     * @param out
     */
    @RequestMapping(value = "bindWeiXin")
    public void bindWeiXin(AcceptData acceptData, Long uid, String code, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
 
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(code)) {
            out.print(JsonUtil.loadFalseResult("请上传code"));
            return;
        }
 
        try {
            userAccountService.bindWeiXin(system, uid, code);
 
            UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
            // 判断taoBaoUid是否已经封禁
            ForbiddenUserIdentifyCode ic = forbiddenUserIdentifyCodeService
                    .listByTypeAndIdentifyCode(ForbiddenUserIdentifyCodeTypeEnum.wxUnionId, user.getWxUnionId());
            if (ic != null && ic.getEffective() != null && ic.getEffective()) {
                out.print(JsonUtil.loadFalseResult(Constant.CODE_FORBIDDEN_USER, Constant.FORBIDDEN_USER_REASON_DESC));
                // 封禁用户
                // 封禁绑定的正常用户
                if (user != null && user.getState() != null && user.getState() == UserInfo.STATE_NORMAL) {
                    userAccountService.forbiddenUser(uid, "封禁:绑定被封禁的微信号");
                }
                return;
            }
 
            JSONObject data = new JSONObject();
            data.put("userInfo", UserUtil.filterForClientUser(user));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
    }
 
 
    /**
     * 更改微信
     *
     * @param acceptData
     * @param uid
     * @param qqUser
     * @param out
     */
    @RequestMapping(value = "bindQQ")
    public void bindQQ(AcceptData acceptData, Long uid, String qqUser, PrintWriter out) {
        BusinessSystem system = getSystem(acceptData);
 
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(qqUser)) {
            out.print(JsonUtil.loadFalseResult("请上传qqUser"));
            return;
        }
 
        String qqUserStr = StringUtil.getFromBase64(qqUser);
        QQUserInfoVO qqUserInfo = new Gson().fromJson(qqUserStr, QQUserInfoVO.class);
        try {
            userAccountService.bindQQ(uid, qqUserInfo);
 
            UserInfo user = userInfoService.getUserByIdWithMybatis(uid);
 
            JSONObject data = new JSONObject();
            data.put("userInfo", UserUtil.filterForClientUser(user));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        }
    }
 
}