五月天综合,国产97成人亚洲综合在线观看,99九九无码人妻,艳妇臀荡乳欲伦69调教视频

幫助與文檔 > 產(chǎn)品文檔 > 視覺智能服務(wù) > API文檔 > PDF轉(zhuǎn)WORD
PDF轉(zhuǎn)WORD

PDF轉(zhuǎn)WORD API 簡(jiǎn)介

說(shuō)明

Hi,您好,歡迎使用有道智云PDF轉(zhuǎn)WORD API接口服務(wù)。

本文檔主要針對(duì)需要集成HTTP API的技術(shù)開發(fā)工程師,詳細(xì)描述PDF轉(zhuǎn)WORD能力相關(guān)的技術(shù)內(nèi)容。

如果您有與我們商務(wù)合作的需求,可以通過(guò)以下方式聯(lián)系我們:

商務(wù)郵箱: AIcloud_Business@corp.youdao.com

如果您對(duì)文檔內(nèi)容有任何疑問(wèn),可以通過(guò)以下幾種方式聯(lián)系我們:

客服QQ:1906538062

智云翻譯技術(shù)交流QQ 1群: 652880659

智云翻譯技術(shù)交流QQ 2群: 669384425

智云翻譯技術(shù)交流QQ 3群: 807539209

智云翻譯技術(shù)交流QQ 4群: 936752411

聯(lián)系郵箱: zhiyun@corp.youdao.com

溫馨提示:

  • 本文檔主要針對(duì)開發(fā)人員,接入測(cè)試前需要獲取應(yīng)用ID和應(yīng)用密鑰;如果您還沒有,請(qǐng)按照 新手指南 獲取。
  • 平臺(tái)向每個(gè)賬戶贈(zèng)送50元的體驗(yàn)金,供用戶集成前測(cè)試所用,具體資費(fèi) 0.1元/頁(yè)。

接口說(shuō)明

PDF轉(zhuǎn)WORD API接口提供有道的PDF轉(zhuǎn)WORD服務(wù)。您只需要通過(guò)調(diào)用PDF轉(zhuǎn)WORD API,傳入文檔的Base64編碼,指定源語(yǔ)言與目標(biāo)語(yǔ)言,通過(guò)POST請(qǐng)求方式,就可以將文檔中的文字內(nèi)容進(jìn)行翻譯。

PDF轉(zhuǎn)WORD API HTTPS地址:

  • 文檔上傳接口

https://openapi.youdao.com/file_convert/upload

  • 進(jìn)度查詢接口

https://openapi.youdao.com/file_convert/query

  • 文檔下載接口

https://openapi.youdao.com/file_convert/download

協(xié)議須知

調(diào)用方在集成文本翻譯API時(shí),請(qǐng)遵循以下規(guī)則。

規(guī)則描述
傳輸方式HTTPS
請(qǐng)求方式POST
字符編碼統(tǒng)一使用UTF-8 編碼
請(qǐng)求格式表單
響應(yīng)格式JSON

接口調(diào)用參數(shù)

調(diào)用API需要向接口發(fā)送以下字段來(lái)訪問(wèn)服務(wù)。

  • 文檔上傳接口
字段名類型含義必填備注
qtext待翻譯文檔True文檔的Base64編碼,大小限制為40M(編碼后)
fileNametext文檔名稱True
fileTypetext文檔類型Truepdf/jpg/png/bmp
appKeytext應(yīng)用IDTrue可在 應(yīng)用管理 查看
salttextUUIDTrueuuid,唯一通用識(shí)別碼
curtimetext當(dāng)前UTC時(shí)間戳(秒)True
signtext簽名Truesha256(應(yīng)用ID+input+salt+curtime+應(yīng)用密鑰)
docTypetext服務(wù)器響應(yīng)類型Truejson
signTypetext簽名類型Truev3
  • 進(jìn)度查詢接口
字段名類型含義必填備注
flownumbertext文檔流水號(hào)True從文檔上傳接口獲取
appKeytext應(yīng)用IDTrue可在 應(yīng)用管理 查看
salttextUUIDTrue
curtimetext當(dāng)前UTC時(shí)間戳(秒)True
signtext簽名Truesha256(應(yīng)用ID+input+salt+curtime+應(yīng)用密鑰)
docTypetext服務(wù)器響應(yīng)類型Truejson
signTypetext簽名類型Truev3
  • 文檔下載接口
