# 智能PPT生成
有奖调研 (opens new window)诚邀您参与我们星火智能PPT生成服务有奖调研,参与问卷即有机会获取超大服务包。技术咨询可直接提交工单 (opens new window)
# 接口调用流程图

# 接口调用示例
部分开发语言Demo如下,其他开发语言请参照文档进行开发,欢迎大家到讯飞开放平台社区 (opens new window)交流集成经验。
智能PPT生成API Demo java语言 (opens new window)
 智能PPT生成API Demo python语言 (opens new window)
# 接口与鉴权
# 接口域名
zwapi.xfyun.cn
# 获取签名
在HTTP请求头 header 中设置参数:
appId,timestamp,signature
String appId = "应用ID";
String secret = "应用的秘钥";
long timestamp = System.currentTimeMillis()/1000;
String signature = ApiAuthAlgorithm.getSignature(appId, secret, timestamp);
request.setHeader("appId",appId);
request.setHeader("timestamp",timestamp);
request.setHeader("signature",signature);
| 字段名 | 类型 | 描述 | 必须 | 默认值 | 
|---|---|---|---|---|
| appId | String | 应用ID | Y | |
| timestamp | Long | 时间戳,单位: s,与服务端时间相差五分钟之内 | Y | |
| signature | String | 签名 | Y | 
# DEMO
ApiAuthAlgorithm.class鉴权类
public class ApiAuthAlgorithm {
    private static final char[] MD5_TABLE = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
    /**
     * 获取签名
     *
     * @param appId    签名的key
     * @param secret 签名秘钥
     * @return 返回签名
     */
    public String getSignature(String appId, String secret, long ts) {
        try {
            String auth = md5(appId + ts);
            return hmacSHA1Encrypt(auth, secret);
        } catch (SignatureException e) {
            return null;
        }
    }
    /**
     * sha1加密
     *
     * @param encryptText 加密文本
     * @param encryptKey  加密键
     * @return 加密
     */
    private String hmacSHA1Encrypt(String encryptText, String encryptKey) throws SignatureException {
        byte[] rawHmac;
        try {
            byte[] data = encryptKey.getBytes(StandardCharsets.UTF_8);
            SecretKeySpec secretKey = new SecretKeySpec(data, "HmacSHA1");
            Mac mac = Mac.getInstance("HmacSHA1");
            mac.init(secretKey);
            byte[] text = encryptText.getBytes(StandardCharsets.UTF_8);
            rawHmac = mac.doFinal(text);
        } catch (InvalidKeyException e) {
            throw new SignatureException("InvalidKeyException:" + e.getMessage());
        } catch (NoSuchAlgorithmException e) {
            throw new SignatureException("NoSuchAlgorithmException:" + e.getMessage());
        }
        return new String(Base64.encodeBase64(rawHmac));
    }
    private String md5(String cipherText) {
        try {
            byte[] data = cipherText.getBytes();
            // 信息摘要是安全的单向哈希函数,它接收任意大小的数据,并输出固定长度的哈希值。
            MessageDigest mdInst = MessageDigest.getInstance("MD5");
            // MessageDigest对象通过使用 update方法处理数据, 使用指定的byte数组更新摘要
            mdInst.update(data);
            // 摘要更新之后,通过调用digest()执行哈希计算,获得密文
            byte[] md = mdInst.digest();
            // 把密文转换成十六进制的字符串形式
            int j = md.length;
            char[] str = new char[j * 2];
            int k = 0;
            for (byte byte0 : md) { // i = 0
                str[k++] = MD5_TABLE[byte0 >>> 4 & 0xf]; // 5
                str[k++] = MD5_TABLE[byte0 & 0xf]; // F
            }
            // 返回经过加密后的字符串
            return new String(str);
        } catch (Exception e) {
            return null;
        }
    }
}
# 错误码
| 错误码 | 描述 | 处理方式 | 
|---|---|---|
| 20002 | 参数错误 | 确认接口入参 | 
| 20005 | 大纲生成失败 | 查看是否存在敏感词汇,尝试重新生成 | 
| 20006 | PPT生成失败 | PPT导出错误,请重新生成或联系技术人员 | 
| 20007 | 鉴权错误 | 检查鉴权信息 | 
| 9999 | 系统异常 | 确认鉴权信息、请求方式、请求参数是否有误,或联系技术人员排查相关日志 | 
# 接口列表
# 1、PPT主题列表查询
1.1 接口地址:
GET   https://zwapi.xfyun.cn/api/aippt/themeList
1.2 响应参数:
{
    "flag": true,
    "code": 0,
    "desc": "成功",
    "count": null,
    "data": [
        {
            "key": purple,					// 主题名
            "name": "紫影幽蓝",
            "thumbnail": "xxx",				// 缩略图
        }
    ]
}
1.3 主题图片:
注意:此处仅展示部分主题图片,如需查看更多主题图片,请调用PPT主题列表查询接口获取。

