2024-03-18PPT WORD生成

随笔3个月前发布 梦马先生
27 0 0

讯飞智文OpenAPI协议文档

可用配置:

  • appid: xxx
  • secret: xxx

接口与鉴权

应用申请

提供工单开通接口权限

接口域名

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生成(直接根据用户输入要求,获得最终PPT)

1.1 接口描述:

基于用户提示、要求等相关内容生成PPT,字数不得超过8000字。

1.2 接口地址:

https://zwapi.xfyun.cn/api/aippt/create

1.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

1.4 可选参数列表:

  • create_model:

    • auto: 自动,由程序自行判断;

    • topic:话题生成(建议150字以内)

    • text:文本生成,基于长文本生成

  • theme(详细信息可通过主题查询接口获得):

    • auto:自动,随机主题

    • purple:紫色主题

    • green:绿色主题

    • lightblue:清逸天蓝

    • taupe:质感之境

    • blue:星光夜影

    • telecomRed:炽热暖阳

    • telecomGreen:幻翠奇旅

1.5 请求响应:

{
    "code":0,
    "desc":"成功",
    "data":{
        "sid":"zhiwen@xxxxxxxxxxxxxxxxxxxxx",   // 请求唯一ID
        "coverImgSrc":"xxxxxxxxxxxxxx",         // 封面地址
        "title" : "xxx",                        // 主标题
        "subTitle" : "xxx"                      // 副标题
    }
}

1.6 响应描述

响应字段 类型 描述
code int 错误码
desc string 错误详情
data.sid string 请求唯一id
data.CoverImgSrc string PPT封面图链接
data.title string PPT主标题
data.subTitle string PPT副标题

2 大纲生成

2.1 接口地址:

https://zwapi.xfyun.cn/api/aippt/createOutline

2.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

2.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
        }
    }
}

2.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 结尾

2.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;
    }
}

3 通过sid和修改后大纲生成PPT

3.1 接口地址:

https://zwapi.xfyun.cn/api/aippt/createBySid

3.2 请求查询参数:

POST,application/json

名称 类型 描述 必须 默认值
sid String 已生成大纲后,相应返回的请求唯一id Y
outline String 修改后大纲(若本次不传,则根据sid获得第一次生成的大纲内容进行ppt生成) N 首次生成的大纲

3.3 请求响应与说明

见1.5、1.6小节说明

4 通过大纲生成PPT

4.1 接口地址:

https://zwapi.xfyun.cn/api/aippt/createByOutline

4.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

4.3 请求响应与说明

见1.5、1.6小节说明

5 PPT进度查询

5.1 接口地址:

https://zwapi.xfyun.cn/api/aippt/progress?sid={}

5.2 请求查询参数:

注:该接口设置限流,三秒访问一次

GET

名称 类型 描述 必须
sid String 请求唯一ID Y

{
    "code":0,
    "desc":"成功",
    "data":{
        "process" : 0           // 生成进度:30-大纲生成完毕、70-PPT生成完毕、100-PPT导出完毕
        "pptId" : xxxx          // pptId
        "pptUrl" : xxxx         // ppt下载链接
    }
}

6 PPT主题列表查询

6.1 接口地址:

https://zwapi.xfyun.cn/api/aippt/themeList

6.2 请求查询参数:

GET

{
    "flag": true,
    "code": 0,
    "desc": "成功",
    "count": null,
    "data": [
        {
            "key": purple,                  // 主题名
            "name": "紫影幽蓝",
            "thumbnail": "xxx",             // 缩略图
        }
    ]
}

7 扣量说明

  • 基于query直接生成ppt:扣除10点量,1个并发,若需要增加备注,则增加5点量;
  • 基于query生成大纲:扣除2点量1个并发
  • 基于sid,获取大纲(可修改)生成ppt:扣除8点量1个并发, 若在表中记录该sid生成的ppt需要生成备注,额外扣除5点量;
  • 基于大纲生成ppt:8点量,若需要生成备注:额外扣除5点量
© 版权声明

相关文章

暂无评论

您必须登录才能参与评论!
立即登录
暂无评论...