接口URL
http://api.polyv.net/live/v3/channel/document/upload-doc
接口说明
(接口调用有频率限制,详细请查看)
1、作用:上传频道文档接口
2、说明:上传的文件不超过50M,格式限制为(ppt, pdf,pptx,doc,docx,wps, xls,xlsx)。
3、接口支持https协议
返回结果支持格式
JSON
请求方式
POST
请求数限制
TRUE
请求参数
参数名 | 必选 | 类型 | 说明 |
---|---|---|---|
appId | 是 | string | 从API设置中获取,在直播系统登记的appId |
sign | 是 | string | 签名,32位大写MD5值 |
timestamp | 是 | string | 当前13位毫秒级时间戳,3分钟内有效 |
channelId | 是 | string | 频道ID |
type | 否 | string | 转换类型(‘common’:转普通图片, ‘animate’:转动画效果)默认不传转普通,因为只有ppt,pptx可以转动画,其他类型文件会自动转成普通;文件转动画转失败会直接把类型转为普通 |
file | 是 | 本地上传文件 | 上传的文件不超过50M,格式限制为(ppt, pdf,pptx,doc,docx,wps, xls,xlsx) |
docName | 否 | string | 文档名称(不传默认使用ppt上传的文件获取到的文件名作为文档名称,文档名称不得超过100个字符) |
callbackUrl | 否 | string | 文档上传转换成功回调地址 |
响应成功JSON示例:
{
"code":200,
"status":"success",
"message":"",
"data": {
"fileId": "xxxxxxxxx",
"type": "common",
"autoId": 1212,
"status": "waitConvert"
}
}
响应异常JSON示例:
未输入appId
{
"code": 400,
"status": "error",
"message": "appId is required.",
"data": ""
}
appId不正确
{
"code": 400,
"status": "error",
"message": "application not found.",
"data": ""
}
时间戳错误
{
"code": 400,
"status": "error",
"message": "invalid timestamp.",
"data": ""
}
签名错误
{
"code": 403,
"status": "error",
"message": "invalid signature.",
"data": ""
}
字段说明
参数名 | 说明 |
---|---|
status | 响应状态 |
data | 成功信息 |
data.fileId | 成功时返回文件ID |
data.autoId | 成功时返回文件记录自增标识id |
data.type | 转换类型(‘common’:转普通图片, ‘animate’:转动画效果)只有ppt,pptx会转动画,其中会自动转成普通,转动画转失败也会直接把类型转为普通 |
data.status | 文件转换状态(“normal” :正常,"waitConvert":转换PPT中,"failConvert":转换PPT失败) |
code | 异常错误代码 |
message | 请求失败时的异常错误信息 |
php请求示例
<?php
//引用config.php
include 'config.php';
//接口需要的参数(非sign)赋值
$appId = "XXXXXXXX";
$channelId = "127075";
$file = 'C:\Users\polyv\Desktop\timg.jpg';
$params = array(
'appId'=>$appId,
'timestamp'=>$timestamp,
'channelId'=>$channelId,
);
//生成sign
$sign = getSign($params); //详细查看config.php文件的getSign方法
$data = array(
'appId' => $appId,
'timestamp' => $timestamp,
'sign' => $sign,
'channelId'=>$channelId,
'file' => new CURLFile(realpath($file))
);
$url = "http://api.polyv.net/live/v3/channel/document/upload-doc";
$ch = curl_init() or die ( curl_error() );
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 360);
$reponse = curl_exec ( $ch );
curl_close ( $ch );
print_r($reponse);
?>
java请求示例
public class SetCoverImg {
private static RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(15000).setConnectTimeout(15000)
.setConnectionRequestTimeout(15000).build();
public static void main(String[] args) {
Integer channelId = 108888; // 频道号
String appId = "XXXXXXXX"; // 应用Id
String appSecret = "XXXXXXXX"; // 应用密匙
Long timestamp = System.currentTimeMillis(); // 13位毫秒级时间戳
// 构建签名
String sign = DigestUtils.md5Hex(appSecret + "appId" + appId + "channelId" + channelId + "timestamp" + timestamp + appSecret).toUpperCase();
String url = String.format("http://api.polyv.net/live/v3/channel/document/upload-doc", channelId);
Map<String, String> map = new HashMap<>();
map.put("appId", appId);
map.put("channelId", String.valueOf(channelId));
map.put("timestamp", String.valueOf(timestamp));
map.put("sign", sign);
// 图片的本地文件路径,推荐128X128
File file = new File("C:\\Users\\lenovo\\Desktop\\demo.ppt");
String responBody = sendHttpPost(url, map, file);
System.out.println(responBody);
}
/**
* 发送 post请求(带文件)
* @param httpUrl 地址
* @param maps 参数
* @param file 上传文件
*/
private static String sendHttpPost(String httpUrl, Map<String, String> maps, File file) {
HttpPost httpPost = new HttpPost(httpUrl);// 创建httpPost
MultipartEntityBuilder meBuilder = MultipartEntityBuilder.create();
// 设置此参数后可以保证服务器拿到的文件名不会出现乱码
meBuilder.setMode(HttpMultipartMode.RFC6532);
for (String key : maps.keySet()) {
meBuilder.addPart(key, new StringBody(maps.get(key), ContentType.TEXT_PLAIN));
}
FileBody fileBody = new FileBody(file);
meBuilder.addPart("file", fileBody); // imgfile 图片对应参数名
HttpEntity reqEntity = meBuilder.build();
httpPost.setEntity(reqEntity);
return sendHttpPost(httpPost);
}
/**
* 发送Post请求
*/
private static String sendHttpPost(HttpPost httpPost) {
CloseableHttpClient httpClient = null;
CloseableHttpResponse response = null;
HttpEntity entity;
String responseContent = null;
try {
// 创建默认的httpClient实例.
httpClient = HttpClients.createDefault();
httpPost.setConfig(requestConfig);
// 执行请求
response = httpClient.execute(httpPost);
entity = response.getEntity();
responseContent = EntityUtils.toString(entity, "UTF-8");
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
// 关闭连接,释放资源
if (response != null) {
response.close();
}
if (null != httpPost) {
httpPost.releaseConnection();
}
if (httpClient != null) {
httpClient.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return responseContent;
}
}
签名规则(config.php文件代码查看)
http://dev.polyv.net/2018/liveproduct/l-api/rule/sign/
回调说明
该接口为的ppt转换图片、动画等过程为异步处理过程,如果需要获取合并的结果,可以在请求接口时提交callbackUrl 参数,在程序转换ppt成功后,会对callbackUrl 进行回调通知
回调参数
参数 | 说明 |
---|---|
fileId | 文件ID,成功时返回 |
channelId | 频道ID |
status | 文件转换状态(“normal” :正常,"failConvert":转换PPT失败) |
timestamp | 13位时间戳 |
sign | 加密串(channelId 加上 timestamp 后得到的字符串进行MD5后得到) |