# 2、PPT生成(直接根据用户输入要求,获得最终PPT)
2.1 接口描述:
基于用户提示、要求等相关内容生成PPT,字数不得超过8000字。
2.2 接口地址:
https://zwapi.xfyun.cn/api/aippt/create
2.3 请求查询参数:
POST,application/json
| 名称 | 类型 | 描述 | 必须 | 默认值 | 
|---|---|---|---|---|
| query | String | 用户生成PPT要求(最多8000字) | Y | |
| create_model | String | PPT生成类型:文本生成、话题生成、程序判断(默认) | N | auto | 
| theme | String | PPT生成主题:随机主题(默认)、紫影幽蓝…… | N | auto | 
| business_id | String | 业务ID(非必传)- 业务方自行决定是否使用 | N | |
| author | String | PPT作者名:用户自行选择是否设置作者名 | N | 智文 | 
| is_card_note | Bool | 是否生成PPT演讲备注 | N | false | 
| is_cover_img | Bool | 是否需要封面图 | N | false | 
| language | String | 语种 | N | cn | 
| is_figure | Bool | 是否自动配图 | N | false | 
2.4 可选参数列表:
create_model:
auto: 自动,由程序自行判断;
topic:话题生成(建议150字以内)
text:文本生成,基于长文本生成
theme(详细信息可通过主题查询接口获得):
auto:自动,随机主题
purple:紫色主题
green:绿色主题
lightblue:清逸天蓝
taupe:质感之境
blue:星光夜影
telecomRed:炽热暖阳
telecomGreen:幻翠奇旅
language:
- cn:中文(简体)
 - en:英语
 - ja:日语
 - ru:俄语
 - ko:韩语
 - de:德语
 - fr:法语
 - pt:葡萄牙语
 - es:西班牙语
 - it:意大利语
 - th:泰语
 
