企业微信下载素材库文件

更新时间:2023-07-07 15:12:47 阅读: 评论:0

企业微信下载素材库⽂件
1、创建MyX509TrustManager
import javax.ssl.X509TrustManager;
import CertificateException;
import X509Certificate;
public class MyX509TrustManager implements X509TrustManager {
public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}
动词过去式变化规则
public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
开车换挡技巧}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
}
2、实现下载具体代码
import net.sf.json.JSONObject;
import ption.ExceptionUtils;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;
import javax.ssl.HttpsURLConnection;
import javax.ssl.SSLContext;
import javax.ssl.SSLSocketFactory;
import javax.ssl.TrustManager;
import java.io.*;
import java.ConnectException;
import java.HttpURLConnection;
import java.URL;
import java.nio.chart.StandardCharts;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardOpenOption;
import java.util.Ba64;
public class WeiXinUtil {
//微信的请求url
// 获取access_token的接⼝地址(GET) 限200(次/天)
public final static String access_token_url = "qyapi./cgi-bin/gettoken?corpid={corpId}&corpcret={corpcret}";//获取jsapi_ticket 的接⼝地址(GET) 限200(次/天)
倾慕的意思public final static String jsapi_ticket_url = "qyapi./cgi-bin/get_jsapi_ticket?access_token=ACCESSTOKEN";
/*** 1.发起https请求并获取结果
*
*@paramrequestUrl 请求地址
*@paramrequestMethod 请求⽅式(GET 、 POST)
*@paramoutputStr 提交的数据
*@returnJSONObject(通过(key)的⽅式获取json对象的属性值)*/
public static String getBa64FromInputStream(InputStream in) {
public static String getBa64FromInputStream(InputStream in) {
// 将图⽚⽂件转化为字节数组字符串,并对其进⾏Ba64编码处理
byte[] data = null;
// 读取图⽚字节数组
try {
ByteArrayOutputStream swapStream = new ByteArrayOutputStream();
byte[] buff = new byte[100];
int rc = 0;
while ((rc = in.read(buff, 0, 100)) > 0) {
swapStream.write(buff, 0, rc);
}
data = ByteArray();
韩国搞笑电视剧
} catch (IOException e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.clo();
} catch (IOException e) {
恋夏500
e.printStackTrace();
}
}
}
return new Encoder().encode(data));
}
下线英文
/*** 2.发送https请求之获取临时素材
*@paramrequestUrl
kingboss*@paramsavePath ⽂件的保存路径,此时还缺⼀个扩展名
*@return*@throwsException*/
public static String getFile(String requestUrl, String savePath) throws Exception {
/
/String Property("ur.dir")+"/img//1.png";
// 创建SSLContext对象,并使⽤我们指定的信任管理器初始化
TrustManager[] tm = {new MyX509TrustManager()};
SSLContext sslContext = Instance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.curity.SecureRandom());
//从上述SSLContext对象中得到SSLSocketFactory对象
SSLSocketFactory ssf = SocketFactory();
URL url = new URL(requestUrl);
HttpsURLConnection httpUrlConn = (HttpsURLConnection) url.openConnection();        httpUrlConn.tSSLSocketFactory(ssf);
httpUrlConn.tDoOutput(true);
httpUrlConn.tDoInput(true);
httpUrlConn.tUCaches(fal);//设置请求⽅式(GET/POST)
httpUrlConn.tRequestMethod("GET");
String ext = ContentType());
savePath = savePath + ext;
System.out.println("savePath" + savePath);//下载⽂件到f⽂件
File file = new File(savePath);//获取微信返回的输⼊流
File file = new File(savePath);//获取微信返回的输⼊流
InputStream in = InputStream();//输出流,将微信返回的输⼊流内容写到⽂件中
String str =  getBa64FromInputStream(in);
in.clo();//释放资源
21玩过界
buzzword
in = null;
httpUrlConn.disconnect();
return str;
}
private static String getExt(String contentType) {
if ("image/jpeg".equals(contentType)) {
return ".jpg";
} el if ("image/png".equals(contentType)) {
return ".png";
} el if ("image/gif".equals(contentType)) {
return ".gif";
}
return null;
}
public static String encryptToBa64(String filePath) {
if (filePath == null) {
return null;
}
try {
byte[] b = (filePath));
Encoder().encodeToString(b);
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
public static InputStream baToInputStream(final byte[] ba64byte){
ByteArrayInputStream stream = null;
try {
byte[] bytes1 = Encoder().encode(ba64byte);
stream = new ByteArrayInputStream(bytes1);
} catch (Exception e) {
// TODO: handle exception
}
return stream;
}
public static void main(String[] args) {
try {
String token
="cHsw7y4FHa6GVv5PfYForp6tyWKEaaAZmpnVD1AUBVoT2pHenckMFz_9rKskaGd3zsCB65NQMFZn1JvHZmrQgnxkS7xi6HuD3vcSUEyC4xmd63KM ZnzFqIrvd4DjPK9LnTPh8duE41pKpRdXnNmGay6Gq-
MpMD4SHbKa3pmLLA8rQzk3Q_HCV6Q2QV9ZhVkyo8uWrPgVSe6zXUPt5hJ05Ox3mfKDYMWXY3QRKjiX_gY";
String str=  getFile("qyapi./cgi-bin/media/get?
access_token="+token+"&media_id=1F__jdg51M5FNk7JX1dnIVLFtpSoDTfxRearMcAwa5eeum6X0voedcQZrRbCjhi_i","d://a//test12");
/*
String str=encryptToBa64("d://a//test12.jpg");
*/
ouraildecryptByBa64(str,"d://a//test12345.jpg");
} catch (Exception e) {
e.printStackTrace();
}
}
public static String decryptByBa64(String ba64, String filePath) {
if (ba64 == null && filePath == null) {
return "⽣成⽂件失败,请给出相应的数据。";
}
try {
Files.(filePath), Decoder().decode(ba64), StandardOpenOption.CREATE);        } catch (IOException e) {
e.printStackTrace();
}
return "指定路径下⽣成⽂件成功!";
}
}

本文发布于:2023-07-07 15:12:47,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/78/1083834.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:获取   请求   对象   微信   数组
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图