| | |
| | | |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.buwan.domain.*; |
| | | import com.yeshi.buwan.domain.system.DetailSystem; |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.dto.user.LoginInfoDto; |
| | | import com.yeshi.buwan.dto.user.QQUserInfo; |
| | | import com.yeshi.buwan.exception.user.LoginUserException; |
| | | import com.yeshi.buwan.exception.SMSException; |
| | | import com.yeshi.buwan.exception.user.RegisterUserException; |
| | | import com.yeshi.buwan.service.imp.CommentService; |
| | | import com.yeshi.buwan.service.imp.MaskKeyService; |
| | | import com.yeshi.buwan.service.imp.SystemService; |
| | | import com.yeshi.buwan.service.imp.UserService; |
| | | import com.yeshi.buwan.service.imp.push.PushService; |
| | | import com.yeshi.buwan.util.JsonUtil; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.service.inter.LoginUserService; |
| | | import com.yeshi.buwan.service.inter.SMSService; |
| | | import com.yeshi.buwan.util.*; |
| | | import com.yeshi.buwan.util.annotation.RequireUid; |
| | | import com.yeshi.buwan.util.wx.MyWXLoginUtil; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.yeshi.utils.entity.wx.WeiXinUser; |
| | | import org.yeshi.utils.wx.WXUtil; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.PrintWriter; |
| | | import java.io.Serializable; |
| | | import java.util.ArrayList; |
| | | import java.util.Calendar; |
| | | import java.util.List; |
| | | |
| | | @Controller |
| | | public class CommentParser { |
| | | |
| | | Logger logger = LoggerFactory.getLogger(CommentParser.class); |
| | | |
| | | @Resource |
| | | private SystemService systemService; |
| | | @Resource |
| | |
| | | private PushService pushService; |
| | | @Resource |
| | | private MaskKeyService maskKeyService; |
| | | |
| | | @Resource |
| | | private LoginUserService loginUserService; |
| | | |
| | | @Resource |
| | | private SMSService smsService; |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | @RequireUid |
| | | public void getReadState(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | |
| | | return; |
| | | } |
| | | |
| | | DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); |
| | | LoginUser lu = userService.getLoginUser(openid, detailSystem.getId(), Integer.parseInt(loginType), portrait, |
| | | name, UserParser.getIp(request) + ":" + request.getRemotePort()); |
| | | LoginInfoDto loginInfoDto = new LoginInfoDto(); |
| | | loginInfoDto.setIpInfo(IPUtil.getRemotIP(request) + ":" + request.getRemotePort()); |
| | | loginInfoDto.setSystemId(acceptData.getDetailSystem().getSystem().getId()); |
| | | |
| | | int loginTypeInt = Integer.parseInt(loginType); |
| | | loginInfoDto.setLoginType(loginTypeInt); |
| | | |
| | | switch (loginTypeInt) { |
| | | case LoginUser.LOGIN_TYPE_EMAIL: |
| | | loginInfoDto.setEmail(openid); |
| | | break; |
| | | case LoginUser.LOGIN_TYPE_QQ: |
| | | QQUserInfo qqUserInfo = new QQUserInfo(); |
| | | qqUserInfo.setName(name); |
| | | qqUserInfo.setOpenId(openid); |
| | | qqUserInfo.setPortrait(portrait); |
| | | qqUserInfo.setSex(sex); |
| | | loginInfoDto.setQqUserInfo(qqUserInfo); |
| | | break; |
| | | } |
| | | |
| | | |
| | | LoginUser lu = null; |
| | | try { |
| | | lu = userService.login(loginInfoDto); |
| | | if (lu == null) { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | return; |
| | | } |
| | | } catch (LoginUserException e) { |
| | | //用户不存在 |
| | | if (e.getCode() == LoginUserException.CODE_NO_USER && loginTypeInt != LoginUser.LOGIN_TYPE_EMAIL) { |
| | | //注册 |
| | | try { |
| | | lu = userService.register(loginInfoDto); |
| | | } catch (RegisterUserException e1) { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | return; |
| | | } |
| | | |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |
| | | return; |
| | | } |
| | | } |
| | | if (lu != null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("LoginUid", lu.getId()); |
| | | object.put("Portrait", lu.getPortrait()); |
| | | object.put("NickName", lu.getName()); |
| | | out.print(JsonUtil.loadTrueJson(object.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | //通过code换取个人信息 |
| | | WeiXinUser weiXinUser = MyWXLoginUtil.getUserInfo(code, MyWXLoginUtil.WEIXIN_APPID, MyWXLoginUtil.WEIXIN_SECRET); |
| | | try { |
| | | logger.error("微信登录:" + new GsonBuilder().create().toJson(weiXinUser)); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | if (weiXinUser == null) { |
| | | out.print(JsonUtil.loadFalseJson("获取授权信息失败,请稍后再试")); |
| | | return; |
| | | } |
| | | |
| | | LoginInfoDto loginInfoDto = new LoginInfoDto(); |
| | | loginInfoDto.setSystemId(acceptData.getDetailSystem().getSystem().getId()); |
| | | loginInfoDto.setLoginType(LoginUser.LOGIN_TYPE_WX); |
| | | loginInfoDto.setWeiXinUser(weiXinUser); |
| | | loginInfoDto.setIpInfo(IPUtil.getRemotIP(request) + ":" + request.getRemotePort()); |
| | | |
| | | |
| | | try { |
| | | LoginUser lu = userService.login(loginInfoDto); |
| | | if (lu != null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu)); |
| | | out.print(JsonUtil.loadTrueJson(object.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | } |
| | | } catch (LoginUserException e) { |
| | | //用户不存在 |
| | | if (e.getCode() == LoginUserException.CODE_NO_USER) { |
| | | //注册 |
| | | try { |
| | | LoginUser lu = userService.register(loginInfoDto); |
| | | if (lu != null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu)); |
| | | out.print(JsonUtil.loadTrueJson(object.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | } |
| | | } catch (RegisterUserException e1) { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | } |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 允许一键登录 |
| | | * |
| | | * @param acceptData |
| | | * @param request |
| | | * @param out |
| | | */ |
| | | public void allowOneKeyLogin(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | Long loginUid = StringUtil.isNullOrEmpty(request.getParameter("loginUid")) ? null : Long.parseLong(request.getParameter("loginUid")); |
| | | if (loginUid == null || loginUid == 0L) { |
| | | out.print(JsonUtil.loadFalseJson("尚未登录")); |
| | | return; |
| | | } |
| | | String device = request.getParameter("Device"); |
| | | long time = System.currentTimeMillis(); |
| | | |
| | | String key = "onkeylogin-" + StringUtil.Md5(device + "#" + TimeUtil.getGernalTime(time, "yyyyMMdd")); |
| | | |
| | | //一个设备一天之内只能允许5次 |
| | | String value = redisManager.getCommonString(key); |
| | | if (!StringUtil.isNullOrEmpty(value) && Integer.parseInt(value) > 10) { |
| | | out.print(JsonUtil.loadFalseJson("一键登录次数超限,请明天再试")); |
| | | return; |
| | | } |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 电话号码绑定 |
| | | * |
| | | * @param acceptData |
| | | * @param request |
| | | * @param out |
| | | */ |
| | | public void bindPhone(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | Long loginUid = StringUtil.isNullOrEmpty(request.getParameter("loginUid")) ? null : Long.parseLong(request.getParameter("loginUid")); |
| | | String phone = request.getParameter("phone"); |
| | | String code = request.getParameter("code"); |
| | | String accessToken = request.getParameter("accessToken"); |
| | | String systemId = request.getParameter("system"); |
| | | String device = request.getParameter("Device"); |
| | | |
| | | long time = System.currentTimeMillis(); |
| | | |
| | | |
| | | if (loginUid == null || loginUid == 0L) { |
| | | out.print(JsonUtil.loadFalseJson("尚未登录")); |
| | | return; |
| | | } |
| | | |
| | | String mobile = null; |
| | | if (!StringUtil.isNullOrEmpty(accessToken)) { |
| | | //一键登录 |
| | | mobile = AliyunOneKeyLoginUtil.getMobile(accessToken, ""); |
| | | |
| | | //增加一键登录的次数 |
| | | String key = "onkeylogin-" + StringUtil.Md5(device + "#" + TimeUtil.getGernalTime(time, "yyyyMMdd")); |
| | | Calendar calendar = Calendar.getInstance(); |
| | | calendar.setTimeInMillis(time); |
| | | calendar.add(Calendar.DAY_OF_WEEK, 1); |
| | | int s = (int) ((TimeUtil.convertGernalTime(TimeUtil.getGernalTime(calendar.getTimeInMillis(), "yyyyMMdd"), "yyyyMMdd") - time) / 1000); |
| | | redisManager.increase(key, s); |
| | | } else { |
| | | //通过验证码登录 |
| | | //判断验证码是否正确 |
| | | |
| | | if (StringUtil.isNullOrEmpty(phone)) { |
| | | out.print(JsonUtil.loadFalseJson("电话号码不能为空")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(code)) { |
| | | out.print(JsonUtil.loadFalseJson("验证码不能为空")); |
| | | return; |
| | | } |
| | | |
| | | if (!smsService.verifyBindVCode(phone, code)) { |
| | | out.print(JsonUtil.loadFalseJson("验证码错误")); |
| | | return; |
| | | } |
| | | mobile = phone; |
| | | } |
| | | |
| | | try { |
| | | loginUserService.bindPhone(loginUid + "", mobile); |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | | } catch (LoginUserException e) { |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |
| | | } |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 绑定QQ |
| | | * |
| | | * @param acceptData |
| | | * @param request |
| | | * @param out |
| | | */ |
| | | public void bindQQ(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | Long loginUid = StringUtil.isNullOrEmpty(request.getParameter("loginUid")) ? null : Long.parseLong(request.getParameter("loginUid")); |
| | | String name = request.getParameter("Name"); |
| | | String portrait = request.getParameter("Portrait"); |
| | | String openId = request.getParameter("OpenId"); |
| | | String systemId = request.getParameter("system"); |
| | | if (loginUid == null || loginUid == 0L) { |
| | | out.print(JsonUtil.loadFalseJson("尚未登录")); |
| | | return; |
| | | } |
| | | if (StringUtil.isNullOrEmpty(openId)) { |
| | | out.print(JsonUtil.loadFalseJson("授权信息为空")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | loginUserService.bindQQ(loginUid + "", openId, name, portrait); |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | | } catch (LoginUserException e) { |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 绑定微信 |
| | | * |
| | | * @param acceptData |
| | | * @param request |
| | | * @param out |
| | | */ |
| | | public void bindWX(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | Long loginUid = StringUtil.isNullOrEmpty(request.getParameter("loginUid")) ? null : Long.parseLong(request.getParameter("loginUid")); |
| | | String code = request.getParameter("code"); |
| | | if (loginUid == null || loginUid == 0L) { |
| | | out.print(JsonUtil.loadFalseJson("尚未登录")); |
| | | return; |
| | | } |
| | | if (StringUtil.isNullOrEmpty(code)) { |
| | | out.print(JsonUtil.loadFalseJson("code为空")); |
| | | return; |
| | | } |
| | | |
| | | //通过code换取个人信息 |
| | | WeiXinUser weiXinUser = MyWXLoginUtil.getUserInfo(code, MyWXLoginUtil.WEIXIN_APPID, MyWXLoginUtil.WEIXIN_SECRET); |
| | | |
| | | if (weiXinUser == null) { |
| | | out.print(JsonUtil.loadFalseJson("获取授权信息失败")); |
| | | return; |
| | | } |
| | | |
| | | DetailSystem detailSystem = systemService.getDetailSystemByPackage(acceptData.getPackageName()); |
| | | |
| | | |
| | | LoginUser lu = userService.getLoginUser(weiXinUser.getOpenid(), detailSystem.getId(), 2, weiXinUser.getHeadimgurl(), |
| | | weiXinUser.getNickname(), UserParser.getIp(request) + ":" + request.getRemotePort()); |
| | | if (lu != null) { |
| | | JSONObject object = new JSONObject(); |
| | | object.put("user", new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(lu)); |
| | | out.print(JsonUtil.loadTrueJson(object.toString())); |
| | | } else { |
| | | out.print(JsonUtil.loadFalseJson("登录失败")); |
| | | try { |
| | | loginUserService.bindWX(loginUid + "", weiXinUser); |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | | } catch (LoginUserException e) { |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 发送电话号码绑定验证码 |
| | | * |
| | | * @param acceptData |
| | | * @param request |
| | | * @param out |
| | | */ |
| | | public void sendBindVerifyCode(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | String loginUid = request.getParameter("loginUid"); |
| | | String phone = request.getParameter("phone"); |
| | | |
| | | |
| | | if (StringUtil.isNullOrEmpty(phone)) { |
| | | out.print(JsonUtil.loadFalseJson("电话号码不能为空")); |
| | | return; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(loginUid)) { |
| | | out.print(JsonUtil.loadFalseJson("用户尚未登录")); |
| | | return; |
| | | } |
| | | |
| | | LoginUser loginUser = userService.getLoginUser(loginUid + ""); |
| | | if (loginUser == null) { |
| | | out.print(JsonUtil.loadFalseJson("用户不存在")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | smsService.sendBindVCode(loginUid, phone, 6); |
| | | } catch (SMSException e) { |
| | | e.printStackTrace(); |
| | | out.print(JsonUtil.loadFalseJson(e.getMessage())); |
| | | logger.error("发送验证码出错:phone-{} msg-{}",phone,e.getMessage(),e); |
| | | return; |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseJson("短信发送出错,请稍后再试")); |
| | | logger.error("发送验证码出错:phone-{} msg-{}",phone,e.getMessage(),e); |
| | | return; |
| | | } |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | | } |
| | | |
| | | |
| | | |
| | | public void getVideoCommentList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | |
| | | String videoId = request.getParameter("VideoId"); |