2.5 请求响应:
{
    "code":0,
    "desc":"成功",
    "data":{
    	"sid":"zhiwen@xxxxxxxxxxxxxxxxxxxxx",	// 请求唯一ID
        "coverImgSrc":"xxxxxxxxxxxxxx",			// 封面地址
        "title" : "xxx",						// 主标题
        "subTitle" : "xxx"						// 副标题
    }
}
2.6 响应描述
| 响应字段 | 类型 | 描述 | 
|---|---|---|
| code | int | 错误码 | 
| desc | string | 错误详情 | 
| data.sid | string | 请求唯一id | 
| data.CoverImgSrc | string | PPT封面图链接 | 
| data.title | string | PPT主标题 | 
| data.subTitle | string | PPT副标题 | 
# 3、自定义PPT生成接口
3.1 接口描述:
基于用户提示、文档等相关内容生成PPT,字数不得超过8000字,文件限制10M。
3.2 接口地址:
https://zwapi.xfyun.cn/api/aippt/createByDoc
3.3 请求查询参数:
POST,multipart/form-data
| 名称 | 类型 | 描述 | 必须 | 默认值 | 
|---|---|---|---|---|
| query | String | 用户生成PPT要求(最多8000字) | N | |
| file | MultipartFile | 上传文件 | N | |
| file_url | String | 文件连接 | N | file和file_url必须二选一 | 
| file_name | String | 文件名 | Y | 带文件名后缀 | 
| theme | String | PPT生成主题:随机主题(默认)、紫影幽蓝…… | N | auto | 
| business_id | String | 业务ID(非必传)- 业务方自行决定是否使用 | N | |
| author | String | PPT作者名:用户自行选择是否设置作者名 | N | 智文 | 
| is_card_note | Bool | 是否生成PPT演讲备注 | N | false | 
| is_cover_img | Boolean | 是否生成封面图 | N | false | 
| language | String | 语种 | N | cn | 
| is_figure | Bool | 是否自动配图 | N | false | 
3.4 请求响应:
{
    "code":0,
    "desc":"成功",
    "data":{
    	"sid":"zhiwen@xxxxxxxxxxxxxxxxxxxxx",	// 请求唯一ID
        "coverImgSrc":"xxxxxxxxxxxxxx",			// 封面地址
        "title" : "xxx",						// 主标题
        "subTitle" : "xxx"						// 副标题
    }
}
3.5 响应描述
| 响应字段 | 类型 | 描述 | 
|---|---|---|
| code | int | 错误码 | 
| desc | string | 错误详情 | 
| data.sid | string | 请求唯一id | 
| data.CoverImgSrc | string | PPT封面图链接 | 
| data.title | string | PPT主标题 | 
| data.subTitle | string | PPT副标题 | 
# 4、大纲生成
4.1 接口地址:
https://zwapi.xfyun.cn/api/aippt/createOutline
4.2 请求参数查询
POST,application/json
| 名称 | 类型 | 描述 | 必须 | 默认值 | 
|---|---|---|---|---|
| query | String | 用户生成PPT要求(最多8000字) | Y | |
| create_model | String | PPT生成类型:文本生成、话题生成、程序判断(默认) | N | auto | 
| theme | String | PPT生成主题:随机主题(默认)、紫影幽蓝…… | N | auto | 
| business_id | String | 业务ID(非必传)- 业务方自行决定是否使用 | N | |
| author | String | PPT作者名:用户自行选择是否设置作者名 | N | 智文 | 
| is_card_note | Bool | 是否生成PPT演讲备注 | N | false | 
| is_cover_img | Bool | 是否生成封面图 | N | false | 
| language | String | 语种 | N | cn | 
| is_figure | Bool | 是否自动配图 | N | false | 
4.3 请求响应
{
    "flag": true,
    "code": 0,
    "desc": "成功",
    "count": null,
    "data": {
        "sid": "本次请求sid",
        "coverImgSrc": "xxx(封面图下载链接)",
        "title": "主标题",
        "subTitle": "副标题",
        "outline": {
            "id": 68133,
            "title": "主标题",
            "subTitle": "副标题",
            "fileUrl": "",
            "fileType": 0,
            "chapters": [
                {
                    "id": 68189,
                    "chapterTitle": "第一章 xxx",
                    "fileUrl": "",
                    "fileType": 0,
                    "chartFlag": false,
                    "searchFlag": false,
                    "chapterContents": [
                        {
                            "id": 68221,
                            "chapterTitle": "1.1 xxx",
                            "fileUrl": "",
                            "fileType": 0,
                            "chartFlag": false,
                            "searchFlag": false,
                            "chapterContents": null
                        },
                        {
                            "id": 68223,
                            "chapterTitle": "1.2 xxx",
                            "fileUrl": "",
                            "fileType": 0,
                            "chartFlag": false,
                            "searchFlag": false,
                            "chapterContents": null
                        }
                    ]
                },
                {
                    "id": 68179,
                    "chapterTitle": "第二章 xxx",
                    "fileUrl": "",
                    "fileType": 0,
                    "chartFlag": false,
                    "searchFlag": false,
                    "chapterContents": [
                        {
                            "id": 68245,
                            "chapterTitle": "2.1 xxx",
                            "fileUrl": "",
                            "fileType": 0,
                            "chartFlag": false,
                            "searchFlag": false,
                            "chapterContents": null
                        },
                        {
                            "id": 68247,
                            "chapterTitle": "2.2 xxx",
                            "fileUrl": "",
                            "fileType": 0,
                            "chartFlag": false,
                            "searchFlag": false,
                            "chapterContents": null
                        }
                    ]
                }
            ],
            "end": "",
            "fileId": null
        }
    }
}
4.4 响应描述
| 响应字段 | 类型 | 描述 | 
|---|---|---|
| code | int | 错误码 | 
| desc | string | 错误详情 | 
| data.sid | string | 请求唯一id | 
| data.CoverImgSrc | string | PPT封面图链接 | 
| data.title | string | PPT主标题 | 
| data.subTitle | string | PPT副标题 | 
| outline.title | string | PPT主标题 | 
| outline.subTitle | string | PPT副标题 | 
| outline.chapters.chapterTitle | String | 章节标题 | 
| outline.end | String | 结尾 | 
4.5 大纲结构体说明
public class OutlineVo {
    // 大纲ID
    private Long id;
    // 主标题
    private String title;
    // 副标题
    private String subTitle;
    
    // 二级标题
    private List<Chapter> chapters;
    // 参考文件相关,暂未开放能力
    private String fileUrl = "";
    Integer fileType = 0;
    private String end = "";
    private String fileId;
    public static class Chapter {
        // 大纲ID,若为新增大纲则设为NULL
        Long id;
        // 章节、子章节标题名称
        String chapterTitle;
        
