admin
2019-10-16 9fc5a5bf46a7db97bec59a672cf2b16fb9b9d832
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
package com.yeshi.fanli.controller.client.v2;
 
import java.io.PrintWriter;
 
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
 
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 com.yeshi.fanli.entity.accept.AcceptData;
import com.yeshi.fanli.entity.bus.user.SMSHistory;
import com.yeshi.fanli.entity.bus.user.UserInfo;
import com.yeshi.fanli.entity.push.DeviceActive;
import com.yeshi.fanli.entity.system.BusinessSystem;
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.homemodule.HomeNavbarUserService;
import com.yeshi.fanli.service.inter.money.UserMoneyService;
import com.yeshi.fanli.service.inter.order.LostOrderService;
import com.yeshi.fanli.service.inter.order.config.HongBaoManageService;
import com.yeshi.fanli.service.inter.push.DeviceActiveService;
import com.yeshi.fanli.service.inter.push.DeviceTokenHWService;
import com.yeshi.fanli.service.inter.push.DeviceTokenOPPOService;
import com.yeshi.fanli.service.inter.push.DeviceTokenVIVOService;
import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService;
import com.yeshi.fanli.service.inter.tlj.UserTaoLiJinOriginService;
import com.yeshi.fanli.service.inter.user.BindRemindService;
import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService;
import com.yeshi.fanli.service.inter.user.ShamUserService;
import com.yeshi.fanli.service.inter.user.SpreadUserImgService;
import com.yeshi.fanli.service.inter.user.TBPidService;
import com.yeshi.fanli.service.inter.user.UserAccountBindingHistoryService;
import com.yeshi.fanli.service.inter.user.UserAccountService;
import com.yeshi.fanli.service.inter.user.UserInfoDeleteRecordService;
import com.yeshi.fanli.service.inter.user.UserInfoModifyRecordService;
import com.yeshi.fanli.service.inter.user.UserInfoService;
import com.yeshi.fanli.service.inter.user.UserShareGoodsRecordService;
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce;
import com.yeshi.fanli.util.Constant;
import com.yeshi.fanli.util.RedisManager;
import com.yeshi.fanli.util.StringUtil;
import com.yeshi.fanli.util.ThreadUtil;
import com.yeshi.fanli.util.VersionUtil;
import com.yeshi.fanli.util.account.UserUtil;
import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
 
import net.sf.json.JSONObject;
 
/**
 * 账户系统
 * 
 * @author Administrator
 *
 */
@Controller
@RequestMapping("api/v2/user")
public class UserAccountControllerV2 {
 
    @Resource
    private UserInfoService userInfoService;
 
    @Resource
    private BusinessSystemService businessSystemService;
 
    @Resource
    private ShamUserService shamUserService;
 
    @Resource
    private ThreeSaleSerivce threeSaleSerivce;
 
    @Resource
    private LostOrderService lostOrderService;
 
    @Resource
    private HongBaoManageService hongBaoManageService;
 
    @Resource
    private UserAccountService userAccountService;
 
    @Resource
    private RedisManager redisManager;
 
    @Resource
    private TBPidService tbPidService;
 
    @Resource
    private DeviceTokenHWService deviceTokenHWService;
 
    @Resource
    private DeviceTokenOPPOService deviceTokenOPPOService;
 
    @Resource
    private DeviceTokenVIVOService deviceTokenVIVOService;
 
    @Resource
    private TaoBaoUnionConfigService taoBaoUnionConfigService;
 
    @Resource
    private SpreadUserImgService spreadUserImgService;
 
    @Resource
    private UserShareGoodsRecordService userShareGoodsRecordService;
 
    @Resource
    private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
 
    @Resource
    private UserSystemCouponService userSystemCouponService;
 
    @Resource
    private UserMoneyService userMoneyService;
 
    @Resource
    private UserAccountBindingHistoryService userAccountBindingHistoryService;
 
    @Resource
    private HomeNavbarUserService homeNavbarUserService;
 
    @Resource
    private UserInfoDeleteRecordService userInfoDeleteRecordService;
 
    @Resource
    private UserTaoLiJinOriginService userTaoLiJinOriginService;
 
    @Resource
    private UserInfoModifyRecordService userInfoModifyRecordService;
 
    @Resource
    private DeviceActiveService deviceActiveService;
 
    @Resource
    private BindRemindService bindRemindService;
 
