@Override
    public File download(String mediaId, String directory) {
        if (StringUtils.isEmpty(mediaId)) {
            throw new IllegalArgumentException("从微信服务器下载附件时,没有指定附件的ID!");
        }
        File file = null;
        if (!StringUtils.isEmpty(directory)) {
            File foo = new File(directory);
            foo.mkdirs();
        }
        if (StringUtils.isEmpty(directory)) {
            directory = System.getProperty("java.io.tmpdir");
        }
        String url = RequestWrapper.getUrl(WeChatUrl.DOWNLOAD, mediaId);
        try {
            //请求获得附件
            HttpClient httpClient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet(url);
            if (SimpleRequest.proxy != null) {
                httpClient.getParams().setParameter("http.route.default-proxy", SimpleRequest.proxy);
            }
            HttpResponse response = httpClient.execute(httpget);
            int status = response.getStatusLine().getStatusCode();
            if (status == 200) {
                Header content = response.getFirstHeader("Content-disposition");
                if (content == null || StringUtils.isEmpty(content.getValue())) {
                    throw new RuntimeException("没有获得附件信息!");
                }
                //获得附件名称
                String disposition = content.getValue();
                int index = disposition.indexOf("filename=");
                if (index > 0) {
                    String fileName = disposition.substring(index + "filename=".length() + 1, disposition.length() - 1);
                    file = new File(directory + fileName);
                }
                //将附件写入到临时目录
                InputStream input = response.getEntity().getContent();
                FileUtils.copyInputStreamToFile(input, file);
            }
            httpClient.getConnectionManager().shutdown();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return file;
    }