字段名類型含義必填備注
flownumbertext文檔流水號(hào)True從文檔上傳接口獲取
downloadFileTypetext下載類型Trueword
appKeytext應(yīng)用IDTrue可在 應(yīng)用管理 查看
salttextUUIDTrue
curtimetext當(dāng)前UTC時(shí)間戳(秒)True
signtext簽名Truesha256(應(yīng)用ID+input+salt+curtime+應(yīng)用密鑰)
docTypetext服務(wù)器響應(yīng)類型Truejson
signTypetext簽名類型Truev3

簽名生成方法如下:

sha256(應(yīng)用ID + input + salt + curtime + 應(yīng)用密鑰)

其中,input的計(jì)算方式為:

  • 文檔上傳接口

input = Base64(fileName)字符串(當(dāng)Base64(fileName)長(zhǎng)度小于等于20)

input = Base64(fileName)前10個(gè)字符前10個(gè)字符 + Base64(fileName)長(zhǎng)度 + Base64(fileName)后十個(gè)字符(當(dāng)Base64(fileName)長(zhǎng)度大于20)

  • 其它接口

input = flownumber字符串(當(dāng)flownumber長(zhǎng)度小于等于20)。

input = flownumber前10個(gè)字符前10個(gè)字符 + flownumber長(zhǎng)度 + flownumber后十個(gè)字符(當(dāng)flownumber長(zhǎng)度大于20)

不同語(yǔ)言獲取時(shí)間戳,請(qǐng)參看 此鏈接

如果對(duì)簽名有疑問(wèn),可以參看文檔末尾各語(yǔ)言demo。

輸出結(jié)果

返回的結(jié)果是json格式,具體說(shuō)明如下:

  • 文檔上傳
字段名類型字段說(shuō)明
errorCodetext錯(cuò)誤碼,一定存在
flownumbertext文檔流水號(hào),上傳成功一定存在
  • 進(jìn)度查詢接口
字段名類型字段說(shuō)明
errorCodetext錯(cuò)誤碼,一定存在
statustext進(jìn)度狀態(tài)碼,查詢成功一定存在
statusStringtext進(jìn)度狀態(tài)描述,查詢成功一定存在
  • 文檔下載接口
    Content-Typeapplication/json,表示下載失敗,返回值為json,否則返回值為文件流。
字段名類型字段說(shuō)明
errorCodetext錯(cuò)誤碼,下載失敗時(shí)存在

示例

  • 文檔上傳接口

返回結(jié)果:

{
    "errorCode": "0",   //錯(cuò)誤碼
    "flownumber": "C9193F8204484E51B7DDA604137AEE3D"   //文檔流水號(hào)
}
  • 進(jìn)度查詢接口

返回結(jié)果:

{
    "errorCode": "0",   //錯(cuò)誤碼
    "status": 1,   //狀態(tài)碼
    "statusString": "上傳中'   //狀態(tài)描述
}
  • 文檔下載接口

失敗時(shí)返回結(jié)果:

{
    "errorCode": "0"   //錯(cuò)誤碼
}

文檔狀態(tài)碼

狀態(tài)碼含義
1上傳中
2轉(zhuǎn)換中
4已完成
5生成中
-1上傳失敗
-2轉(zhuǎn)換失敗
-4已取消
-5生成失敗
-11文件被刪除

服務(wù)配置

| 支持格式 | 文件大小 |
| -------- | --------------- |
| pdf | 40M內(nèi)(編碼后) |

錯(cuò)誤代碼列表

