首页 文章 精选 留言 我的

精选列表

搜索[GitHub后端],共10000篇文章
优秀的个人博客,低调大师

汽车后端开发小技巧:通过 VIN 码查询API,一键获取车辆完整档案

## 一、应用场景 1. **二手车平台**:VIN 一键解析车型配置,自动补齐车源档案,提升上架效率。 2. **车险风控**:投保、定损快速核验车辆信息,辅助保费测算与风险校验。 3. **汽车维保系统**:精准匹配车型、原厂配置与配件,提升维修效率。 4. **车辆资产管理**:车贷、抵押、车队场景批量建档,标准化车辆数据。 ## 二、接口简介 **探数 API VIN 码查询接口**,支持传入标准 17 位车架号,直接返回结构化 JSON 数据,包含信息如下: | 名称 | 类型 | 说明 | | --- | --- | --- | | matching_mode | int | 匹配模式 1 标准车型 2 公告车型 | | is_commercial | int | 是否商用 1 是 0 否 | | cid | string | 车ID,车辆车型大全接口 可查看该车所有配置信息 | | brand_name | string | 品牌名称 | | series_name | string | 车系 | | name | string | 车型车款 | | year | string | 年款 | | price | string | 厂家指导价 | | gearbox | string | 变速箱 | | geartype | string | 变速箱类型 | | engine_model | string | 发动机型号 | | driven_type | string | 驱动方式 | | displacement_ml | string | 排量(mL) | | displacement | string | 排量(L) | | nedczhyh | string | 油耗 | | effluent_standard | string | 环保标准 | | scale | string | 车辆级别 | | csjg | string | 车身结构 | | cms | string | 车门数(个) | | zws | string | 座位数(个) | | market_date | string | 上市时间 | | stop_date | string | 停产日期 | | length | string | 长度(mm) | | width | string | 宽度(mm) | | high | string | 高度(mm) | | wheelbase | string | 轴距(mm) | | trackfront | string | 前轮距(mm) | | trackrear | string | 后轮距(mm) | | full_weight | string | 整备质量(kg) | | front_tyre_size | string | 前轮胎规格 | | rear_tyre_size | string | 后轮胎规格 | | rlxs | string | 燃料形式 | | ryxh | string | 燃油标号 | | gearbox_number | string | 变速箱号 | | chassis_number | string | 底盘号 | | model_list | object | 可能的销售车型列表 | | full_weight_max | string | 最大满载质量(kg) | - `model_list` 返回可能的销售车型列表,例:运动版、旗舰版 ## 三、接入代码示例(Python) ``` import urllib3 # 禁用请求警告 urllib3.disable_warnings() http = urllib3.PoolManager() # 接口地址 url = "https://www.tanshuapi.com/market/detail-66" # 请求头填入你的密钥 headers = { "Authorization": "APPCODE 你的密钥" } # 请求参数,替换为真实17位VIN params = { "vin": "填写17位车架号" } # 发起GET请求 resp = http.request("GET", url, headers=headers, fields=params) # 打印返回结果 print(resp.data.decode("utf-8")) ``` ## 四、开发避坑提示 1. VIN 码字母建议统一转大写后再传入接口,避免大小写导致识别异常; 2. 高频查询场景,可对查询结果增加缓存(Redis),减少调用量; 3. 版本选择 - 私家车 / 二手车平台:选乘用车 VIN - 货车、重卡、车队、货运保险:需要**商用车专用 VIN 接口** 4. **错误码**:VIN 格式错误、无匹配数据、密钥错误; | 错误码 | 说明 | | --- | --- | | 206601 | 缺少必要参数 | | 206602 | 未找到相关数据信息 | | 206603 | 无解码结果! | ## 五、配套相关 API(常一起使用) - VIN 图片 OCR 识别:图片识别车架号文字 - 车辆年检、交强险查询(单独接口) - 车型库查询

优秀的个人博客,低调大师

Java后端开发三年多线程你都懂,问你异步编程你说你没听过???

