|
@@ -1,6 +1,7 @@
|
|
|
package com.github.zuihou.tenant.util;
|
|
|
|
|
|
import cn.hutool.json.JSONObject;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import org.apache.http.HttpEntity;
|
|
|
import org.apache.http.HttpResponse;
|
|
|
import org.apache.http.HttpStatus;
|
|
@@ -26,11 +27,15 @@ import org.apache.http.impl.conn.ManagedHttpClientConnectionFactory;
|
|
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
|
import org.apache.http.impl.conn.SystemDefaultDnsResolver;
|
|
|
import org.apache.http.impl.io.DefaultHttpRequestWriterFactory;
|
|
|
+import org.apache.http.protocol.HTTP;
|
|
|
import org.apache.http.util.EntityUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
import java.net.SocketTimeoutException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
@@ -288,6 +293,42 @@ public class HttpClientUtils {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ public String test(String token,Map<String,Object> params1) throws IOException {
|
|
|
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
+
|
|
|
+ HttpPost httpPost = new HttpPost("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token); // 接口
|
|
|
+ httpPost.addHeader(HTTP.CONTENT_TYPE, "application/json");
|
|
|
+ String body = JSON.toJSONString(params1);
|
|
|
+ System.err.println(body);//必须是json模式的 post
|
|
|
+ StringEntity entity;
|
|
|
+ entity = new StringEntity(body);
|
|
|
+ entity.setContentType("image/png");
|
|
|
+
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ HttpResponse response;
|
|
|
+
|
|
|
+ response = httpClient.execute(httpPost);
|
|
|
+ InputStream inputStream = response.getEntity().getContent();
|
|
|
+ ByteArrayOutputStream bytestream = new ByteArrayOutputStream();
|
|
|
+ int ch;
|
|
|
+ try {
|
|
|
+ while ((ch = inputStream.read()) != -1) {
|
|
|
+ bytestream.write(ch);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ catch (IOException e) {
|
|
|
+ // TODO Auto-generated catch block
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ byte[] program = bytestream.toByteArray();
|
|
|
+ BASE64Encoder encoder = new BASE64Encoder();
|
|
|
+ String binary = encoder.encodeBuffer(program).trim();
|
|
|
+ return binary;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
/**
|
|
|
* 获取数据流
|
|
|
*
|