| | |
| | | import javax.servlet.http.HttpServletRequest;
|
| | | import javax.servlet.http.HttpSession;
|
| | |
|
| | | import org.aspectj.weaver.JoinPointSignature;
|
| | | import org.springframework.stereotype.Controller;
|
| | | import org.springframework.web.bind.annotation.RequestMapping;
|
| | | import org.yeshi.utils.IPUtil;
|
| | |
| | | import com.yeshi.fanli.dto.WXMPAcceptData;
|
| | | import com.yeshi.fanli.dto.user.wx.WXMPLoginData;
|
| | | import com.yeshi.fanli.dto.user.wx.WXMPLoginResult;
|
| | | import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode;
|
| | | import com.yeshi.fanli.entity.bus.user.ForbiddenUserIdentifyCode.ForbiddenUserIdentifyCodeTypeEnum;
|
| | | import com.yeshi.fanli.entity.bus.user.UserInfo;
|
| | | import com.yeshi.fanli.entity.bus.user.WeiXinUser;
|
| | | import com.yeshi.fanli.exception.user.UserAccountException;
|
| | | import com.yeshi.fanli.exception.user.UserInfoExtraException;
|
| | | import com.yeshi.fanli.service.inter.user.ForbiddenUserIdentifyCodeService;
|
| | | import com.yeshi.fanli.service.inter.user.UserAccountService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoExtraService;
|
| | | import com.yeshi.fanli.service.inter.user.UserInfoService;
|
| | |
| | |
|
| | | @Resource
|
| | | private RedisManager redisManager;
|
| | |
|
| | | @Resource
|
| | | private ForbiddenUserIdentifyCodeService forbiddenUserIdentifyCodeService;
|
| | |
|
| | | /**
|
| | | * 通过邀请码获取用户信息
|
| | |
| | | out.print(JsonUtil.loadTrueResult(data));
|
| | | }
|
| | |
|
| | | @RequestMapping("bindWX")
|
| | | public void bindWX(WXMPAcceptData acceptData, Long uid, String wxEncryptedData, String wxIv,
|
| | | HttpServletRequest request, HttpSession session, PrintWriter out) {
|
| | | if (StringUtil.isNullOrEmpty(acceptData.getOpenId())) {
|
| | | out.print(JsonUtil.loadFalseResult("openId为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | if(uid==null){
|
| | | out.print(JsonUtil.loadFalseResult("uid为空"));
|
| | | return;
|
| | | }
|
| | |
|
| | | if (StringUtil.isNullOrEmpty(wxEncryptedData) || StringUtil.isNullOrEmpty(wxIv)) {
|
| | | out.print(JsonUtil.loadFalseResult("微信信息为空"));
|
| | | return;
|
| | | }
|
| | | |
| | | WXMPSessionInfo sessionInfo = (WXMPSessionInfo) session.getAttribute(UserController.WXMP_SESSION_INFO_KEY);
|
| | | if (sessionInfo == null) {
|
| | | out.print(JsonUtil.loadFalseResult(90000, "请重新登录"));
|
| | | return;
|
| | | }
|
| | |
|
| | | String sessionKey = sessionInfo.getSessionKey();
|
| | | if (StringUtil.isNullOrEmpty(sessionKey)) {
|
| | | out.print(JsonUtil.loadFalseResult("code无效"));
|
| | | return;
|
| | | }
|
| | |
|
| | | WXMPUserInfo userInfo = WXXCXUtil.getUserInfo(sessionKey, wxEncryptedData, wxIv);
|
| | | if (userInfo == null || StringUtil.isNullOrEmpty(userInfo.getUnionId())) {
|
| | | out.print(JsonUtil.loadFalseResult("获取微信信息失败"));
|
| | | return;
|
| | | }
|
| | |
|
| | | // 绑定微信
|
| | |
|
| | | WeiXinUser wxUser = new WeiXinUser();
|
| | | wxUser.setHeadimgurl(userInfo.getAvatarUrl());
|
| | | wxUser.setCity(userInfo.getCity());
|
| | | wxUser.setCountry(userInfo.getCountry());
|
| | | wxUser.setNickname(userInfo.getNickName());
|
| | | wxUser.setOpenid("");
|
| | | wxUser.setProvince(userInfo.getProvince());
|
| | | wxUser.setSex(userInfo.getGender());
|
| | | wxUser.setUnionid(userInfo.getUnionId());
|
| | |
|
| | | try {
|
| | | 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;
|
| | | }
|
| | |
|
| | | userAccountService.bindWeiXin(uid, wxUser);
|
| | | user = userInfoService.getUserByIdWithMybatis(uid);
|
| | | 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()));
|
| | | }
|
| | |
|
| | | }
|
| | |
|
| | | }
|