python实现乐固加固API 请求例子

安装SDK教程地址
https://gitee.com/tencentcloud/tencentcloud-sdk-python

这里实现了Android加固包请求与查询的方法

from tencentcloud.common import credential
from tencentcloud.common.exception.tencent_cloud_sdk_exception import TencentCloudSDKException
from tencentcloud.ms.v20180408 import models,ms_client
from tencentcloud.ms.v20180408.models import AndroidAppInfo,ServiceInfo


def reqJiaGu(client:ms_client.MsClient,md5,url):
    #请求加固
    req = models.CreateShieldInstanceRequest()
    info = AndroidAppInfo()
    serviceInfo = ServiceInfo()
    serviceInfo.CallbackUrl = ""
    serviceInfo.PlanId = 0

    info.AppMd5 = md5
    info.AppUrl = url
    req.AppInfo = info
    req.ServiceInfo = serviceInfo
    resp = client.CreateShieldInstance(req)
    #返回ItemId 用于查询加固结果 e3822edc39946179f743342465fc1ad2
    ItemId = resp.ItemId 
    print(resp.to_json_string())

def queryJiagu(client:ms_client.MsClient,ItemId):
    req = models.DescribeShieldResultRequest()
    req.ItemId = ItemId
    resp = client.DescribeShieldResult(req)
    #返回ItemId 用于查询加固结果 e3822edc39946179f743342465fc1ad2
    print(resp.to_json_string())

try:
    # 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中,请参考本文凭证管理章节。
    # 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。
    cred = credential.Credential("", "")
    # cred = credential.Credential(
    #     os.environ.get("TENCENTCLOUD_SECRET_ID"),
    #     os.environ.get("TENCENTCLOUD_SECRET_KEY"))
    client  = ms_client.MsClient(cred,"ap-shanghai")
    #reqJiaGu(client,"e6eddd68750a7961ce773e13f720287b","")
    queryJiagu(client,"e3822edc39946179f743342465fc1ad2")

except TencentCloudSDKException as err:
    print(err)

通俗易懂

你可能感兴趣的:(python,Android开发,python,开发语言)