Java调用Http/Https接口(5)--HttpAsyncClient调用Http/Https接口
HttpAsyncClient是HttpClient的异步版本,提供异步调用的api。文中所使用到的软件版本:Java 1.8.0_191、HttpClient 4.1.4。
1、服务端
2、调用Http接口
2.1、GET请求
public static void get() {
String requestPath = "http://localhost:8080/demo/httptest/getUser?userId=1000&userName=李白";
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
HttpGet get = new HttpGet(requestPath);
Future<HttpResponse> future = httpClient.execute(get, null);
HttpResponse response = future.get();
System.out.println("GET返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("GET返回结果:" + EntityUtils.toString(responseEntity));
//回调方式调用
final CountDownLatch latch = new CountDownLatch(1);
final HttpGet get2 = new HttpGet(requestPath);
httpClient.execute(get2, new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse response) {
latch.countDown();
System.out.println("GET(回调方式)返回状态:" + response.getStatusLine());
try {
System.out.println("GET(回调方式)返回结果:" + EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
public void failed(final Exception e) {
latch.countDown();
e.printStackTrace();
}
public void cancelled() {
latch.countDown();
System.out.println("cancelled");
}
});
latch.await();
//流方式调用
final CountDownLatch latch2 = new CountDownLatch(1);
final HttpGet get3 = new HttpGet(requestPath);
HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(get3);
AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
HttpResponse response;
@Override
protected void onResponseReceived(final HttpResponse response) {
this.response = response;
}
@Override
protected void releaseResources() {
}
@Override
protected HttpResponse buildResult(final HttpContext context) {
return this.response;
}
@Override
protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
System.out.println("GET(流方式)返回结果:" + buf.toString());
}
};
httpClient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse response) {
latch2.countDown();
System.out.println("GET(流方式)返回状态:" + response.getStatusLine());
}
public void failed(final Exception e) {
latch2.countDown();
e.printStackTrace();
}
public void cancelled() {
latch2.countDown();
System.out.println("cancelled");
}
});
latch2.await();
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.2、POST请求(发送键值对数据)
public static void post() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/getUser";
HttpPost post = new HttpPost(requestPath);
List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("userId", "1000"));
list.add(new BasicNameValuePair("userName", "李白"));
post.setEntity(new UrlEncodedFormEntity(list, "utf-8"));
Future<HttpResponse> future = httpClient.execute(post, null);
HttpResponse response = future.get();
System.out.println("POST返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("POST返回结果:" + EntityUtils.toString(responseEntity));
//回调方式和流方式调用类似
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.3、POST请求(发送JSON数据)
public static void post2() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/addUser";
HttpPost post = new HttpPost(requestPath);
post.setHeader("Content-type", "application/json");
String param = "{\"userId\": \"1001\",\"userName\":\"杜甫\"}";
post.setEntity(new StringEntity(param, "utf-8"));
Future<HttpResponse> future = httpClient.execute(post, null);
HttpResponse response = future.get();
System.out.println("POST json返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("POST josn返回结果:" + EntityUtils.toString(responseEntity));
//回调方式和流方式调用类似
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.4、上传文件
public static void upload() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/upload";
ZeroCopyPost producer = new ZeroCopyPost(requestPath, new File("d:/a.jpg"), ContentType.create("text/plain"));
AsyncCharConsumer<HttpResponse> consumer = new AsyncCharConsumer<HttpResponse>() {
HttpResponse response;
@Override
protected void onResponseReceived(final HttpResponse response) {
this.response = response;
}
@Override
protected void releaseResources() {
}
@Override
protected HttpResponse buildResult(final HttpContext context) {
return this.response;
}
@Override
protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
System.out.println("upload返回结果:" + buf.toString());
}
};
Future<HttpResponse> future = httpClient.execute(producer, consumer, null);
HttpResponse response = future.get();
System.out.println("upload返回状态:" + response.getStatusLine());
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.5、下载文件
public static void download() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/download";
HttpGet get = new HttpGet(requestPath);
HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
File download = new File("d:/temp/download_" + System.currentTimeMillis() + ".jpg");
ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
@Override
protected File process(final HttpResponse response, final File file, final ContentType contentType) throws Exception {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
}
return file;
}
};
Future<File> future = httpClient.execute(producer, consumer, null);
System.out.println("download文件大小:" + future.get().length());
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
}
2.6、完整例子
package com.inspur.demo.http.client; import java.io.File;
import java.io.IOException;
import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.nio.IOControl;
import org.apache.http.nio.client.methods.AsyncCharConsumer;
import org.apache.http.nio.client.methods.HttpAsyncMethods;
import org.apache.http.nio.client.methods.ZeroCopyConsumer;
import org.apache.http.nio.client.methods.ZeroCopyPost;
import org.apache.http.nio.protocol.HttpAsyncRequestProducer;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils; /**
* 通过HttpClient调用Http接口
*/
public class HttpAsyncClientCase {
/**
* GET请求
*/
public static void get() {
String requestPath = "http://localhost:8080/demo/httptest/getUser?userId=1000&userName=李白";
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
HttpGet get = new HttpGet(requestPath);
Future<HttpResponse> future = httpClient.execute(get, null);
HttpResponse response = future.get();
System.out.println("GET返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("GET返回结果:" + EntityUtils.toString(responseEntity)); //回调方式调用
final CountDownLatch latch = new CountDownLatch(1);
final HttpGet get2 = new HttpGet(requestPath);
httpClient.execute(get2, new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse response) {
latch.countDown();
System.out.println("GET(回调方式)返回状态:" + response.getStatusLine());
try {
System.out.println("GET(回调方式)返回结果:" + EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
}
}
public void failed(final Exception e) {
latch.countDown();
e.printStackTrace();
}
public void cancelled() {
latch.countDown();
System.out.println("cancelled");
} });
latch.await(); //流方式调用
final CountDownLatch latch2 = new CountDownLatch(1);
final HttpGet get3 = new HttpGet(requestPath);
HttpAsyncRequestProducer producer3 = HttpAsyncMethods.create(get3);
AsyncCharConsumer<HttpResponse> consumer3 = new AsyncCharConsumer<HttpResponse>() {
HttpResponse response;
@Override
protected void onResponseReceived(final HttpResponse response) {
this.response = response;
}
@Override
protected void releaseResources() {
}
@Override
protected HttpResponse buildResult(final HttpContext context) {
return this.response;
}
@Override
protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
System.out.println("GET(流方式)返回结果:" + buf.toString());
}
};
httpClient.execute(producer3, consumer3, new FutureCallback<HttpResponse>() {
public void completed(final HttpResponse response) {
latch2.countDown();
System.out.println("GET(流方式)返回状态:" + response.getStatusLine());
}
public void failed(final Exception e) {
latch2.countDown();
e.printStackTrace();
}
public void cancelled() {
latch2.countDown();
System.out.println("cancelled");
}
});
latch2.await();
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} /**
* POST请求(发送键值对数据)
*/
public static void post() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/getUser";
HttpPost post = new HttpPost(requestPath); List<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("userId", "1000"));
list.add(new BasicNameValuePair("userName", "李白"));
post.setEntity(new UrlEncodedFormEntity(list, "utf-8")); Future<HttpResponse> future = httpClient.execute(post, null);
HttpResponse response = future.get();
System.out.println("POST返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("POST返回结果:" + EntityUtils.toString(responseEntity)); //回调方式和流方式调用类似
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} /**
* POST请求(发送json数据)
*/
public static void post2() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/addUser";
HttpPost post = new HttpPost(requestPath);
post.setHeader("Content-type", "application/json");
String param = "{\"userId\": \"1001\",\"userName\":\"杜甫\"}";
post.setEntity(new StringEntity(param, "utf-8")); Future<HttpResponse> future = httpClient.execute(post, null);
HttpResponse response = future.get();
System.out.println("POST json返回状态:" + response.getStatusLine());
HttpEntity responseEntity = response.getEntity();
System.out.println("POST josn返回结果:" + EntityUtils.toString(responseEntity)); //回调方式和流方式调用类似
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} /**
* 上传文件
*/
public static void upload() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/upload";
ZeroCopyPost producer = new ZeroCopyPost(requestPath, new File("d:/a.jpg"), ContentType.create("text/plain"));
AsyncCharConsumer<HttpResponse> consumer = new AsyncCharConsumer<HttpResponse>() {
HttpResponse response;
@Override
protected void onResponseReceived(final HttpResponse response) {
this.response = response;
}
@Override
protected void releaseResources() {
}
@Override
protected HttpResponse buildResult(final HttpContext context) {
return this.response;
}
@Override
protected void onCharReceived(CharBuffer buf, IOControl ioctrl) throws IOException {
System.out.println("upload返回结果:" + buf.toString());
}
};
Future<HttpResponse> future = httpClient.execute(producer, consumer, null);
HttpResponse response = future.get();
System.out.println("upload返回状态:" + response.getStatusLine());
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} /**
* 下载文件
*/
public static void download() {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
try {
httpClient.start();
String requestPath = "http://localhost:8080/demo/httptest/download";
HttpGet get = new HttpGet(requestPath);
HttpAsyncRequestProducer producer = HttpAsyncMethods.create(get);
File download = new File("d:/temp/download_" + System.currentTimeMillis() + ".jpg");
ZeroCopyConsumer<File> consumer = new ZeroCopyConsumer<File>(download) {
@Override
protected File process(final HttpResponse response, final File file, final ContentType contentType) throws Exception {
if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
throw new ClientProtocolException("Upload failed: " + response.getStatusLine());
}
return file;
}
};
Future<File> future = httpClient.execute(producer, consumer, null);
System.out.println("download文件大小:" + future.get().length());
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpClient);
}
} private static void close(CloseableHttpAsyncClient httpClient) {
try {
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} public static void main(String[] args) {
get();
post();
post2();
upload();
download();
}
}
3、调用Https接口
与调用Http接口不一样的部分主要在设置ssl部分,其ssl的设置与HttpsURLConnection很相似(参见Java调用Http/Https接口(2)--HttpURLConnection/HttpsURLConnection调用Http/Https接口);下面用GET请求来演示ssl的设置,其他调用方式类似。
package com.inspur.demo.http.client; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.security.KeyStore;
import java.util.concurrent.Future; import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession; import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.impl.nio.client.CloseableHttpAsyncClient;
import org.apache.http.impl.nio.client.HttpAsyncClients;
import org.apache.http.nio.conn.ssl.SSLIOSessionStrategy;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.ssl.SSLContexts;
import org.apache.http.util.EntityUtils; import com.inspur.demo.common.util.FileUtil; /**
* 通过HttpAsyncClient调用Https接口
*/
public class HttpAsyncClientHttpsCase { public static void main(String[] args) {
CloseableHttpAsyncClient httpAsyncClient = null;
CloseableHttpAsyncClient httpAsyncClient2 = null;
CloseableHttpAsyncClient httpAsyncClient3 = null;
try {
/*
* 请求有权威证书的地址
*/
String requestPath = "https://www.12306.cn/index/";
httpAsyncClient = HttpAsyncClients.createDefault();
httpAsyncClient.start();
HttpGet get = new HttpGet(requestPath);
Future<HttpResponse> future = httpAsyncClient.execute(get, null);
HttpResponse response = future.get();
System.out.println(response.getStatusLine());
System.out.println("GET1返回结果:" + EntityUtils.toString(response.getEntity(), "utf-8")); /*
* 请求自定义证书的地址
*/
//获取信任证书库
KeyStore trustStore = getkeyStore("jks", "d:/temp/cacerts", "123456");
//不需要客户端证书
requestPath = "https://10.40.x.x:9010/zsywservice";
httpAsyncClient2 = HttpAsyncClients.custom().setSSLStrategy(getSSLIOSessionStrategy(trustStore)).build();
httpAsyncClient2.start();
get = new HttpGet(requestPath);
future = httpAsyncClient2.execute(get, null);
response = future.get();
System.out.println("GET2:" + EntityUtils.toString(response.getEntity())); //需要客户端证书
requestPath = "https://10.40.x.x:9016/zsywservice";
KeyStore keyStore = getkeyStore("pkcs12", "d:/client.p12", "123456");
httpAsyncClient3 = HttpAsyncClients.custom().setSSLStrategy(getSSLIOSessionStrategy(keyStore, "123456", trustStore)).build();
httpAsyncClient3.start();
get = new HttpGet(requestPath);
future = httpAsyncClient3.execute(get, null);
response = future.get();
System.out.println("GET3返回结果:" + EntityUtils.toString(response.getEntity()));
} catch (Exception e) {
e.printStackTrace();
} finally {
close(httpAsyncClient);
close(httpAsyncClient2);
close(httpAsyncClient3);
}
} public static SSLIOSessionStrategy getSSLIOSessionStrategy(KeyStore keyStore, String keyPassword, KeyStore trustStore) throws Exception {
SSLContextBuilder bulider = SSLContexts.custom();
if (keyStore != null) {
bulider.loadKeyMaterial(keyStore, keyPassword.toCharArray());
}
if (keyStore != null) {
bulider.loadTrustMaterial(trustStore, null);
} else {
bulider.loadTrustMaterial(new TrustSelfSignedStrategy());
}
SSLContext sslContext = bulider.build();
// 验证URL的主机名和服务器的标识主机名是否匹配
HostnameVerifier hostnameVerifier = new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// if ("xxx".equals(hostname)) {
// return true;
// } else {
// return false;
// }
return true;
}
};
SSLIOSessionStrategy strategy = new SSLIOSessionStrategy(sslContext, new String[] { "TLSv1", "TLSv1.2" }, null,
hostnameVerifier); return strategy;
} public static SSLIOSessionStrategy getSSLIOSessionStrategy(KeyStore trustStore) throws Exception {
return getSSLIOSessionStrategy(null, null, trustStore);
} private static KeyStore getkeyStore(String type, String filePath, String password) {
KeyStore keySotre = null;
FileInputStream in = null;
try {
keySotre = KeyStore.getInstance(type);
in = new FileInputStream(new File(filePath));
keySotre.load(in, password.toCharArray());
} catch (Exception e) {
e.printStackTrace();
} finally {
FileUtil.close(in);
}
return keySotre;
} private static void close(CloseableHttpAsyncClient httpClient) {
try {
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
} }
Java调用Http/Https接口(5)--HttpAsyncClient调用Http/Https接口的更多相关文章
- Java WebService接口生成和调用 图文详解>【转】【待调整】
webservice简介: Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的.专门的第三方软件或硬件, 就可相互交换数据或集成.依据Web Service规范实施的应用之间 ...
- c#代码 天气接口 一分钟搞懂你的博客为什么没人看 看完python这段爬虫代码,java流泪了c#沉默了 图片二进制转换与存入数据库相关 C#7.0--引用返回值和引用局部变量 JS直接调用C#后台方法(ajax调用) Linq To Json SqlServer 递归查询
天气预报的程序.程序并不难. 看到这个需求第一个想法就是只要找到合适天气预报接口一切都是小意思,说干就干,立马跟学生沟通价格. 不过谈报价的过程中,差点没让我一口老血喷键盘上,话说我们程序猿的人 ...
- java接口对接——别人调用我们接口获取数据
java接口对接——别人调用我们接口获取数据,我们需要在我们系统中开发几个接口,给对方接口规范文档,包括访问我们的接口地址,以及入参名称和格式,还有我们的返回的状态的情况, 接口代码: package ...
- .net WebServer示例及调用(接口WSDL动态调用 JAVA)
新建.asmx页面 using System; using System.Collections.Generic; using System.Linq; using System.Web; using ...
- 使用Socket&反射&Java流操作进行方法的远程调用(模拟RPC远程调用)
写在前面 阅读本文首先得具备基本的Socket.反射.Java流操作的基本API使用知识:否则本文你可能看不懂... 服务端的端口监听 进行远程调用,那就必须得有客户端和服务端.服务端负责提供服务,客 ...
- java多态的实现原理(JVM调用过程)(综合多篇文章,参考见文末)
一个对象变量可以指示多种实际类型的现象称为多态 允许不同类的对象对同一消息做出响应.方法的重载.类的覆盖正体现了多态. 1.多态的机制 1.1 本质上多态分两种 1.编译时多态(又称静态多态) 2.运 ...
- 从Java future 到 Guava ListenableFuture实现异步调用
从Java future 到 Guava ListenableFuture实现异步调用 置顶 2016年04月24日 09:11:14 皮斯特劳沃 阅读数:17570 标签: java异步调用线程非阻 ...
- Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结
Atitit java c# php c++ js跨语言调用matlab实现边缘检测等功能attilax总结 1.1. 边缘检测的基本方法Canny最常用了1 1.2. 编写matlab边缘检测代码, ...
- 【Java EE 学习 80 下】【调用WebService服务的四种方式】【WebService中的注解】
不考虑第三方框架,如果只使用JDK提供的API,那么可以使用三种方式调用WebService服务:另外还可以使用Ajax调用WebService服务. 预备工作:开启WebService服务,使用jd ...
随机推荐
- Java NIO 文件通道使用
读取一个文件的内容,然后写入另外一个文件 public class NioTest4 { public static void main(String[] args) throws Exception ...
- httpcomponents 发送get post请求
引入的包为: <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient --> <de ...
- UDP用于保持大量终端的在线与控制,应用与业务则通过TCP去实现。这个和FTP服务控制与数据分离,采取不同的连接,有异曲同工之处 端口映射老化时间
移动端IM/推送系统的协议选型:UDP还是TCP? http://www.52im.net/thread-33-1-1.html
- 图解 https 单向认证和双向认证!
来源: 一.Http HyperText Transfer Protocol,超文本传输协议,是互联网上使用最广泛的一种协议,所有WWW文件必须遵循的标准.HTTP协议传输的数据都是未加密的,也就是明 ...
- xgboost 算法总结
xgboost有一篇博客写的很清楚,但是现在网址已经失效了,之前转载过,可以搜索XGBoost 与 Boosted Tree. 现在参照这篇,自己对它进行一个总结. xgboost是GBDT的后继算法 ...
- PHP Y2K38 (2038年) 问题
PHP 的 strtotime('2100-01-01'); 转换失败:经查询是因为32位系统的 Y2K38问题: Y2K38 问题:当时间大于 2038年01月19日03:14:07 时,strto ...
- ElasticSearch集群状态查看命令大全(转)
原文地址: https://blog.csdn.net/pilihaotian/article/details/52460747 Elasticsearch中信息很多,同时ES也有很多信息查看命令,可 ...
- html2canvas 将网页截图为图片,上传base64 到服务端
await html2canvas(getById("winyh"), { height:500, allowTaint: true, useCORS: true, }).then ...
- jsp标签${fn:contains()}遇到问题记录
在jsp页面要实现这样一个功能,列表的某一列字段要显示的数据,是从后台的一个列表中获取的,数据库里面该列存储的方式是 类似 1,2,3 这样的 主键id数据.显示的时候要根据id显示名称,如果是多个 ...
- [PHP] dompdf 使用记录
# 安装字体,解决中文乱码参考: https://blog.51cto.com/lampzxr/1916038```首先下载composer curl -sS https://getcomposer. ...