    /**
     * 新版登录 V1.5.3
     * 
     * @param acceptData
     * @param vcode
     * @param phone
     * @param code
     * @param loginType
     *            登录方式: 1-手机登录 2-微信登录
     * @param request
     * @param out
     */
    @RequestMapping(value = "login", method = RequestMethod.POST)
    public void login(AcceptData acceptData, int loginType, String vcode, String phone, String code,
            HttpServletRequest request, PrintWriter out) {
        try {
            BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                    acceptData.getPackages());
            if (system == null) {
                out.print(JsonUtil.loadFalseResult("系统不存在"));
                return;
            }
 
            UserInfo userInfo = null;
            // 手机登录
            if (loginType == 1) {
                userInfo = userAccountService.loginPhone(request, loginType, vcode, phone, system.getAppid());
            }
 
            // 微信登录
            if (loginType == 2) {
                userInfo = userAccountService.loginWeiXinNew(request, acceptData, loginType, code, system.getAppid());
            }
 
            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);
                        }
 
                        if (VersionUtil.greaterThan_1_5_60(acceptData.getPlatform(), acceptData.getVersion())) {
                            /* 新人红包 */
                            try {
                                userTaoLiJinOriginService.synchDeviceHongbao(uuser.getId(), device);
                            } catch (Exception e) {
                                e.printStackTrace();
                            }
                        }
 
                        // 绑定oppo,VIVO推送
                        DeviceActive active = deviceActiveService.getFirstActiveInfo(acceptData.getDevice());
                        if (active != null) {
                            deviceTokenOPPOService.bindUid(uuser.getId(), active.getId());
                            deviceTokenVIVOService.bindUid(uuser.getId(), active.getId());
                        }
                    }
                });
            }
 
        } catch (UserAccountException e) {
            int errorCode = e.getCode();
            if (errorCode == 101) { // 需要绑定手机号
                JSONObject data = new JSONObject();
                data.put("key", e.getMsg());
                JSONObject object = new JSONObject();
                object.put("code", errorCode);
                object.put("data", data);
                out.print(object.toString());
            } else {
                out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
                try {
                    LogHelper.cookieLog("登录出错:" + 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();
            }
        }
    }
 
    /**
     * 绑定电话号码 V2.0.1 微信登录
     * 
     * @param acceptData
     * @param vcode
     * @param phone
     * @param out
     */
    @RequestSerializableByKey(key = "'bindPhoneLogin-'+#phone")
    @RequestMapping(value = "bindPhoneLogin")
    public void bindPhoneLogin(AcceptData acceptData, String vcode, String phone, String key,
            HttpServletRequest request, PrintWriter out) {
        BusinessSystem system = businessSystemService.getBusinessSystemCache(acceptData.getPlatform(),
                acceptData.getPackages());
        if (system == null) {
            out.print(JsonUtil.loadFalseResult("系统不存在"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(vcode)) {
            out.print(JsonUtil.loadFalseResult("验证码不能为空"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(phone)) {
            out.print(JsonUtil.loadFalseResult("电话号码不能为空"));
            return;
        }
 
        if (StringUtil.isNullOrEmpty(key)) {
            out.print(JsonUtil.loadFalseResult("key值不能为空"));
            return;
        }
 
        phone = phone.replaceAll(" ", "");
 
        String oldVCode = redisManager.getSMSVCode(phone, SMSHistory.TYPE_BIND);
        if (Constant.IS_OUTNET) {
            if (!vcode.equalsIgnoreCase(oldVCode)) {
                out.print(JsonUtil.loadFalseResult(9001, "验证码错误,重新输入"));
                return;
            }
            redisManager.clearSMSFrequencyLimit(phone, SMSHistory.TYPE_BIND);
        }
 
        try {
            UserInfo userInfo = userAccountService.bindPhoneToLogin(phone, key, system.getAppid(), request);
 
            JSONObject data = new JSONObject();
            data.put("userInfo", UserUtil.filterForClientUser(userInfo));
            out.print(JsonUtil.loadTrueResult(data));
        } catch (UserAccountException e) {
            out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
        } catch (Exception e) {
            out.print(JsonUtil.loadFalseResult(1, "绑定失败"));
        }
    }
 
    /**
     * 绑定电话号码 V2.0.1 微信登录
     * 
     * @param acceptData
     * @param vcode
     * @param phone
     * @param out
     */
    @RequestMapping(value = "recordBind")
    public void recordBind(AcceptData acceptData, Long uid, PrintWriter out) {
        if (uid == null || uid <= 0) {
            out.print(JsonUtil.loadFalseResult("用户id为空"));
            return;
        }
 
        bindRemindService.addBindPhone(uid);
        out.print(JsonUtil.loadTrueResult("记录成功"));
    }
 
}