CDN加速

文档中心 API文档 AI服务 游戏分类打标

游戏分类打标

更新时间:2019-12-12 17:31:53
适用产品:定制化接口

接口描述

识别图片中的游戏类型

请求参数

参数名称类型必填描述
file图片用户传上来的预测图片

返回参数

参数名称类型描述
codestring返回调用结果的状态
messagestring调用接口,返回状态码的说明
datastring返回游戏分类模型的预测结果

错误码

错误代码(code)描述(message)HTTP状态码语义
30052002post字段没有图片内容200

示例

示例说明
请求示例
复制
#!/usr/bin/env python
# -- coding: utf-8 --


import requests
import sys
import os
import json
import base64
import time
from hashlib import sha256

url = 'http://open.chinanetcenter.com/image/v1/game/tag'
username = 'xxx'
apikey = 'xxx'
__curPath__ = os.path.split(os.path.realpath(__file__))[0]

def getDate():
    import datetime
    GMT_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
    date_gmt = datetime.datetime.utcnow().strftime(GMT_FORMAT)
    print("getDate: " + date_gmt)
    return date_gmt

def sha(date):
    import hmac
    print("sha: " + date)
    signed_apikey = hmac.new(apikey.encode(
        'utf-8'), date.encode('utf-8'), sha256).digest()
    signed_apikey = base64.b64encode(signed_apikey)
    print("sha: " + signed_apikey.decode())
    return signed_apikey


def encode(auth):
    print("encode: " + auth.decode())
    msg = username + ":" + auth.decode()
    result = base64.b64encode(msg.encode('utf-8'))
    print("encode: " + result.decode())
    return result


def getAuth():
    return encode(sha(getDate()))

def getABase64StrFromFile(fname):
    with open(fname, 'rb') as f:
        c = f.read()
        c = base64.b64encode(c)
        return str(c, encoding='utf-8') 

def connect(fname):
    auth = getAuth()
    auth = 'Basic ' + auth.decode()
    d = {'file': getABase64StrFromFile(
        __curPath__ + r'/live-duan234--20190315171806.bmp')}
    headers = {'Content-Type': 'application/json', 'Accept': "application/json",
               "Date": getDate(), 'Authorization': auth}
    r = requests.post(url, headers=headers, data=json.dumps(d))
    ret = r.text
    print(ret)

if __name__ == '__main__':
    connect('./img/582954.png')
返回示例
复制
{"code": "0", "message": "Success", "data": "DNF"}