当前位置:网站首页>web服务通过用户访问请求判断设备来源
web服务通过用户访问请求判断设备来源
2022-07-30 17:03:00 【漂泊的猎人】
前言:
为了更精准的捕获用户访问类型,对用户的行为进行捕获和分析,同时也为了更少的对现有接口进行改动和兼容,我们需要识别接口请求来源于pc设备还是移动端设备。
1、正则表达式
static String phoneDevicesReg = "\\b(ip(hone|od)|android|opera m(ob|in)i"
+"|windows (phone|ce)|blackberry"
+"|s(ymbian|eries60|amsung)|p(laybook|alm|rofile/midp"
+"|laystation portable)|nokia|fennec|htc[-_]"
+"|mobile|up.browser|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
static String tableDevicesReg = "\\b(ipad|tablet|(Nexus 7)|up.browser"
+"|[1-4][0-9]{2}x[1-4][0-9]{2})\\b";
//移动设备手机端正则匹配
static Pattern phoneDevicesPat = Pattern.compile(phoneDevicesReg, Pattern.CASE_INSENSITIVE);
//移动设备平板端正则匹配
static Pattern tableDevicesPat = Pattern.compile(tableDevicesReg, Pattern.CASE_INSENSITIVE);
2、对移动设备识别标记
public static boolean mobileDevices(HttpServletRequest request){
String userAgent = request.getHeader("USER-AGENT").toLowerCase();
if(null == userAgent){
userAgent = "";
}
// 匹配
Matcher matcherDevicesPhone = phoneDevicesPat.matcher(userAgent);
Matcher matcherDevicesTable = tableDevicesPat.matcher(userAgent);
return (matcherDevicesPhone.find() || matcherDevicesTable.find());
}
边栏推荐
- KDD 2020 | 深入浅出优势特征蒸馏在淘宝推荐中的应用
- 数据预处理:离散特征编码方法
- Paper reading (63): Get To The Point: Summarization with Pointer-Generator Networks
- 向量检索基础方法总结
- HUAWEI CLOUD data governance production line DataArts, let "data 'wisdom' speak"
- 优酷视频元素内容召回系统:多级多模态引擎探索
- Win11如何把d盘空间分给c盘?Win11d盘分盘出来给c盘的方法
- 你是这样的volatile,出乎意料
- Deep Feedback Network for Recommendation
- MySQL 8.0.29 解压版安装教程(亲测有效)
猜你喜欢
随机推荐
MySQL 8.0.29 解压版安装教程(亲测有效)
数据预处理:离散特征编码方法
Various meanings of SQL's PARTITION BY syntax (with examples)
阿里SIM-基于检索的用户行为兴趣CTR模型(Search-based user Interest Model(SIM))
哎,这要人老命的缓存一致问题啊
Chapter 6: Decisive Autumn Moves
Invalid or corrupt jarfile xxx.jar
CMake库搜索函数居然不搜索LD_LIBRARY_PATH
牛客网刷题——运算符问题
初识二叉搜索树
DLCM - 基于列表上下文信息的重排序模型
Public Key Retrieval is not allowed error solution
Discuz magazine/news report template (jeavi_line) UTF8-GBK template
云厂商做生态需要“真连接、真赋能”,用“技术+真金实银”发展伙伴
理解实现搜索二叉树
第5章 SQL高级处理
升级Win11后不喜欢怎么退回Win10系统?
Error occurred while trying to proxy request项目突然起不来了
Google Cloud Spanner的实践经验
No qualifying bean of type问题解决








