拦截用户登录切面分析
来源:互联网 发布:qt网络编程 tcp连接 编辑:程序博客网 时间:2024/05/16 12:49
1.aop 标注的使用
2.joinpoint
3.使用httpclient 在java程序中直接获取网络资源
4.NameValuePair类的使用
5.根据用户id获取地址信息的api:http://api.map.baidu.com/location/ip
例子 http://api.map.baidu.com/location/ip?ak=DA01fc8690585960288eb3820c5f5bf7&ip="+ip+"&coor=bd09ll
6.
public void recordUserRegon(JoinPoint joinPoint){Object[] os=joinPoint.getArgs();//获取登录时传入的用户ipUser user=(User) (os[0]);String ip=user.getIp();Long userId=user.getId();//创建redisRedisUtil4 redis=new RedisUtil4();String coor="bd09ll";List<NameValuePair> nvps = new ArrayList<NameValuePair>();nvps.add(new BasicNameValuePair("ip",ip));nvps.add(new BasicNameValuePair("ak","7f1e2da824f3bf559861ec7dfb1831a9"));nvps.add(new BasicNameValuePair("coor",coor));try {JSONObject result = JSONObject.fromObject(HttpClientUtil.post("http://api.map.baidu.com/location/ip",nvps));if(result.getInt("status")==0){//获取区域contentJSONObject content=result.getJSONObject("content");//获取详细地址信息JSONObject address_detail=content.getJSONObject("address_detail");//获取坐标信息JSONObject point=content.getJSONObject("point");UserRegion userRegion=new UserRegion();userRegion.setUserId(userId);userRegion.setCity(address_detail.getString("city"));userRegion.setCityCode(address_detail.getInt("city_code"));userRegion.setCoorType(coor);userRegion.setProvince(address_detail.getString("province"));userRegion.setDistrict(address_detail.getString("district"));userRegion.setLatitude(point.getDouble("y"));userRegion.setLongitude(point.getDouble("x"));userRegion.setIp(ip);//获取用户登录的区域代码userRegion.setRegioncode(userDao.selectUserRegionCode(userRegion).getRegioncode());if(userDao.replaceUserRegion(userRegion)>0){redis.updateUsr(userRegion.getUserId(), "city",userRegion.getCity());redis.updateUsr(userRegion.getUserId(), "citycode",userRegion.getCityCode().toString());redis.updateUsr(userRegion.getUserId(), "province",userRegion.getProvince());redis.updateUsr(userRegion.getUserId(), "district",userRegion.getDistrict());redis.updateUsr(userRegion.getUserId(), "latitude",userRegion.getLatitude().toString());redis.updateUsr(userRegion.getUserId(), "longitude",userRegion.getLongitude().toString());}}} catch (Exception e) {e.printStackTrace();}finally{redis.close();}}
httpclient.post 源码
public static String post(String url, List<NameValuePair> params)throws Exception {String body = null;// Post请求HttpPost httppost = new HttpPost(url);// 设置参数UrlEncodedFormEntity req = new UrlEncodedFormEntity(params, "utf-8");httppost.setEntity(req);// 发送请求CloseableHttpClient hc = getHttpClient();HttpResponse httpresponse = hc.execute(httppost);// 获取返回数据HttpEntity entity = httpresponse.getEntity();body = EntityUtils.toString(entity);if (entity != null) {entity.consumeContent();}hc.close();return body;}
0 0
- 拦截用户登录切面分析
- 用户登录拦截器
- springmvc拦截器,用户登录拦截过程
- struts2拦截器--拦截未登录用户
- java用户登录拦截判断
- spring 用户登录拦截器
- SSM使用AOP切面获取用户登录操作日志
- struts2 拦截器控制用户登录权限
- struts2用户登录拦截器测试
- 利用Filter对用户登录进行拦截
- web开发利用filter拦截未登录用户
- 拦截器验证用户是否登录
- JavaWeb实现用户登录的拦截
- java-web实现拦截未登录用户
- Struts2拦截器—自定义拦截器验证用户登录
- 在springmvc配置拦截器拦截未登录用户操作
- springmvc 自定义拦截器实现未登录用户的拦截
- ejabberd分析(四) 用户登录
- 使用Qt的qmake管理boost::filesystem代码时出现LNK2019问题
- 8张图理解Java
- 使用 JWT 让你的 RESTful API 更安全
- Ubuntu 删除两个文件夹下相同文件名的文件(内容也完全相同)
- Convert Sorted List to Binary Search Tree LeetCode
- 拦截用户登录切面分析
- tableHeaderView的Masonry
- STL 的各个版本
- 编译glew
- volley为什么能够支持android-6.0
- Linux下端口占用查看
- 一个调用webservice的php基类
- Xcode compile rocket always failed with exit code 5
- PS制作各种效果汇总