小雅OS开放平台文档

小雅OS开放平台文档

  • 快速入门
  • 客户端接入
  • 服务端接入

›iOS SDK

概述

  • 客户端接入

API 接入

  • WebSocket接口协议定义
  • Http接口协议定义
  • 调用样例
  • API 列表
  • 实体列表
  • 错误码

设备端

    Android SDK

    • 配置工程
    • 初始化
    • 功能
    • 回调
    • Demo 使用
    • 更新日志

    iOS SDK

    • 配置工程
    • 初始化
    • 功能
    • 回调
    • 更新日志

    C++ SDK

    • SDK获取方法
    • 环境要求
    • 目录结构
    • SDK架构
    • 调用示例
    • 接口文档

手机伴侣

    Android SDK

    • 接入准备
    • 账号模块
    • 内容模块
    • 反向控制
    • 设备管理模块
    • 技能模块
    • 蓝牙模块
    • 更新日志

    iOS SDK

    • 接入准备
    • 账号模块
    • 内容模块
    • 反向控制
    • 设备管理模块
    • 技能模块

内容页

    Android

    • 更新日志
    • 初始化

    iOS

    • 更新日志
    • 初始化

技能模块

获取设备激活的技能列表:

/**
* 请求用户设备的技能列表
*/
+ (void)requestUserSkillListWithProductId:(NSString *)productId 
success:(nullable void(^)(NSArray * _Nullable skillList))success 
failure:(nullable void (^)(NSError *error))failure;

所需参数如下:

productId: 设备id

返回值为数组:

[{
        "id": 16,
        "createdAt": 1548993821000,
        "updatedAt": 1548993821000,
        "skillId": "os.skill.qa",
        "name": "问答",
        "type": 0,
        "category": "工具",
        "clientId": null,
        "icon": "http://fdfs.xmcdn.com/group31/M00/77/26/wKgJX1l1xqrSlUB2AAAU44wYum4236.jpg",
        "description": "翻译、股票日常问答;人物、地理、历史等丰富的百科知识",
        "cmdSamples": "大象的英文怎么说;世界上跑的最快的动物;世界上最高的山是什么",
        "version": "v1.0",
        "versionDescription": "系统原生技能",
        "status": 1,
        "act": null,
        "serviceUrl": null,
        "ptfId": null,
        "wakeName": null
    },
    {
        "id": 15,
        "createdAt": 1548993779000,
        "updatedAt": 1548993779000,
        "skillId": "os.skill.calculator",
        "name": "计算器",
        "type": 0,
        "category": "工具",
        "clientId": null,
        "icon": "http://fdfs.xmcdn.com/group31/M00/77/26/wKgJX1l1xqrSlUB2AAAU44wYum4236.jpg",
        "description": "加减乘除混合运算以及根号、平方等复杂运算。不用再打开手机计算器来点了,吃饭AA,买东西拼单,无论什么数学运算问题,分分钟帮你算好",
        "cmdSamples": "15乘以15是多少;二的平方等于多少;15加45加120等于多少",
        "version": "v1.0",
        "versionDescription": "系统原生技能",
        "status": 1,
        "act": null,
        "serviceUrl": null,
        "ptfId": null,
        "wakeName": null
    }
]

获取技能详情

/**
* 请求技能详情
*/
+ (void)requestSkillDetailWithSkillId:(NSString *)skillId 
skillVersion:(NSString *)version 
success:(nullable void(^)(NSDictionary *skillDic))success 
failure:(nullable void (^)(NSError * _Nullable error))failure;

返回值如下:

{
    "version": "1.0",
    "session": {
        "sid": "49ed2b9e2b09187f22a815bc499c6540",
        "attributes": {}
    },
    "cookies": {},
    "nlu": [{
        "domain": "BizApp",
        "intent": "skillDetail",
        "slots": {
            "skill_id": "os.skill.14"
        },
        "env": "online"
    }],
    "asr": null,
    "response": {
        "outputSpeech": {
            "type": "",
            "text": "",
            "ssml": "",
            "playBehavior": ""
        },
        "card": {},
        "directives": [],
        "data": {
            "skill_version": "v1.0",
            "skill_version_update_time": 1553830965000,
            "skill_update": 0,
            "skill_icon": "http://fdfs.xmcdn.com/group57/M0A/44/18/wKgLgVydw9bhkzAIAAAuF7djPdE529.png",
            "user_skill_score": 0,
            "skill_usage": [{
                "usage_type": "指令示例",
                "usage_detail_list": [{
                    "usage_detail": "我想听郭德纲的相声"
                }, {
                    "usage_detail": "给我来一段评书"
                }, {
                    "usage_detail": "我要听广播"
                }, {
                    "usage_detail": "我想听睡前故事\n\n"
                }]
            }],
            "score_num": 0,
            "skill_company": "",
            "skill_name": "有声内容",
            "skill_introduce": "我们拥有丰富的音频内容,涵盖相声段子、有声书、综艺娱乐、情感生活、评书、外语、培训讲座、广播剧、商业财经、健康养生、汽车、旅游、电影等20多个分类,快来点播吧",
            "platform_id": "",
            "skill_login": 0,
            "skill_id": "os.skill.14",
            "skill_score": 0,
            "skill_no": 0,
            "skill_version_info": "系统默认技能",
            "skill_company_url": ""
        },
        "nextScene": null,
        "shouldEndSession": true
    }
}

技能绑定喜马拉雅账号

对于部分喜马拉雅技能需要绑定喜马拉雅账号才能使用,因此在获取技能详情时,通过判断登录状态,提供绑定功能:

{
    "loginDetail": {
        "skillPtfId": "os.ptf.xmly.testsdkdemo",
        "thirdAuth": {
            "redirectUri": "http://skill-xypubtest.ainirobot.com/xy-os-console/xy-os-ucenter/account/auth-callback/os.ptf.xmly.testsdkdemo",
            "tokenUrl": "https://api.ximalaya.com/oauth2/v2/access_token",
            "authCredUrl": "https://api.ximalaya.com/oauth2/v2/authorize",
            "refreshUrl": "https://api.ximalaya.com/oauth2/refresh_token",
            "thirdClientId": "a25f0afd27887f679240e88646c5fd5c",
            "bindIndex": 2,
            "authUrl": "https://m.ximalaya.com/login",
            "createdAt": 1559723181000,
            "responseType": "code",
            "thirdClientSecret": "43e0a59b43c4afd5c6637efe927d3a53",
            "id": 213,
            "ptfId": "os.ptf.xmly.testsdkdemo",
            "updatedAt": 1559723181000
        },
        "status": 0
    }
}

status 为0:需要登录,1:已登录,2:无需登录

NSString *fromUri = [NSString stringWithFormat:@"%@?client_id=%@&response_type=code&redirect_uri=%@&device_id=%@&client_os_type=3", thirdAuth.authCredUrl, thirdAuth.thirdClientId, redrectUrl, deviceId];
// 授权url
NSString *urlString = [NSString stringWithFormat:@"%@?fromUri=%@", thirdAuth.authUrl, encodeFromUri];

技能退出登录

使用 XYSDK+Account.h 接口:

/**
* 解绑第三方账户(目前默认为解绑喜马拉雅)
*/
+ (void)requestThirdUnbind:(NSString *_Nullable)skillId completionBlock:(nullable void(^)(NSDictionary *__nullable result, NSError * _Nullable error))block;
← 设备管理模块更新日志 →
  • 获取设备激活的技能列表:
  • 获取技能详情
  • 技能绑定喜马拉雅账号
  • 技能退出登录
北京小雅星空科技有限公司 京ICP备19010603号