錯(cuò)誤碼含義
101缺少必填的參數(shù),首先確保必填參數(shù)齊全,然后,確認(rèn)參數(shù)書寫是否正確。
102不支持的語(yǔ)言類型
103翻譯文本過(guò)長(zhǎng)
104不支持的API類型
105不支持的簽名類型
106不支持的響應(yīng)類型
107不支持的傳輸加密類型
108應(yīng)用ID無(wú)效,注冊(cè)賬號(hào),登錄后臺(tái)創(chuàng)建應(yīng)用和實(shí)例并完成綁定,可獲得應(yīng)用ID和應(yīng)用密鑰等信息
109batchLog格式不正確
110無(wú)相關(guān)服務(wù)的有效實(shí)例,應(yīng)用沒有綁定服務(wù)實(shí)例,可以新建服務(wù)實(shí)例,綁定服務(wù)實(shí)例。注:某些服務(wù)的翻譯結(jié)果發(fā)音需要tts實(shí)例,需要在控制臺(tái)創(chuàng)建語(yǔ)音合成實(shí)例綁定應(yīng)用后方能使用。
111開發(fā)者賬號(hào)無(wú)效
112請(qǐng)求服務(wù)無(wú)效
113q不能為空
114不支持的圖片傳輸方式
201解密失敗,可能為DES,BASE64,URLDecode的錯(cuò)誤
202簽名檢驗(yàn)失敗,如果確認(rèn)應(yīng)用ID和應(yīng)用密鑰的正確性,仍返回202,一般是編碼問(wèn)題。請(qǐng)確保翻譯文本 q 為UTF-8編碼.
203訪問(wèn)IP地址不在可訪問(wèn)IP列表
205請(qǐng)求的接口與應(yīng)用的平臺(tái)類型不一致,確保接入方式(Android SDK、IOS SDK、API)與創(chuàng)建的應(yīng)用平臺(tái)類型一致。如有疑問(wèn)請(qǐng)參考入門指南
206因?yàn)闀r(shí)間戳無(wú)效導(dǎo)致簽名校驗(yàn)失敗
207重放請(qǐng)求
301辭典查詢失敗
302翻譯查詢失敗
303服務(wù)端的其它異常
304會(huì)話閑置太久超時(shí)
401賬戶已經(jīng)欠費(fèi)停
402offlinesdk不可用
411訪問(wèn)頻率受限,請(qǐng)稍后訪問(wèn)
412長(zhǎng)請(qǐng)求過(guò)于頻繁,請(qǐng)稍后訪問(wèn)
1001無(wú)效的OCR類型
1002不支持的OCR image類型
1003不支持的OCR Language類型
1004識(shí)別圖片過(guò)大
1201圖片base64解密失敗
1301OCR段落識(shí)別失敗
1411訪問(wèn)頻率受限
1412超過(guò)最大識(shí)別字節(jié)數(shù)
2003不支持的語(yǔ)言識(shí)別Language類型
2004合成字符過(guò)長(zhǎng)
2005不支持的音頻文件類型
2006不支持的發(fā)音類型
2201解密失敗
2301服務(wù)的異常
2411訪問(wèn)頻率受限,請(qǐng)稍后訪問(wèn)
2412超過(guò)最大請(qǐng)求字符數(shù)
3001不支持的語(yǔ)音格式
3002不支持的語(yǔ)音采樣率
3003不支持的語(yǔ)音聲道
3004不支持的語(yǔ)音上傳類型
3005不支持的語(yǔ)言類型
3006不支持的識(shí)別類型
3007識(shí)別音頻文件過(guò)大
3008識(shí)別音頻時(shí)長(zhǎng)過(guò)長(zhǎng)
3009不支持的音頻文件類型
3010不支持的發(fā)音類型
3201解密失敗
3301語(yǔ)音識(shí)別失敗
3302語(yǔ)音翻譯失敗
3303服務(wù)的異常
3411訪問(wèn)頻率受限,請(qǐng)稍后訪問(wèn)
3412超過(guò)最大請(qǐng)求字符數(shù)
4001不支持的語(yǔ)音識(shí)別格式
4002不支持的語(yǔ)音識(shí)別采樣率
4003不支持的語(yǔ)音識(shí)別聲道
4004不支持的語(yǔ)音上傳類型
4005不支持的語(yǔ)言類型
4006識(shí)別音頻文件過(guò)大
4007識(shí)別音頻時(shí)長(zhǎng)過(guò)長(zhǎng)
4201解密失敗
4301語(yǔ)音識(shí)別失敗
4303服務(wù)的異常
4411訪問(wèn)頻率受限,請(qǐng)稍后訪問(wèn)
4412超過(guò)最大請(qǐng)求時(shí)長(zhǎng)
5001無(wú)效的OCR類型
5002不支持的OCR image類型
5003不支持的語(yǔ)言類型
5004識(shí)別圖片過(guò)大
5005不支持的圖片類型
5006文件為空
5201解密錯(cuò)誤,圖片base64解密失敗
5301OCR段落識(shí)別失敗
5411訪問(wèn)頻率受限
5412超過(guò)最大識(shí)別流量
9001不支持的語(yǔ)音格式
9002不支持的語(yǔ)音采樣率
9003不支持的語(yǔ)音聲道
9004不支持的語(yǔ)音上傳類型
9005不支持的語(yǔ)音識(shí)別 Language類型
9301ASR識(shí)別失敗
9303服務(wù)器內(nèi)部錯(cuò)誤
9411訪問(wèn)頻率受限(超過(guò)最大調(diào)用次數(shù))
9412超過(guò)最大處理語(yǔ)音長(zhǎng)度
10001無(wú)效的OCR類型
10002不支持的OCR image類型
10004識(shí)別圖片過(guò)大
10201圖片base64解密失敗
10301OCR段落識(shí)別失敗
10411訪問(wèn)頻率受限
10412超過(guò)最大識(shí)別流量
11001不支持的語(yǔ)音識(shí)別格式
11002不支持的語(yǔ)音識(shí)別采樣率
11003不支持的語(yǔ)音識(shí)別聲道
11004不支持的語(yǔ)音上傳類型
11005不支持的語(yǔ)言類型
11006識(shí)別音頻文件過(guò)大
11007識(shí)別音頻時(shí)長(zhǎng)過(guò)長(zhǎng),最大支持30s
11201解密失敗
11301語(yǔ)音識(shí)別失敗
11303服務(wù)的異常
11411訪問(wèn)頻率受限,請(qǐng)稍后訪問(wèn)
11412超過(guò)最大請(qǐng)求時(shí)長(zhǎng)
12001圖片尺寸過(guò)大
12002圖片base64解密失敗
12003引擎服務(wù)器返回錯(cuò)誤
12004圖片為空
12005不支持的識(shí)別圖片類型
12006圖片無(wú)匹配結(jié)果
13001不支持的角度類型
13002不支持的文件類型
13003表格識(shí)別圖片過(guò)大
13004文件為空
13301表格識(shí)別失敗
15001需要圖片
15002圖片過(guò)大(1M)
15003服務(wù)調(diào)用失敗
17001需要圖片
17002圖片過(guò)大(1M)
17003識(shí)別類型未找到
17004不支持的識(shí)別類型
17005服務(wù)調(diào)用失敗
18001需要參數(shù)
18002需要流水號(hào)
18003需要文件名
18004需要文件類型
18005需要源語(yǔ)言
18006需要目標(biāo)語(yǔ)言
18007需要翻譯文件
18008上傳文件失敗
18009錯(cuò)誤的流水號(hào)
18010未完成
18011轉(zhuǎn)換失敗
18012找不到文件
18013需要文件下載類型
18014不支持的語(yǔ)言
18015不支持的文件類型
18016不支持的下載類型
18017文件過(guò)大

