当前位置:网站首页>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());
}
边栏推荐
猜你喜欢

DTSE Tech Talk丨Phase 2: 1 hour in-depth interpretation of SaaS application system design

字符串复制、拼接、比较以及分割函数总结(一)

huato hot update environment construction (DLL method hot update C# code)

Weka 3.8.6安装与Weka 3.8.6功能介绍

全球架构师峰会

ERROR 2003 (HY000) Can‘t connect to MySQL server on ‘localhost3306‘ (10061)解决办法

592. Fraction Addition and Subtraction

云厂商做生态需要“真连接、真赋能”,用“技术+真金实银”发展伙伴

打印1-100之间的奇数

说几个大厂分库分表的那点破事。
随机推荐
数据的存储
LeetCode167:有序数组两数之和
京东获取推荐商品列表 API
Tensorflow模型量化(Quantization)原理及其实现方法
有没有并发系统设计的经验,我该怎么说?
Test Management and Specification
大厂面试官眼中的好简历到底长啥样
为人处世之道,与君共勉!
Paper reading (63): Get To The Point: Summarization with Pointer-Generator Networks
LeetCode318: Maximum product of word lengths
每日练习------生成13位条形, Ean-13码规则:第十三位数字是前十二位数字经过计算得到的校验码。
腾讯专家献上技术干货,带你一览腾讯广告召回系统的演进
Error occurred while trying to proxy request项目突然起不来了
Invalid or corrupt jarfile xxx.jar
Discuz magazine/news report template (jeavi_line) UTF8-GBK template
2022-07-30 Androd 进入深度休眠后把WIFI给关掉,唤醒之后重新打开WIFI
Explore CSAPP Experiment 2-bomb lab-Section 1
论文阅读 (63):Get To The Point: Summarization with Pointer-Generator Networks
FP6606CMP5 CPC-16L USB类型-C和PD充电控制器 百盛电子代理商
浅谈在线编辑器中增量编译技术的应用