Skip to main content

python sdk of taiqiyun

Project description

钛旗云 SDK 使用说明

python版

安装 SDK

通过 pip 一键完成安装

pip install tisdk -U
使用 SDK 调试接口

安装完成后, 可直接在命令行使用 tireq 命令调试接口

tireq username secret_key method url [foo:bar,foo2:bar2...]

tireq 命令的参数依次是:

  1. 用户名 (由钛旗云系统分配)
  2. 密钥 (由钛旗云系统分配)
  3. 请求方法名 (get post put ...)
  4. 请求 url
  5. 请求体参数 (参数名和参数值以 : 相隔, 多对参数之间以 , 相隔) 非必须

参考示例如下

tireq myusername 4fbe6e7084ec4d05 post /api/xxx/v1 name1:value1
在代码中调用 SDK 发起请求

参考 Python 代码如下

import tisdk

username = 'myusername'
secret_key = '4fbe6e7084ec4d05'
method = 'post'
url = '/api/xxx/v1'
data = {'name1': 'value1'}

# 直接调用 ti_request 方法发起请求
# 每次发起请求时都传入`用户名`和`密钥`
tisdk.ti_request(username, secret_key, method, url, data)

# 以`用户名`和`密钥`初始化 Ti 对象
# 之后调用 Ti.request 方法发起请求, 不需每次传`用户名`和`密钥`
ti = tisdk.Ti(username, secret_key)
ti.request(method, url, data)

java版

说明

通过我司提供的jar包工具类,可直接生成请求需要的签名和数据的加密或者直接发起请求

jar包依赖第三方库fastjson(1.2以上)和httpclient(4.5以上)

<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.5.9</version>
</dependency>
<dependency>
  <groupId>com.alibaba</groupId>
  <artifactId>fastjson</artifactId>
  <version>1.2.58</version>
</dependency>
jar包工具类说明
  • AesUtils: Aes加解密工具类
  • HmacSha256: Hmac256生成工具类
  • RequestUtil: api请求工具类
  • Ti: 钛旗云 sdk工具类
在代码中调用 SDK 发起请求

参考 java代码如下

import com.alibaba.fastjson.JSON;
import com.kq300061.tisdk.AesUtils;
import com.kq300061.tisdk.Ti;

import java.util.HashMap;
import java.util.Map;

public class ReqTest {
    public static void main(String[] args) {
        try {
            String username = "username";
            String secret = "secret";
            String url = "https://XX//api/xxx/v1";
            HashMap<String, Object> reqbody = new HashMap<String, Object>() {{
                put("name", "abc");
                put("phone", "cdf");
                put("idCard", "123");
            }};

//            https
            String resp = new Ti(username, secret).doHttpsPost(url, reqbody);
//            或者使用以下这种方式
//            Ti TiRequest = new Ti(username, secret);
//            String resp = TiRequest.doHttpPost(url, reqbody);
//            String resp = TiRequest.doHttpsPost(url, reqbody);

            Map respMap = JSON.parseObject(resp);
            boolean contains = respMap.containsKey("data");    //判断是否包含data
            if (contains) {         //如果有data字段
                AesUtils aesUtils = new AesUtils(secret);

//            获取aes解码后的data数据
                String dedata = aesUtils.decrypt(respMap.get("data").toString());
                System.out.println("解码后的data数据: " + dedata);
            } else {//如果没有有data字段,获取错误信息message
                System.out.println(resp);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tisdk-0.0.20.tar.gz (4.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page