各位大神老师能否帮忙修改一下controller层代码,实现用户在用一时间只能进
操作员扫码的时候是有user_id的,并且操作的时候是有当前的时间的。怎么在那第一次来的时候,把user_id和当前的时间存入到session里面 key是user_id 值是当前时间。下次来的时候如果是相同的user_id 则取出session里对应user_id的值也就是上次的时间值,如果间隔小于1秒那么就是重复访问,就直接return。怎么在代码里实现,帮忙修改一下controller层的代码谢谢
@RequestMapping(value = "/adduserproductmap", method = RequestMethod.GET) private String addUserProductMap(HttpServletRequest request, HttpServletResponse response) throws IOException { // 获取微信授权信息 WechatIden iden = getOperatorInfo(request); if (iden != null) { PersonInfo operator = iden.getPersonInfo(); request.getSession().setAttribute("user", operator); // 获取二维码里state携带的content信息并解码 String qrCodeinfo = new String( URLDecoder.decode(HttpServletRequestUtil.getString(request, "state"), "UTF-8")); ObjectMapper mapper = new ObjectMapper(); WechatInfo wechatInfo = null; try { // 将解码后的内容用aaa去替换掉之前生成二维码的时候加入的aaa前缀,转换成WechatInfo实体类 wechatInfo = mapper.readValue(qrCodeinfo.replace("aaa", "\""), WechatInfo.class); } catch (Exception e) { return "shop/operationfail"; } // 校验二维码是否已经过期 if (!checkQRCodeInfo(wechatInfo)) { return "shop/operationfail"; } // 获取添加消费记录所需要的参数并组建成userproductmap实例 Long productId = wechatInfo.getProductId(); Long customerId = wechatInfo.getCustomerId(); UserProductMap userProductMap = compactUserProductMap4Add(customerId, productId, iden.getPersonInfo()); if (userProductMap != null && customerId != -1) { try { if (!checkShopIden(operator.getUserId(), userProductMap)) { return "shop/operationfail"; } UserProductMapExecution se = service_UserProductMap.addUserProductMap(userProductMap); if (se.getState() == UserProductMapStateEnum.SUCCESS.getState()) { return "shop/operationsuccess"; } } catch (RuntimeException e) { return "shop/operationfail"; }
} } return "shop/operationfail"; }
//根据code获取UserAccessToken,进而通过token里的openId获取微信用户信息
private WechatIden getOperatorInfo(HttpServletRequest request) { String code = request.getParameter("code"); WechatIden iden = null; if (null != code) { UserAccessToken token; try { token = WechatUtil.getUserAccessToken(code); String openId = token.getOpenId(); request.getSession().setAttribute("openId", openId); iden = service_WeChatIden.getWechatIdenByOpenId(openId); } catch (IOException e) { e.printStackTrace(); } } return iden; }
//超过5分钟则认为过期 private boolean checkQRCodeInfo(WechatInfo wechatInfo) { if (wechatInfo != null && wechatInfo.getProductId() != null && wechatInfo.getCustomerId() != null && wechatInfo.getCreateTime() != null) { long nowTime = System.currentTimeMillis(); if ((nowTime - wechatInfo.getCreateTime()) |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|
longnowTime=System.currentTimeMillis();
if((nowTime- Integer.valueOf(request.getSession.getAtrribute("user_id"))) |
|
|
|
|