常用語(yǔ)言 Demo

Java 示例

import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.*;

public class Demo {

    private static Logger logger = LoggerFactory.getLogger(Demo.class);

    private static final String YOUDAO_URL_UPLOAD = "https://openapi.youdao.com/file_convert/upload";

    private static final String YOUDAO_URL_QUERY = "https://openapi.youdao.com/file_convert/query";

    private static final String YOUDAO_URL_DOWNLOAD = "https://openapi.youdao.com/file_convert/download";

    private static final String APP_KEY = "您的應(yīng)用ID";

    private static final String APP_SECRET = "您的應(yīng)用密鑰";

    public static void main(String[] args) throws IOException {
        upload();
        query();
        download();
    }
    
    public static void upload() throws IOException {
        Map<String,String> params = new HashMap<String,String>();
        String q = loadAsBase64("文件的路徑");
        String salt = String.valueOf(System.currentTimeMillis());
        String curtime = String.valueOf(System.currentTimeMillis() / 1000);
        String signStr = APP_KEY + truncate(q) + salt + curtime + APP_SECRET;
        String sign = getDigest(signStr);
        params.put("q", q);
        params.put("fileName", "文件名稱");
        params.put("fileType", "文件類型");
        params.put("appKey", APP_KEY);
        params.put("salt", salt);
        params.put("curtime", curtime);
        params.put("sign", sign);
        params.put("docType", "json");
        params.put("signType", "v3");
        String result = requestForHttp(YOUDAO_URL_UPLOAD, params);
        /** 處理結(jié)果 */
        System.out.println(result);
    }
    
    public static void query() throws IOException {
        Map<String,String> params = new HashMap<String,String>();
        String flownumber = "文件流水號(hào)";
        String salt = String.valueOf(System.currentTimeMillis());
        String curtime = String.valueOf(System.currentTimeMillis() / 1000);
        String signStr = APP_KEY + truncate(flownumber) + salt + curtime + APP_SECRET;
        String sign = getDigest(signStr);
        params.put("flownumber", flownumber);
        params.put("appKey", APP_KEY);
        params.put("salt", salt);
        params.put("curtime", curtime);
        params.put("sign", sign);
        params.put("docType", "json");
        params.put("signType", "v3");
        String result = requestForHttp(YOUDAO_URL_QUERY, params);
        /** 處理結(jié)果 */
        System.out.println(result);
    }
    