        // 参考文件相关,能力暂未开放
        String fileUrl = "";
        Integer fileType = 0;
        Boolean chartFlag = false;
        Boolean searchFlag = false;
        List<Chapter> chapterContents = null;
    }
}
# 5、自定义大纲生成
5.1 接口描述:
基于用户提示、文档等相关内容生成PPT大纲,字数不得超过8000字,文件限制10M。
上传文件支持pdf(不支持扫描件)、doc、docx、txt、md格式的文件。
5.2 接口地址:
https://zwapi.xfyun.cn/api/aippt/createOutlineByDoc
5.3 请求查询参数:
POST,multipart/form-data
| 名称 | 类型 | 描述 | 必须 | 默认值 | 
|---|---|---|---|---|
| query | String | 用户生成PPT要求(最多8000字) | N | |
| file | MultipartFile | 上传文件 | N | |
| file_url | String | 文件连接 | N | file和file_url必须二选一 | 
| file_name | String | 文件名 | Y | 带后缀 | 
| theme | String | PPT生成主题:随机主题(默认)、紫影幽蓝…… | N | auto | 
| business_id | String | 业务ID(非必传)- 业务方自行决定是否使用 | N | |
| author | String | PPT作者名:用户自行选择是否设置作者名 | N | 智文 | 
| is_card_note | Bool | 是否生成PPT演讲备注 | N | false | 
| is_cover_img | Bool | 是否生成封面图 | N | false | 
| language | String | 语种 | N | cn | 
| is_figure | Bool | 是否自动配图 | N | false | 
# 6、通过sid和修改后大纲生成PPT
6.1 接口地址:
https://zwapi.xfyun.cn/api/aippt/createBySid
6.2 请求查询参数:
POST,application/json
| 名称 | 类型 | 描述 | 必须 | 默认值 | 
|---|---|---|---|---|
| sid | String | 已生成大纲后,相应返回的请求唯一id | Y | |
| outline | String | 修改后大纲(若本次不传,则根据sid获得第一次生成的大纲内容进行ppt生成) | N | 首次生成的大纲 | 
6.3 请求响应与说明
见2.5、2.6小节说明
# 7、通过大纲生成PPT
7.1 接口地址:
https://zwapi.xfyun.cn/api/aippt/createByOutline
7.2 请求查询参数:
POST,application/json
| 名称 | 类型 | 描述 | 必须 | 默认值 | 
|---|---|---|---|---|
| query | String | 用户生成PPT要求(最多8000字) | Y | |
| outline | String | 大纲内容(不得超过10个一级大纲) | Y | |
| create_model | String | PPT生成类型:文本生成、话题生成、程序判断(默认) | N | auto | 
| theme | String | PPT生成主题:随机主题(默认)、紫影幽蓝…… | N | auto | 
| business_id | String | 业务ID(非必传)- 业务方自行决定是否使用 | N | |
| author | String | PPT作者名:用户自行选择是否设置作者名 | N | 智文 | 
| is_card_note | Bool | 是否生成PPT演讲备注 | N | false | 
| is_cover_img | Bool | 是否生成封面图 | N | false | 
| language | String | 语种(保证传入大纲语种与输入PPT语种一致) | N | cn | 
| is_figure | Bool | 是否自动配图 | N | false | 
7.3 请求响应与说明
见2.5、2.6小节说明
# 8、PPT进度查询
8.1 接口地址:
https://zwapi.xfyun.cn/api/aippt/progress?sid={}
8.2 请求查询参数:
注:该接口设置限流,三秒访问一次
GET
| 名称 | 类型 | 描述 | 必须 | 
|---|---|---|---|
| sid | String | 请求唯一ID | Y | 
{
    "code":0,
    "desc":"成功",
    "data":{
    	"process" : 0			// 生成进度:30-大纲生成完毕、70-PPT生成完毕、100-PPT导出完毕
    	"pptId" : xxxx			// pptId
    	"pptUrl" : xxxx			// ppt下载链接
    	"errMsg" : xxxx			// 错误信息
    }
}
# 扣量说明
- 基于query直接生成ppt:扣除10点量,1个并发,若需要增加备注,则增加5点量
 - 基于query生成大纲:扣除2点量1个并发
 - 基于sid,获取大纲(可修改)生成ppt:扣除8点量1个并发, 若在表中记录该sid生成的ppt需要生成备注,额外扣除5点量
 - 基于大纲生成ppt:8点量,若需要生成备注:额外扣除5点量
 - PPT自动配图:4点量
 - PPT多语种翻译:3点量,若仅生成大纲,则扣1点量