• 手机版

    扫码体验手机版

  • 微信公众号

    扫码关注公众号

国内首家协议开发

软芯音视解码保护平台

在线
客服

发布
需求

在线
聊天

天盟
APP

天盟APP下载

关注
微信

微信扫一扫访问
顶部

各位大神老师能否帮忙修改一下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())

免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。

版权声明:作者保留权利,不代表天盟立场。

使用道具 举报

全部参与1

longnowTime=System.currentTimeMillis();

if((nowTime- Integer.valueOf(request.getSession.getAtrribute("user_id")))

使用道具 举报

发新帖

发布任务需求已有1031167位用户正在使用天盟网服务

发布分类: *
任务预算: *
需求内容: *
手机号码: *
任务商家报价为
  • 预算价 :
  • 成交价 :
  • 完工期 :
  • 质保期 :

* 最终任务项目以服务商报价、双方协商为准!