    public static void download() throws IOException {
        Map<String,String> params = new HashMap<String,String>();
        String flownumber = "文件流水號(hào)";
        String salt = String.valueOf(System.currentTimeMillis());
        String curtime = String.valueOf(System.currentTimeMillis() / 1000);
        String signStr = APP_KEY + truncate(flownumber) + salt + curtime + APP_SECRET;
        String sign = getDigest(signStr);
        params.put("flownumber", flownumber);
        params.put("downloadFileType", "文件下載類型(word)");
        params.put("appKey", APP_KEY);
        params.put("salt", salt);
        params.put("curtime", curtime);
        params.put("sign", sign);
        params.put("docType", "json");
        params.put("signType", "v3");
        String result = requestForHttp(YOUDAO_URL_DOWNLOAD, params);
        /** 處理結(jié)果 */
        System.out.println(result);
    }

    public static String requestForHttp(String url,Map<String,String> params) throws IOException {
        String result = "";

        /** 創(chuàng)建HttpClient */
        CloseableHttpClient httpClient = HttpClients.createDefault();

        /** httpPost */
        HttpPost httpPost = new HttpPost(url);
        List<NameValuePair> paramsList = new ArrayList<NameValuePair>();
        Iterator<Map.Entry<String,String>> it = params.entrySet().iterator();
        while(it.hasNext()){
            Map.Entry<String,String> en = it.next();
            String key = en.getKey();
            String value = en.getValue();
            paramsList.add(new BasicNameValuePair(key,value));
        }
        httpPost.setEntity(new UrlEncodedFormEntity(paramsList,"UTF-8"));
        CloseableHttpResponse httpResponse = httpClient.execute(httpPost);
        try{
            HttpEntity httpEntity = httpResponse.getEntity();
            result = EntityUtils.toString(httpEntity,"UTF-8");
            EntityUtils.consume(httpEntity);
        }finally {
            try{
                if(httpResponse!=null){
                    httpResponse.close();
                }
            }catch(IOException e){
                logger.info("## release resouce error ##" + e);
            }
        }
        return result;
    }

