本文为您介绍号码隐私保护Python SDK的使用方法及示例。

前提条件

  • 已经注册阿里云账号并生成访问密钥(AccessKey)。详细步骤请参见获取AccessKey
  • 您需要开通号码隐私保护并完成购买号码等操作。具体流程,请参见入门概览
  • 安装Python环境。Alibaba Cloud SDK for Python要求使用Python 2.7 或 3.x。

安装Python SDK核心库

  • 使用依赖包工具安装(推荐):具体安装使用的依赖包,请参见Python
  • 自行下载安装

    您可以使用git clone或其它手段下载aliyun-python-sdk-core并自行添加解决方案。下载安装包,请参见SDK 核心库

添加AXB号码的绑定关系

  • 代码示例
    #!/usr/bin/env python
    #coding=utf-8
    
    from aliyunsdkcore.client import AcsClient
    from aliyunsdkcore.acs_exception.exceptions import ClientException
    from aliyunsdkcore.acs_exception.exceptions import ServerException
    from aliyunsdkcore.auth.credentials import AccessKeyCredential
    from aliyunsdkcore.auth.credentials import StsTokenCredential
    from aliyunsdkdyplsapi.request.v20170525.BindAxbRequest import BindAxbRequest
    
    credentials = AccessKeyCredential('<your-access-key-id>', '<your-access-key-secret>')
    # use STS Token
    # credentials = StsTokenCredential('<your-access-key-id>', '<your-access-key-secret>', '<your-sts-token>')
    client = AcsClient(region_id='cn-shanghai', credential=credentials)
    
    request = BindAxbRequest()
    request.set_accept_format('json')
    
    request.set_PoolKey("FC5526*****")
    request.set_PhoneNoA("150****0000")
    request.set_PhoneNoB("150****0000")
    request.set_PhoneNoX("150****0000")
    request.set_Expiration("2021-09-05 12:00:00")
    request.set_ExpectCity("北京")
    request.set_IsRecordingEnabled(True)
    request.set_OutId("abcdef")
    request.set_OutOrderId("34553330****")
    request.set_CallRestrict("CONTROL_AX_DISABLE")
    request.set_CallDisplayType(1)
    request.set_RingConfig("{\"AXBRing_B\":\"100000001\",\"AXBRing_A\":\"100000001\"}")
    request.set_ASRModelId("7ee372834d2f4cc7ac0d0ab****")
    request.set_CallTimeout(10)
    
    response = client.do_action_with_exception(request)
    # python2:  print(response) 
    print(str(response, encoding='utf-8'))
  • 结果示例
    {
      "SecretBindDTO" : {
        "Extension" : "130",
        "SecretNo" : "170****0000",
        "SubsId" : "10000007683*****"
      },
      "Message" : "OK",
      "RequestId" : "9297B722-A016-43FB-B51A-E54050D9369D",
      "Code" : "OK"
    }

相关文档

  • 如果您想了解更多示例,请参见OpenAPI开发者门户
    说明 登录开发者门户平台,SDK版本选择时,请选择原版 SDK
  • 号码隐私保护相关API,请参见API概览