用户权益扣减

如图所示:

  • 用户点击下载时,稿定编辑器SDK通过钩子方法(由合作方实现)获取权益使用凭证
  • 编辑器SDK根据权益使用凭证去进行合作方权益扣除和作品下载

获取权益使用凭证接口

接口说明:根据企业用户ID,获取SDK的授权码,接口调用方式请参考:开放API对接文档

body参数

字段

类型

是否必填

字段描述

app_id

string

应用ID,使用回调方法async getUseRightCert(info)中的info.appId

ability_code

string

开放API能力编码,使用回调方法async getUseRightCert(info)中的info.abilityCode

SDK高级版编码:

模板编辑器=TE002

图片编辑器=IE002

抠图编辑器=KE002

works_id

number

作品ID,使用回调方法asyn getUseRightCert(info)中的info.workId

uid

string

对接方用户体系的用户唯一标识,同「获取用户授权码」接口的uid

响应参数

字段

类型

字段描述

use_cert

string

权益使用凭证,仅可使用1次,有效期10分钟

响应示例

{
  "use_cert":"sadfsdfs"
}

请求示例


Java示例:

import com.alibaba.fastjson.JSONObject;
import com.gaoding.commons.util.JsonMapper;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.util.TreeMap;

public class HashHmacTest {
    public static String getHMAC(String data, String key) throws Exception {
        String HMAC_SHA1_ALGORITHM = "HmacSHA1";
        SecretKeySpec signinKey = new SecretKeySpec(key.getBytes(), HMAC_SHA1_ALGORITHM);
        Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
        mac.init(signinKey);
        byte[] rawHmac = mac.doFinal(data.getBytes());
        return new String(Base64.encodeBase64(rawHmac));
    }

    public static void main(String[] args) throws Exception {
        // TODO 使用真实AK
        String ak = "********************************";
        // TODO 使用真实SK
        String sk = "********************************";
        String httpMethod = "POST";
        String uri = "/api/use-cert/";
        String queryString = "";
        JSONObject jsonBody = new JSONObject();
        // TODO 使用真实接口入参
        jsonBody.put("ability_code", "******");
        jsonBody.put("app_id", "******");
        jsonBody.put("works_id", "******");
        jsonBody.put("uid", "******");
        long timestamp = System.currentTimeMillis() / 1000;
        String requestRaw = StringUtils.join(new String[]{httpMethod, "@", uri, "@", queryString, "@", Long.toString(timestamp), "@", jsonBody.toJSONString()}, "");
        String signature = getHMAC(requestRaw, sk);
        CloseableHttpClient client = HttpClientBuilder.create().build();
        HttpPost httpPost = new HttpPost("https://open-api.gaoding.com/api/use-cert");
        CloseableHttpResponse response = null;
        try {
            httpPost.addHeader("Content-Type", "application/json");
            httpPost.addHeader("X-Timestamp", Long.toString(timestamp));
            httpPost.addHeader("X-AccessKey", ak);
            httpPost.addHeader("X-Signature", signature);
            httpPost.setEntity(new StringEntity(jsonBody.toString()));
            response = client.execute(httpPost);
            HttpEntity responseEntity = response.getEntity();
            System.out.println("响应状态为:" + response.getStatusLine());
            if (responseEntity != null) {
                System.out.println("响应内容为:" + EntityUtils.toString(responseEntity));
            }
        } finally {
            try {
                // 释放资源
                if (client != null) {
                    client.close();
                }
                if (response != null) {
                    response.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}