You need to enable JavaScript to run this app.
导航

离线功能授权

最近更新时间2023.09.02 22:09:04

首次发布时间2023.09.02 22:09:04

C接口

头文件:

#include "sami_core.h"

接入步骤

  1. 初始化Context

函数名:

int SAMICoreInitContext(SAMICoreContextType contextType, void* params)

作用:
在调用SAMI SDK的创建功能句柄之前,请先通过SAMICoreInitContext设置token和appKey初始化Context,只需要初始化一次。
参数说明:

参数名参数类型参数说明
contextTypeSAMICoreContextType待初始化的Context类型,选择TokenVerifyMixedContext
paramsSAMICoreTokenVerifyMixedParameter待初始化的参数,详见sami_core_auth_check.h

返回值
成功返回SAMI_OK,失败请查看sami_core_error_code.h定义的错误码。

  1. 调用功能

详见具体的功能使用文档

  1. 释放Context内存

函数名:

int SAMICoreReleaseContext(SAMICoreContextType type)

作用:
在使用完SAMI SDK的功能后,需要释放Context的内存,与SAMICoreInitContext成对使用。
参数说明

参数名参数类型参数说明
typeSAMICoreContextType待释放的Context类型,这里是对齐SAMICoreInitContext调用的type

返回值
成功返回SAMI_OK,失败请查看sami_core_error_code.h定义的错误码。

完整示例

#include "sami_core.h"
#include <iostream>
#include <cstring>

int main(int argc, char* argv[]) {

    //step 1 : init context
    SAMICoreTokenVerifyMixedParameter parameter;
    memset(&parameter, 0, sizeof(parameter));
    parameter.token = "your token";
    parameter.appKey = "your appkey";
    parameter.extra = nullptr;
    int ret = SAMICoreInitContext(SAMICoreContextType::TokenVerifyMixedContext, &parameter);
    if(ret != SAMI_OK) {
        std::cout << "init mixed token context failed" << std::endl;
        return -1;
    }
 
    //step 2: 调用功能

    //step 3: release context
    SAMICoreReleaseContext(SAMICoreContextType::TokenVerifyMixedContext);
}
Java接口

引入的类:

import com.mammon.audiosdk.SAMICore;
import com.mammon.audiosdk.SAMICoreCode;
import com.mammon.audiosdk.enums.SAMICoreDataType;
import com.mammon.audiosdk.enums.SAMICoreIdentify;
import com.mammon.audiosdk.structures.SAMICoreBlock;
import com.mammon.audiosdk.structures.SAMICoreTokenResult;

使用步骤

  1. 初始化Context

函数名:

public class SAMICore {
    public static int InitContext(Context context, String appKey, SAMICoreContextType tokenType, String token)
}

作用:

在调用SAMI SDK的创建功能句柄之前,请先通过SAMICore::InitContext设置token和appKey初始化Context,整个APP只需要初始化一次。
  参数说明:

参数名参数类型参数说明
contextContextandroid上下文context
appKeyString在火山引擎获取,查看上文简介
contextTypeSAMICoreContextTypetoken类型,选择TokenVerifyMixedContext
tokenString在火山引擎获取,查看授权介绍

返回值
  具体错误码参考 com.mammon.audiosdk.SAMICoreCode

返回值含义
SAMI_OK成功
其他失败
  1. 调用功能

    详见具体的功能使用文档

  2. 释放Context内存

    函数名:

    public class SAMICore {
        public static void ReleaseContext(Context context, SAMICoreContextType tokenType);
    }
    

作用:
在使用完SAMI SDK的功能后,需要释放相关的内存,与SAMICore::InitContext成对使用。

参数说明

参数名参数类型参数说明
contextContextandroid上下文context
typeSAMICoreContextType待释放的Context类型,这里是TokenVerifyMixedContext

返回值
  具体错误码参考 com.mammon.audiosdk.SAMICoreCode

返回值含义
SAMI_OK成功
其他失败

完整示例

//step 1 : 设置授权
String appKey = "填写实际的appkey";
String token = "填写实际的token";
int ret = SAMICore.InitContext(MainActivity.this,appKey, SAMICoreContextType.TokenVerifyMixedContext,token);
if(ret != SAMICoreCode.SAMI_OK){
    Log.e(TAG,"InitContext result:"+ret);
}

//step 2 : 调用具体功能

//step 3 : 释放内存
SAMICore.ReleaseContext(this, SAMICoreContextType.TokenVerifyMixedContext);
Objective-C 接口

头文件:

#import "SAMICore.h"

接入步骤

  1. 初始化Context

    函数名:

    @interface SAMICore: NSObject
    + (int)initContextWithType:(SAMICore_ContextType)type
                     parameter:(id _Nonnull)params;
    @end
    

    作用:
      在调用SAMI SDK的创建功能句柄之前,设置token和appKey初始化Context,整个APP只需要初始化一次。
      参数说明:

    参数名参数类型参数说明
    typeSAMICore_ContextType待初始化的Context类型,选择SAMICore_TokenVerifyMixedContext
    parameterSAMICoreTokenVerifyOfflineParameter待初始化的参数,详见对应头文件

    返回值
      具体错误码参考SAMICoreCode.h

    返回值含义
    SAMI_OK成功
    其他失败
  2. 调用功能

详见具体的功能使用文档


  1. 释放Context内存

    函数名:

    @interface SAMICore: NSObject
    + (int)releaseContext:(SAMICore_ContextType)type;
    @end
    

    作用:
      在使用完SAMI SDK的功能后,需要释放Context的内存,与SAMICore::initContextWithType成对使用。
      参数说明:

    参数名参数类型参数说明
    typeSAMICore_ContextType上文初始化的SAMICore_ContextType类型

    返回值
      具体错误码参考SAMICoreCode.h

    返回值含义
    SAMI_OK成功
    其他失败

    完整示例

    //1.初始化
    SAMICore_TokenVerifyOfflineParameter *offlineParameter = [[SAMICore_TokenVerifyOfflineParameter alloc] init];
    offlineParameter.token = tokenValue;
    offlineParameter.appKey = appKeyValue;
    offlineParameter.extra = nil;
        
    int ret = [SAMICore initContextWithType:SAMICore_TokenVerifyMixedContext parameter:offlineParameter];
    
    //2.调用具体功能
    
    //3.释放相关资源
    ret = [SAMICore releaseContext:SAMICore_TokenVerifyMixedContext];