/**
* @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的更多相关文章

  1. 下载 Microsoft SQL Server JDBC 驱动程序

    JDBC 驱动程序中使用 Maven 中心 JDBC 驱动程序可以通过将其添加为依赖项在 POM.xml 文件中使用以下代码添加到 Maven 项目: XML复制 <dependency> ...

  2. WebLogic Server官方下载地址

    WebLogic Server官方下载地址 英文(更新到12c和9.2.4):http://www.oracle.com/technetwork/middleware/ias/downloads/wl ...

  3. 【转】SQL Server 2008下载 (附注册码)

    SQL Server 2008 中文试用版下载地址:http://sqlserver.dlservice.microsoft.com/dl/download/B/8/0/B808AF59-7619-4 ...

  4. Team Foundation Server 2010下载安装配置方法

    一.Team Foundation Server 2010下载: ed2k://|file|cn_visual_studio_team_foundation_server_2010_x86_x64_d ...

  5. sql server 2000 下载地址

    sql  server 2000 下载地址 http://pan.baidu.com/share/link?shareid=146152&uk=1225012539

  6. SQL SERVER 2008 下载地址&安装方法

    下载地址:http://sqlserver.dlservice.microsoft.com/dl/download/B/8/0/B808AF59-7619-4A71-A447-F597DE74AC44 ...

  7. SQL Server 2008 下载及版本说明

    一.下载地址 SQL Server 2008 R2 Enterprise下载地址来源网络整理:MSDN网址,参考: 选中下面链接,放在迅雷中即可下载: ed2k://|file|cn_sql_serv ...

  8. Centos 7 官网下载安装mysql server 5.6

    Centos 7 官网下载安装 mysql server # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rp ...

  9. Java中的Date Time 与SQL Server 2005里的Datetime 之间的交互

    Preface Environment:Platform: Windows XPLanguage: Java 1.5IDE: MyEclipse 6.0.1Database: SQL Server 2 ...

随机推荐

  1. [HDU 4261] Estimation

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4261 [算法] 首先,有一个结论 : | a[1] - k | + | a[2] - k | + ...

  2. 【CQOI 2009】 余数之和

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1257 [算法] k mod i = k - [k / i] * i 所以 (k mo ...

  3. Node.js:目录

    ylbtech-Node.js:目录 1.返回顶部   2.返回顶部   3.返回顶部   4.返回顶部   5.返回顶部 1. http://www.runoob.com/nodejs/nodejs ...

  4. .NET WebForm 简介(9.19)

    WebForm是微软开发的一款产品,它将用户的请求和响应都封装为控件.让开发者认为自己是在操作一个windows界面.极大地提高了开发效率. WinForm是C/S(客户端) 主要是本机执行 WebF ...

  5. Git Learning Part III - working remotely (Github)

    help document of Github : https://help.github.com/ 1 upload 1.1 new update  Initialize a repository  ...

  6. 读《Android电视机(机顶盒)初次开发的一些经验分享》后的笔记

    原文: http://blog.csdn.net/tanghongchang123/article/details/52982818 一.基本命令: 1.adb connect [ip] 2. adb ...

  7. MFC常用控件之滚动条

    近期学习了鸡啄米大神的博客,对其中的一些知识点做了一些自己的总结.不过,博客内容大部分来自鸡啄米.因此,这个博客算是转载博客,只是加了一些我自己的理解而已.若想学习鸡啄米大神的博客总结,请点击连接:h ...

  8. Verilog之$sreadmemb

    1 Memories  Memories file format is shown below, the address is specified as @ <address> in he ...

  9. python版本及ML库

    一:关于Python版本的选择问题 关于Python的选择问题:要看学术界能不能把科学库迁移到Python3. 1:多个版本共用: 最近发现SciPy的最高版本是3.2,只能是退而求其次,不使用最新版 ...

  10. 在maven项目结构下对于Resources目录下文件的存取

    在maven项目中,文件结构如下: proj ---src ----main ----java ----Main.java ----resources ----userFile.properties ...