    /**
     * 生成加密字段
     */
    public static String getDigest(String string) {
        if (string == null) {
            return null;
        }
        char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
        byte[] btInput = string.getBytes(StandardCharsets.UTF_8);
        try {
            MessageDigest mdInst = MessageDigest.getInstance("SHA-256");
            mdInst.update(btInput);
            byte[] md = mdInst.digest();
            int j = md.length;
            char str[] = new char[j * 2];
            int k = 0;
            for (byte byte0 : md) {
                str[k++] = hexDigits[byte0 >>> 4 & 0xf];
                str[k++] = hexDigits[byte0 & 0xf];
            }
            return new String(str);
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }

    public static String loadAsBase64(String imgFile)
  {//將文件轉(zhuǎn)化為字節(jié)數(shù)組字符串,并對(duì)其進(jìn)行Base64編碼處理

    File file = new File(imgFile);
    if(!file.exists()){
        logger.error("文件不存在");
        return null;
    }
    InputStream in = null;
    byte[] data = null;
      //讀取文件字節(jié)數(shù)組
    try
    {
        in = new FileInputStream(imgFile);
        data = new byte[in.available()];
        in.read(data);
        in.close();
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
      //對(duì)字節(jié)數(shù)組Base64編碼
    return Base64.getEncoder().encodeToString(data);//返回Base64編碼過(guò)的字節(jié)數(shù)組字符串
  }

  public static String truncate(String q) {
        if (q == null) {
            return null;
        }
        int len = q.length();
        String result;
        return len <= 20 ? q : (q.substring(0, 10) + len + q.substring(len - 10, len));
    }
}

Python 示例

# -*- coding: utf-8 -*-
import sys
import uuid
import requests
import base64
import hashlib
import time

reload(sys)
sys.setdefaultencoding('utf-8')

YOUDAO_URL_UPLOAD = 'https://openapi.youdao.com/file_convert/upload'
YOUDAO_URL_QUERY = 'https://openapi.youdao.com/file_convert/query'
YOUDAO_URL_DOWNLOAD = 'https://openapi.youdao.com/file_convert/download'
APP_KEY = '您的應(yīng)用ID'
APP_SECRET = '您的應(yīng)用密鑰'


def truncate(q):
    if q is None:
        return None
    q_utf8 = q.decode("utf-8")
    size = len(q_utf8)
    return q_utf8 if size <= 20 else q_utf8[0:10] + str(size) + q_utf8[size - 10:size]


def encrypt(signStr):
    hash_algorithm = hashlib.sha256()
    hash_algorithm.update(signStr.encode('utf-8'))
    return hash_algorithm.hexdigest()


def do_request(url, data):
    headers = {'Content-Type': 'application/x-www-form-urlencoded'}
    return requests.post(url, data=data, headers=headers)


def upload():
    f = open(r'文件的路徑', 'rb')  # 二進(jìn)制方式打開文件
    q = base64.b64encode(f.read())  # 讀取文件內(nèi)容,轉(zhuǎn)換為base64編碼
    f.close()
    salt = str(uuid.uuid1())
    curtime = str(int(time.time()))
    signStr = APP_KEY + truncate(q) + salt + curtime + APP_SECRET
    sign = encrypt(signStr)

    data = {}
    data['q'] = q
    data['fileName'] = '文件名稱'
    data['fileType'] = '文件類型'
    data['appKey'] = APP_KEY
    data['salt'] = salt
    data['curtime'] = curtime
    data['sign'] = sign
    data['docType'] = 'json'
    data['signType'] = 'v3'

    response = do_request(YOUDAO_URL_UPLOAD, data)
    print response.content


def query():
    flownumber = '文件流水號(hào)'
    salt = str(uuid.uuid1())
    curtime = str(int(time.time()))
    signStr = APP_KEY + truncate(flownumber) + salt + curtime + APP_SECRET
    sign = encrypt(signStr)

    data = {}
    data['flownumber'] = flownumber
    data['appKey'] = APP_KEY
    data['salt'] = salt
    data['curtime'] = curtime
    data['sign'] = sign
    data['docType'] = 'json'
    data['signType'] = 'v3'

    response = do_request(YOUDAO_URL_QUERY, data)
    print response.content


def download():
    flownumber = '文件流水號(hào)'
    salt = str(uuid.uuid1())
    curtime = str(int(time.time()))
    signStr = APP_KEY + truncate(flownumber) + salt + curtime + APP_SECRET
    sign = encrypt(signStr)

    data = {}
    data['flownumber'] = flownumber
    data['downloadFileType'] = '文件下載類型'
    data['appKey'] = APP_KEY
    data['salt'] = salt
    data['curtime'] = curtime
    data['sign'] = sign
    data['docType'] = 'json'
    data['signType'] = 'v3'

    response = do_request(YOUDAO_URL_DOWNLOAD, data)
    print response.content


if __name__ == '__main__':
    upload()
    query()
    download()

C# 示例

using System;
using System.IO;
using System.Net;
using System.Text;
using System.Collections.Generic;
using System.Security.Cryptography;

namespace zhiyun_csharp_demo
{
    class Demo
    {
        public static void Main()
        {
            Upload();
            Query();
            Download();
        }
        
        protected static void Upload() {
            Dictionary dic = new Dictionary();
            string appKey = "您的應(yīng)用ID";
            string appSecret = "您的應(yīng)用密鑰";
            string url = "https://openapi.youdao.com/file_convert/upload";
            string q = LoadAsBase64("文件的路徑");
            string salt = DateTime.Now.Millisecond.ToString();
            TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
            long millis = (long) ts.TotalMilliseconds;
            string curtime = Convert.ToString(millis / 1000);
            string signStr = appKey + Truncate(q) + salt + curtime + appSecret;
            string sign = ComputeHash(signStr, new SHA256CryptoServiceProvider());
            dic.Add("q", System.Web.HttpUtility.UrlEncode(q));
            dic.Add("fileName", "文件名稱");
            dic.Add("fileType", "文件類型");
            dic.Add("appKey", appKey);
            dic.Add("salt", salt);
            dic.Add("curtime", curtime);
            dic.Add("sign", sign);
            dic.Add("docType", "json");
            dic.Add("signType", "v3");
            string result = Post(url, dic);
            Console.WriteLine(result);
        }
        
        protected static void Query() {
            Dictionary dic = new Dictionary();
            string appKey = "您的應(yīng)用ID";
            string appSecret = "您的應(yīng)用密鑰";
            string url = "https://openapi.youdao.com/file_convert/query";
            string flownumber = "文件流水號(hào)";
            string salt = DateTime.Now.Millisecond.ToString();
            TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
            long millis = (long) ts.TotalMilliseconds;
            string curtime = Convert.ToString(millis / 1000);
            string signStr = appKey + Truncate(flownumber) + salt + curtime + appSecret;;
            string sign = ComputeHash(signStr, new SHA256CryptoServiceProvider());
            dic.Add("flownumber", flownumber);
            dic.Add("appKey", appKey);
            dic.Add("salt", salt);
            dic.Add("curtime", curtime);
            dic.Add("sign", sign);
            dic.Add("docType", "json");
            dic.Add("signType", "v3");
            string result = Post(url, dic);
            Console.WriteLine(result);
        }
        
        protected static void Download() {
            Dictionary dic = new Dictionary();
            string appKey = "您的應(yīng)用ID";
            string appSecret = "您的應(yīng)用密鑰";
            string url = "https://openapi.youdao.com/file_convert/download";
            string flownumber = "文件流水號(hào)";
            string salt = DateTime.Now.Millisecond.ToString();
            TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc));
            long millis = (long) ts.TotalMilliseconds;
            string curtime = Convert.ToString(millis / 1000);
            string signStr = appKey + Truncate(flownumber) + salt + curtime + appSecret;;
            string sign = ComputeHash(signStr, new SHA256CryptoServiceProvider());
            dic.Add("flownumber", flownumber);
            dic.Add("downloadFileType", "文件下載類型");
            dic.Add("appKey", appKey);
            dic.Add("salt", salt);
            dic.Add("curtime", curtime);
            dic.Add("sign", sign);
            dic.Add("docType", "json");
            dic.Add("signType", "v3");
            string result = Post(url, dic);
            Console.WriteLine(result);
        }

        protected static string ComputeHash(string input, HashAlgorithm algorithm)
        {
          Byte[] inputBytes = Encoding.UTF8.GetBytes(input);
          Byte[] hashedBytes = algorithm.ComputeHash(inputBytes);
          return BitConverter.ToString(hashedBytes).Replace("-", "");
        }

        protected static string Truncate(string q)
        {
            if (q == null)
            {
               return null;
            }
            int len = q.Length;
            return len <= 20 ? q : (q.Substring(0, 10) + len + q.Substring(len - 10, 10));
        }

        protected static string LoadAsBase64(string filename)
        {
            try
            {
                FileStream filestream = new FileStream(filename, FileMode.Open);
                byte[] arr = new byte[filestream.Length];
                filestream.Position = 0;
                filestream.Read(arr, 0, (int)filestream.Length);
                filestream.Close();
                return Convert.ToBase64String(arr);
            }
            catch (Exception ex)
            {
                return null;
            }
        }

        protected static string Post(string url, Dictionary dic)
        {
            string result = "";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            StringBuilder builder = new StringBuilder();
            int i = 0;
            foreach (var item in dic)
            {
                if (i > 0)
                    builder.Append("&");
                builder.AppendFormat("{0}={1}", item.Key, item.Value);
                i++;
            }
            byte[] data = Encoding.UTF8.GetBytes(builder.ToString());
            req.ContentLength = data.Length;
            using (Stream reqStream = req.GetRequestStream())
            {
                reqStream.Write(data, 0, data.Length);
                reqStream.Close();
            }
            HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
            Stream stream = resp.GetResponseStream();
            using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
            {
                result = reader.ReadToEnd();
            }
            return result;
        }
    }
}

