| | |
| | | |
| | | import com.google.gson.GsonBuilder; |
| | | import com.yeshi.buwan.domain.*; |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.exception.LoginUserException; |
| | | import com.yeshi.buwan.exception.SMSException; |
| | | 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.JSONObject; |
| | | 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 |
| | |
| | | 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) { |
| | |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 允许一键登录 |
| | | * |
| | | * @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; |
| | | } |
| | | |
| | | 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())); |
| | | return; |
| | | } catch (Exception e) { |
| | | out.print(JsonUtil.loadFalseJson("短信发送出错,请稍后再试")); |
| | | return; |
| | | } |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | | } |
| | | |
| | | public void getVideoCommentList(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | |
| | | String videoId = request.getParameter("VideoId"); |