前言 以前需要异步执行一个任务时,一般是用Thread或者线程池Executor去创建。如果需要返回值,则是调用Executor.submit获取Future。但是多个线程存在依赖组合,我们又能怎么办?可使用同步组件CountDownLatch、CyclicBarrier等;其实有简单的方法,就是用CompletableFuture 线程任务的创建 线程任务的串行执行 线程任务的并行执行 处理任务结果和异常 多任务的简单组合 取消执行线程任务 任务结果的获取和完成与否判断 1、创建异步线程任务 根据supplier创建CompletableFuture任务 //使用内置线程ForkJoinPool.commonPool(),根据supplier构建执行任务 public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier) //指定自定义线程,根据supplier构建执行任务 public static <U> CompletableFuture<U> supplyAsync(Supplier<U> supplier, Executor executor) 根据runnable创建CompletableFuture任务 //使用内置线程ForkJoinPool.commonPool(),根据runnable构建执行任务 public static CompletableFuture<Void> runAsync(Runnable runnable) //指定自定义线程,根据runnable构建执行任务 public static CompletableFuture<Void> runAsync(Runnable runnable, Executor executor) 使用示例 ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<Void> rFuture = CompletableFuture .runAsync(() -> System.out.println("hello siting"), executor); //supplyAsync的使用 CompletableFuture<String> future = CompletableFuture .supplyAsync(() -> { System.out.print("hello "); return "siting"; }, executor); //阻塞等待,runAsync 的future 无返回值,输出null System.out.println(rFuture.join()); //阻塞等待 String name = future.join(); System.out.println(name); executor.shutdown(); // 线程池需要关闭 --------输出结果-------- hello siting null hello siting 常量值作为CompletableFuture返回 //有时候是需要构建一个常量的CompletableFuture public static <U> CompletableFuture<U> completedFuture(U value) 2 、线程串行执行 ​任务完成则运行action,不关心上一个任务的结果,无返回值 public CompletableFuture<Void> thenRun(Runnable action) public CompletableFuture<Void> thenRunAsync(Runnable action) public CompletableFuture<Void> thenRunAsync(Runnable action, Executor executor) 使用示例 CompletableFuture<Void> future = CompletableFuture .supplyAsync(() -> "hello siting", executor) .thenRunAsync(() -> System.out.println("OK"), executor); executor.shutdown(); --------输出结果-------- OK 任务完成则运行action,依赖上一个任务的结果,无返回值 public CompletableFuture<Void> thenAccept(Consumer<? super T> action) public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action) public CompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action, Executor executor) 使用示例 ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<Void> future = CompletableFuture .supplyAsync(() -> "hello siting", executor) .thenAcceptAsync(System.out::println, executor); executor.shutdown(); --------输出结果-------- hello siting 任务完成则运行fn,依赖上一个任务的结果,有返回值 public <U> CompletableFuture<U> thenApply(Function<? super T,? extends U> fn) public <U> CompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn) public <U> CompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor) 使用示例 ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<String> future = CompletableFuture .supplyAsync(() -> "hello world", executor) .thenApplyAsync(data -> { System.out.println(data); return "OK"; }, executor); System.out.println(future.join()); executor.shutdown(); --------输出结果-------- hello world OK thenCompose - 任务完成则运行fn,依赖上一个任务的结果,有返回值 类似thenApply(区别是thenCompose的返回值是CompletionStage,thenApply则是返回 U),提供该方法为了和其他CompletableFuture任务更好地配套组合使用 public <U> CompletableFuture<U> thenCompose(Function<? super T, ? extends CompletionStage<U>> fn) public <U> CompletableFuture<U> thenComposeAsync(Function<? super T, ? extends CompletionStage<U>> fn) public <U> CompletableFuture<U> thenComposeAsync(Function<? super T, ? extends CompletionStage<U>> fn, Executor executor) 使用示例 //第一个异步任务,常量任务 CompletableFuture<String> f = CompletableFuture.completedFuture("OK"); //第二个异步任务 ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<String> future = CompletableFuture .supplyAsync(() -> "hello world", executor) .thenComposeAsync(data -> { System.out.println(data); return f; //使用第一个任务作为返回 }, executor); System.out.println(future.join()); executor.shutdown(); --------输出结果-------- hello world OK 3 、线程并行执行 两个CompletableFuture[并行]执行完,然后执行action,不依赖上两个任务的结果,无返回值 public CompletableFuture<Void> runAfterBoth(CompletionStage<?> other, Runnable action) public CompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action) public CompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor) 使用示例 //第一个异步任务,常量任务 CompletableFuture<String> first = CompletableFuture.completedFuture("hello world"); ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<Void> future = CompletableFuture //第二个异步任务 .supplyAsync(() -> "hello siting", executor) // () -> System.out.println("OK") 是第三个任务 .runAfterBothAsync(first, () -> System.out.println("OK"), executor); executor.shutdown(); --------输出结果-------- OK 两个CompletableFuture[并行]执行完,然后执行action,依赖上两个任务的结果,无返回值 //第一个任务完成再运行other,fn再依赖消费两个任务的结果,无返回值 public <U> CompletableFuture<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) //两个任务异步完成,fn再依赖消费两个任务的结果,无返回值 public <U> CompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action) //两个任务异步完成(第二个任务用指定线程池执行),fn再依赖消费两个任务的结果,无返回值 public <U> CompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T, ? super U> action, Executor executor) 使用示例 //第一个异步任务,常量任务 CompletableFuture<String> first = CompletableFuture.completedFuture("hello world"); ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<Void> future = CompletableFuture //第二个异步任务 .supplyAsync(() -> "hello siting", executor) // (w, s) -> System.out.println(s) 是第三个任务 .thenAcceptBothAsync(first, (s, w) -> System.out.println(s), executor); executor.shutdown(); --------输出结果-------- hello siting 两个CompletableFuture[并行]执行完,然后执行action,依赖上两个任务的结果,有返回值 //第一个任务完成再运行other,fn再依赖消费两个任务的结果,有返回值 public <U,V> CompletableFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn) //两个任务异步完成,fn再依赖消费两个任务的结果,有返回值 public <U,V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn) //两个任务异步完成(第二个任务用指定线程池执行),fn再依赖消费两个任务的结果,有返回值 public <U,V> CompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor) 使用示例 //第一个异步任务,常量任务 CompletableFuture<String> first = CompletableFuture.completedFuture("hello world"); ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<String> future = CompletableFuture //第二个异步任务 .supplyAsync(() -> "hello siting", executor) // (w, s) -> System.out.println(s) 是第三个任务 .thenCombineAsync(first, (s, w) -> { System.out.println(s); return "OK"; }, executor); System.out.println(future.join()); executor.shutdown(); --------输出结果-------- hello siting OK 4 、线程并行执行,谁先执行完则谁触发下一任务(二者选其最快) 上一个任务或者other任务完成, 运行action,不依赖前一任务的结果,无返回值 public CompletableFuture<Void> runAfterEither(CompletionStage<?> other, Runnable action) public CompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action) public CompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor) 使用示例 //第一个异步任务,休眠1秒,保证最晚执行晚 CompletableFuture<String> first = CompletableFuture.supplyAsync(()->{ try{ Thread.sleep(1000); }catch (Exception e){} System.out.println("hello world"); return "hello world"; }); ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<Void> future = CompletableFuture //第二个异步任务 .supplyAsync(() ->{ System.out.println("hello siting"); return "hello siting"; } , executor) //() -> System.out.println("OK") 是第三个任务 .runAfterEitherAsync(first, () -> System.out.println("OK") , executor); executor.shutdown(); --------输出结果-------- hello siting OK 上一个任务或者other任务完成, 运行action,依赖最先完成任务的结果,无返回值 public CompletableFuture<Void> acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action) public CompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) public CompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor) 使用示例 //第一个异步任务,休眠1秒,保证最晚执行晚 CompletableFuture<String> first = CompletableFuture.supplyAsync(()->{ try{ Thread.sleep(1000); }catch (Exception e){} return "hello world"; }); ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<Void> future = CompletableFuture //第二个异步任务 .supplyAsync(() -> "hello siting", executor) // data -> System.out.println(data) 是第三个任务 .acceptEitherAsync(first, data -> System.out.println(data) , executor); executor.shutdown(); --------输出结果-------- hello siting 上一个任务或者other任务完成, 运行fn,依赖最先完成任务的结果,有返回值 public <U> CompletableFuture<U> applyToEither(CompletionStage<? extends T> other, Function<? super T, U> fn) public <U> CompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn) public <U> CompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T, U> fn, Executor executor) 使用示例 //第一个异步任务,休眠1秒,保证最晚执行晚 CompletableFuture<String> first = CompletableFuture.supplyAsync(()->{ try{ Thread.sleep(1000); }catch (Exception e){} return "hello world"; }); ExecutorService executor = Executors.newSingleThreadExecutor(); CompletableFuture<String> future = CompletableFuture //第二个异步任务 .supplyAsync(() -> "hello siting", executor) // data -> System.out.println(data) 是第三个任务 .applyToEitherAsync(first, data -> { System.out.println(data); return "OK"; } , executor); System.out.println(future); executor.shutdown(); --------输出结果-------- hello siting OK 5 、处理任务结果或者异常 exceptionally-处理异常 public CompletableFuture<T> exceptionally(Function<Throwable, ? extends T> fn) 如果之前的处理环节有异常问题,则会触发exceptionally的调用相当于 try...catch 使用示例 CompletableFuture<Integer> first = CompletableFuture .supplyAsync(() -> { if (true) { throw new RuntimeException("main error!"); } return "hello world"; }) .thenApply(data -> 1) .exceptionally(e -> { e.printStackTrace(); // 异常捕捉处理,前面两个处理环节的日常都能捕获 return 0; }); handle-任务完成或者异常时运行fn,返回值为fn的返回 相比exceptionally而言,即可处理上一环节的异常也可以处理其正常返回值 public <U> CompletableFuture<U> handle(BiFunction<? super T, Throwable, ? extends U> fn) public <U> CompletableFuture<U> handleAsync(BiFunction<? super T, Throwable, ? extends U> fn) public <U> CompletableFuture<U> handleAsync(BiFunction<? super T, Throwable, ? extends U> fn, Executor executor) 使用示例 CompletableFuture<Integer> first = CompletableFuture .supplyAsync(() -> { if (true) { throw new RuntimeException("main error!"); } return "hello world"; }) .thenApply(data -> 1) .handleAsync((data,e) -> { e.printStackTrace(); // 异常捕捉处理 return data; }); System.out.println(first.join()); --------输出结果-------- java.util.concurrent.CompletionException: java.lang.RuntimeException: main error! ... 5 more null whenComplete-任务完成或者异常时运行action,有返回值 whenComplete与handle的区别在于,它不参与返回结果的处理,把它当成监听器即可 即使异常被处理,在CompletableFuture外层,异常也会再次复现 使用whenCompleteAsync时,返回结果则需要考虑多线程操作问题,毕竟会出现两个线程同时操作一个结果 public CompletableFuture<T> whenComplete(BiConsumer<? super T, ? super Throwable> action) public CompletableFuture<T> whenCompleteAsync(BiConsumer<? super T, ? super Throwable> action) public CompletableFuture<T> whenCompleteAsync(BiConsumer<? super T, ? super Throwable> action, Executor executor) 使用示例 CompletableFuture<AtomicBoolean> first = CompletableFuture .supplyAsync(() -> { if (true) { throw new RuntimeException("main error!"); } return "hello world"; }) .thenApply(data -> new AtomicBoolean(false)) .whenCompleteAsync((data,e) -> { //异常捕捉处理, 但是异常还是会在外层复现 System.out.println(e.getMessage()); }); first.join(); --------输出结果-------- java.lang.RuntimeException: main error! Exception in thread "main" java.util.concurrent.CompletionException: java.lang.RuntimeException: main error! ... 5 more 6 、多个任务的简单组合 public static CompletableFuture<Void> allOf(CompletableFuture<?>... cfs) public static CompletableFuture<Object> anyOf(CompletableFuture<?>... cfs) 使用示例 CompletableFuture<Void> future = CompletableFuture .allOf(CompletableFuture.completedFuture("A"), CompletableFuture.completedFuture("B")); //全部任务都需要执行完 future.join(); CompletableFuture<Object> future2 = CompletableFuture .anyOf(CompletableFuture.completedFuture("C"), CompletableFuture.completedFuture("D")); //其中一个任务行完即可 future2.join(); 7、取消执行线程任务 // mayInterruptIfRunning 无影响;如果任务未完成,则返回异常 public boolean cancel(boolean mayInterruptIfRunning) //任务是否取消 public boolean isCancelled() 使用示例 CompletableFuture<Integer> future = CompletableFuture .supplyAsync(() -> { try { Thread.sleep(1000); } catch (Exception e) { } return "hello world"; }) .thenApply(data -> 1); System.out.println("任务取消前:" + future.isCancelled()); // 如果任务未完成,则返回异常,需要对使用exceptionally,handle 对结果处理 future.cancel(true); System.out.println("任务取消后:" + future.isCancelled()); future = future.exceptionally(e -> { e.printStackTrace(); return 0; }); System.out.println(future.join()); --------输出结果-------- 任务取消前:false 任务取消后:true java.util.concurrent.CancellationException at java.util.concurrent.CompletableFuture.cancel(CompletableFuture.java:2276) at Test.main(Test.java:25) 0 8、任务的获取和完成与否判断 // 任务是否执行完成 public boolean isDone() //阻塞等待 获取返回值 public T join() // 阻塞等待 获取返回值,区别是get需要返回受检异常 public T get() //等待阻塞一段时间,并获取返回值 public T get(long timeout, TimeUnit unit) //未完成则返回指定value public T getNow(T valueIfAbsent) //未完成,使用value作为任务执行的结果,任务结束。需要future.get获取 public boolean complete(T value) //未完成,则是异常调用,返回异常结果,任务结束 public boolean completeExceptionally(Throwable ex) //判断任务是否因发生异常结束的 public boolean isCompletedExceptionally() //强制地将返回值设置为value,无论该之前任务是否完成;类似complete public void obtrudeValue(T value) //强制地让异常抛出,异常返回,无论该之前任务是否完成;类似completeExceptionally public void obtrudeException(Throwable ex) 使用示例 CompletableFuture<Integer> future = CompletableFuture .supplyAsync(() -> { try { Thread.sleep(1000); } catch (Exception e) { } return "hello world"; }) .thenApply(data -> 1); System.out.println("任务完成前:" + future.isDone()); future.complete(10); System.out.println("任务完成后:" + future.join()); --------输出结果-------- 任务完成前:false 任务完成后:10 总结 Java 多线程一直是面试时候的重点,也是能力提升的重要体现,如何做到波澜不惊,从容面对,需要我们对其中的内容融汇贯通,小编这里也对应总结了一份多线程-并发编程的思维导图,需要的朋友可以看看,关注公众号:麒麟改bug,还可以领取一份包含了Java基础、Java集合容器、Java异常、并发编程、JVM、Spring、Spring MVC、Spring Boot、Spring Cloud、MyBatis、Redis、MySQL数据库、消息中间件MQ与RabbitMQ、Dubbo、Linux、Tomcat、ZooKeeper、Netty、 架构设计&分布式&数据结构与算法等等,都是互联网大厂的面试真题,已经有粉丝靠这份PDF拿下众多大厂的offer。 欢迎大家一起交流,喜欢文章记得关注我点赞哟,感谢支持!

优秀的个人博客,低调大师

web-flash 1.2 发布,基于 Spring Boot&Vue.js 的前后端分离后台管理系统

web-flash 发布将近半年,系统已经趋于稳定,本次没有重大功能更新,主要进行性能的优化和部分组件的例行升级以及bug修复 本次更新内容如下: Change 删除角色时判断是有用户使用该角色,如果有则不允许删除 Change 简化手机站点api地址配置 Change baseService增加缓存功能 Update 升级element-ui至2.11.0 Update 升级Vue全家桶:vue.js(2.6.10),vuex(3.1.1),vue-router(3.0.3),axios(0.18.1),"vue-loader(15.7.0),vue-template-compiler(2.6.10) Change 完善在线文档 Fix bug 本次发布版地址:https://gitee.com/enilu/web-flash/releases/1.2

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

用户登录
用户注册
修改密码
忘记密码