PHP 示例

<?php
define("CURL_TIMEOUT",   2000);
define("URL_UPLOAD",     "https://openapi.youdao.com/file_convert/upload");
define("URL_QUERY",      "https://openapi.youdao.com/file_convert/query");
define("URL_DOWNLOAD",   "https://openapi.youdao.com/file_convert/download");
define("APP_KEY",        "您的應(yīng)用ID"); // 替換為您的應(yīng)用ID
define("SEC_KEY",        "您的應(yīng)用密鑰"); // 替換為您的密鑰

function upload()
{
     $file = "文件的路徑";
     $fp = fopen($file, "r") or die("Can't open file");
     // base64編碼
     $q = base64_encode(fread($fp, filesize($file)));
     fclose($fp);
     $salt = create_guid();
     $curtime = strtotime("now");
     $signStr = APP_KEY . truncate($q) . $salt . $curtime . SEC_KEY;
     $args = array(
        'appKey' => APP_KEY,
        'salt' => $salt,
     );
     $args['q'] = $q;
     $args['fileName'] = '文件名稱';
     $args['fileType'] = '文件類型';
     $args['curtime'] = $curtime;
     $args['sign'] = hash("sha256", $signStr);
     $args['docType'] = 'json';
     $args['signType'] = 'v3';
     $ret = call(URL_UPLOAD, $args);
     print_r($ret);
     $ret = json_decode($ret, true);
     return $ret;
}

