Linksfield Developer
OverviewCube APIs旧版本API
OverviewCube APIs旧版本API
  1. CSSS APIs
  • CSSS APIs
    • 全局说明/Overview
    • 国际化/ Internationalization
    • 状态码/Status code
    • 签名代码示例 / Sign code Example
    • SIM
      • 批量获取拥有的设备信息/Get all SIM cards info
      • 查询单一设备实时信息/Get real-time info about one SIM card
      • 同步使用中SIM卡信息/Get the SIM Cards in use
    • Usage
      • 查询单张SIM卡流量使用情况/ Example Query the traffic usage of a single SIM card
      • 批量查询SIM卡流量接口 /Batch querying SIM card usage
      • 查询单日流量使用情况 / Example Query the daily usage
      • 批量查询指定月份的流量使用情况/ Batch querying the usage in a specified month
    • Plan
      • 同步资费套餐 / Get data plan
      • 订购流量套餐/ Order data plan
      • 批量订购套餐/ Bulk order package
      • 续订流量套餐/ Renew your data plan
      • 查询套餐订单信息 / Query the package order information
      • 开通/启用流量套餐订单 / To enable the order
      • 取消流量套餐订单/ Cancel an unenabled package order
      • 提前结束设备套餐订单/ End package orders early
      • [不推荐]停机/暂停流量套餐订单
      • [不推荐]复机/重新启动流量套餐订单
      • 【不推荐】分页批量(查询)同步设备可订购套餐
    • SMS
      • 发送短信/ send SMS
    • Customized
      • OTA日套餐下单/Order OTA Plan
      • 运营商侧剩余流量查询/Query the remaing data by MNO side
  • Notification
    • Notification全局说明
    • Notification状态码
    • 流量使用量API预警
      POST
    • 短信下行回调
      POST
    • 短信上行回调
      POST
    • 短信上行回调(区分文本二进制)
      POST
    • 订单状态变更回调(IMSI)
      POST
  • Mall APIs
    • Mall全局说明
    • Mall业务流程
    • Mall签名代码示例
    • APP调用Stripe的SDK示例说明
    • Vshop
      • 卡片登录验证
      • 获取可购套餐商品列表
      • 创建用户订单
      • 查询正在使用、未启用订单
      • 获取生效中的自动续费
      • 关闭自动续费
      • 用户下单(第三方支付)
    • Payment
      • 获取stripe单次支付权限
      • 获取Stripe订阅支付权限
      • 创建Stripe订阅/自动续费
      • 支付结果查询
    • Notification
      • 消息推送
  • eSIM QR Mall APIs
    • Introduction
    • Pre - order
      POST
    • webhook
      POST
    • 用户登录
      POST
    • My eSIM Detail
      POST
  1. CSSS APIs

签名代码示例 / Sign code Example

Java#

Map map = new TreeMap();
data = JSON.toJSONString(map);
/**
 * HmacSHA1签名
 *
 * @param data 请求报文 自然排序 json 序列化
 * @param secretKey 企业对应的secret
 * @return
 */

public static String generateSign(String data, String secretKey) {
    try {
        SecretKeySpec sk = new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(sk);
        byte[] res = mac.doFinal(data.getBytes("UTF-8"));
        Base64.Encoder encoder = Base64.getEncoder();
        return encoder.encodeToString(res);
    } catch (Exception e) {
        logger.error("sign fail", e);
        return "";
    }

}

Python#

import base64
import hmac
from hashlib import sha1
import json

def hash_hmac_sign(code, key, sha1):
    hmac_code = hmac.new(key.encode(), code.encode(), sha1).digest()
    return base64.b64encode(hmac_code).decode()

if __name__ == '__main__':
    strb = {
        "version": "2.0",
        "access_code": "P000270",
        "timestamp": "1643251754",
        "device_id": "89852022018041800193",
    }
    strb2 = str(strb)
    key_P000270 = "cfIAKh8O5ARL6HKAyUWUDYIZ64oZBJdW"
    '''
        data = json.dumps(strb, sort_keys=True, indent=4, separators=(',', ': ')) #indent=4 展示的样式
        sort_keys是告诉编码器按照字典key排序(a到z)输出
        indent参数根据数据格式缩进显示,读起来更加清晰, indent的值,代表缩进空格式
        separators参数的作用是去掉‘,’ ‘:’后面的空格,在传输数据的过程中,越精简越好,冗余的东西全部去掉。
        skipkeys参数,在encoding过程中,dict对象的key只可以是string对象,如果是其他类型,那么在编码过程中就会抛出ValueError的异常。skipkeys可以跳过那些非string对象当作key的处理.
        ensure_ascii=False (False输出中文、True输出ascii编码),json.dumps 序列化时对中文默认使用的ascii编码
    '''

    data = json.dumps(strb, sort_keys=True, separators=(',', ':'), ensure_ascii=False)
    print(data)
    print(hash_hmac_sign(data, key_P000270, sha1))
		

修改于 2022-10-10 03:07:31
上一页
状态码/Status code
下一页
批量获取拥有的设备信息/Get all SIM cards info
Built with