java 微信server录音下载到自己server
/**
* @author why
*
*/
public class VoiceDownload {
/**
*
* 依据文件id下载文件
*
*
*
* @param mediaId
*
* 媒体id
*
* @throws Exception
*/ public static InputStream getInputStream(String accessToken, String mediaId) {
InputStream is = null;
String url = "http://file.api.weixin.qq.com/cgi-bin/media/get? access_token="
+ accessToken + "&media_id=" + mediaId;
try {
URL urlGet = new URL(url);
HttpURLConnection http = (HttpURLConnection) urlGet
.openConnection();
http.setRequestMethod("GET"); // 必须是get方式请求
http.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
http.setDoOutput(true);
http.setDoInput(true);
System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
http.connect();
// 获取文件转化为byte流
is = http.getInputStream(); } catch (Exception e) {
e.printStackTrace();
}
return is; } /**
*
* 获取下载图片信息(jpg)
*
*
*
* @param mediaId
*
* 文件的id
*
* @throws Exception
*/ public static void saveImageToDisk(String accessToken, String mediaId, String picName, String picPath)
throws Exception {
InputStream inputStream = getInputStream(accessToken, mediaId);
byte[] data = new byte[10240];
int len = 0;
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream(picPath+picName+".amr");
while ((len = inputStream.read(data)) != -1) {
fileOutputStream.write(data, 0, len);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (inputStream != null) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} }
java 微信server录音下载到自己server的更多相关文章
- 下载 Microsoft SQL Server JDBC 驱动程序
JDBC 驱动程序中使用 Maven 中心 JDBC 驱动程序可以通过将其添加为依赖项在 POM.xml 文件中使用以下代码添加到 Maven 项目: XML复制 <dependency> ...
- WebLogic Server官方下载地址
WebLogic Server官方下载地址 英文(更新到12c和9.2.4):http://www.oracle.com/technetwork/middleware/ias/downloads/wl ...
- 【转】SQL Server 2008下载 (附注册码)
SQL Server 2008 中文试用版下载地址:http://sqlserver.dlservice.microsoft.com/dl/download/B/8/0/B808AF59-7619-4 ...
- Team Foundation Server 2010下载安装配置方法
一.Team Foundation Server 2010下载: ed2k://|file|cn_visual_studio_team_foundation_server_2010_x86_x64_d ...
- sql server 2000 下载地址
sql server 2000 下载地址 http://pan.baidu.com/share/link?shareid=146152&uk=1225012539
- SQL SERVER 2008 下载地址&安装方法
下载地址:http://sqlserver.dlservice.microsoft.com/dl/download/B/8/0/B808AF59-7619-4A71-A447-F597DE74AC44 ...
- SQL Server 2008 下载及版本说明
一.下载地址 SQL Server 2008 R2 Enterprise下载地址来源网络整理:MSDN网址,参考: 选中下面链接,放在迅雷中即可下载: ed2k://|file|cn_sql_serv ...
- Centos 7 官网下载安装mysql server 5.6
Centos 7 官网下载安装 mysql server # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rp ...
- Java中的Date Time 与SQL Server 2005里的Datetime 之间的交互
Preface Environment:Platform: Windows XPLanguage: Java 1.5IDE: MyEclipse 6.0.1Database: SQL Server 2 ...
随机推荐
- wampserver配置多站点
1.打开C:\wamp\bin\apache\apache2.2.22\conf\httpd.conf(因安装的路径而异),查找listen 80 下面加上listen 8080 2.然后加上 < ...
- Elasticsearch日志收集
Install pip if necessary curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py&q ...
- OpenCASCADE 包说明
转载地址:http://www.cppblog.com/eryar/archive/2012/06/30/180916.html 一.简介 Introduction to Package gp gp是 ...
- Android拼图-变形金刚
开篇 学了几个月的Android开发,动手做了一个简单的拼图小游戏,没有使用游戏框架,名字也纯属娱乐,比较粗糙请大家一笑别骂. 游戏界面是一张图片切割的6*6的小图片,并将其中一块拿走,玩家通过不同的 ...
- 什么是J2EE的集群?
1. 前言 现在有越来越多的关键应用和大型应用是基于J2EE 来创建的,像银行系统和帐单系统这些关键应用要求有很高的可用性,而Google 和Yahoo 这样的大型应用就需要很好的可扩 ...
- 洛谷P1466 集合 Subset Sums_01背包水题
不多解释,适当刷刷水… Code: #include<cstdio> #include<algorithm> using namespace std; const int ma ...
- 如何添加删除子网卡eth0:1(linux案例)
这种方法实现了单网卡多IP,我的系统是centos7的,如何添加删除子网卡IP详细请看下面操作例子 添加子网卡IP:ifconfig ens3:1 192.168.0.100/24 ...
- Python笔记17---------魔法方法
魔法方法也为特殊方法,即用两个下划线形成的(__方法__).自己定义的方法最好不要采用这种方式,因为这些方法会在一些特殊的情况下直接被调用. 1.第一个魔法方法:类中常用的__init__()方法:相 ...
- [NOI 2002] 银河英雄传说 (带权并查集)
题目描述 公元五八○一年,地球居民迁至金牛座α第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展. 宇宙历七九九年,银河系的两大军事集团在巴米利恩星域爆发战争.泰山压顶 ...
- Linux初级命令总结
第1节 查看当前系统版本及内核 cat /etc/redhat-release (查看系统版本) CentOS Linux release 7.4.1708 (Core) uname -r (查看系统 ...