function query()
{
     $flownumber = "文件流水號(hào)";
     $salt = create_guid();
     $curtime = strtotime("now");
     $signStr = APP_KEY . truncate($flownumber) . $salt . $curtime . SEC_KEY;
     $args = array(
        'appKey' => APP_KEY,
        'salt' => $salt,
     );
     $args['flownumber'] = $flownumber;
     $args['curtime'] = $curtime;
     $args['sign'] = hash("sha256", $signStr);
     $args['docType'] = 'json';
     $args['signType'] = 'v3';
     $ret = call(URL_QUERY, $args);
     print_r($ret);
     $ret = json_decode($ret, true);
     return $ret;
}

function download()
{
     $flownumber = "文件流水號(hào)";
     $salt = create_guid();
     $curtime = strtotime("now");
     $signStr = APP_KEY . truncate($flownumber) . $salt . $curtime . SEC_KEY;
     $args = array(
        'appKey' => APP_KEY,
        'salt' => $salt,
     );
     $args['flownumber'] = $flownumber;
     $args['downloadFileType'] = '文件下載類型';
     $args['curtime'] = $curtime;
     $args['sign'] = hash("sha256", $signStr);
     $args['docType'] = 'json';
     $args['signType'] = 'v3';
     $ret = call(URL_DOWNLOAD, $args);
     print_r($ret);
     $ret = json_decode($ret, true);
     return $ret;
}

// 發(fā)起網(wǎng)絡(luò)請(qǐng)求
function call($url, $args=null, $method="post", $testflag = 0, $timeout = CURL_TIMEOUT, $headers=array())
{
    $ret = false;
    $i = 0;
    while($ret === false)
    {
        if($i > 1)
            break;
        if($i > 0)
        {
            sleep(1);
        }
         $ret = callOnce($url, $args, $method, false, $timeout, $headers);
         $i++;
    }
    return $ret;
}

function callOnce($url, $args=null, $method="post", $withCookie = false, $timeout = CURL_TIMEOUT, $headers=array())
{
    $ch = curl_init();
    if($method == "post")
    {
        $data = convert($args);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_POST, 1);
    }
    else
    {
        $data = convert($args);
        if($data)
        {
            if(stripos($url, "?") > 0)
            {
                 $url .= "&$data";
            }
            else
            {
                 $url .= "?$data";
            }
        }
    }
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    if(!empty($headers))
    {
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    }
    if($withCookie)
    {
        curl_setopt($ch, CURLOPT_COOKIEJAR, $_COOKIE);
    }
    $r = curl_exec($ch);
    curl_close($ch);
    return $r;
}

function convert(&$args)
{
    $data = '';
    if (is_array($args))
    {
        foreach ($args as $key=>$val)
        {
            if (is_array($val))
            {
                foreach ($val as $k=>$v)
                {
                     $data .= $key.'['.$k.']='.rawurlencode($v).'&';
                }
            }
            else
            {
                     $data .="$key=".rawurlencode($val)."&";
            }
        }
        return trim($data, "&");
    }
    return $args;
}

// uuid generator
function create_guid(){
    $microTime = microtime();
    list($a_dec, $a_sec) = explode(" ", $microTime);
    $dec_hex = dechex($a_dec* 1000000);
    $sec_hex = dechex($a_sec);
    ensure_length($dec_hex, 5);
    ensure_length($sec_hex, 6);
    $guid = "";
    $guid .= $dec_hex;
    $guid .= create_guid_section(3);
    $guid .= '-';
    $guid .= create_guid_section(4);
    $guid .= '-';
    $guid .= create_guid_section(4);
    $guid .= '-';
    $guid .= create_guid_section(4);
    $guid .= '-';
    $guid .= $sec_hex;
    $guid .= create_guid_section(6);
    return $guid;
}

function truncate($q) {
    $len = abslength($q);
    return $len <= 20 ? $q : (mb_substr($q, 0, 10) . $len . mb_substr($q, $len - 10, $len));
}

function abslength($str)
{
    if(empty($str)){
        return 0;
    }
    if(function_exists('mb_strlen')){
        return mb_strlen($str,'utf-8');
    }
    else {
        preg_match_all("/./u", $str, $ar);
        return count($ar[0]);
    }
}

function ensure_length(&$string, $length){
    $strlen = strlen($string);
    if($strlen < $length)
    {
         $string = str_pad($string, $length, "0");
    }
    else if($strlen > $length)
    {
         $string = substr($string, 0, $length);
    }
}

function create_guid_section($characters){
    $return = "";
    for($i = 0; $i < $characters; $i++)
    {
         $return .= dechex(mt_rand(0,15));
    }
    return $return;
}
// 輸入
upload();
query();
download();
?>