1、官方地址

号码隐私服务

2、代码

引入依赖

    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>dyplsapi20170525</artifactId>
        <version>2.0.5</version>
    </dependency>
    @Value("${aliyun.pnp.AccessKeyID}")
    private String accessKeyId;
    @Value("${aliyun.pnp.AccessKeySecret}")
    private String accessKeySecret;
    @Value("${aliyun.pnp.PoolKey}")
    private String poolKey;

    @Autowired
    private PhoneNumberProtectionService phoneNumberProtectionService;

    @ApiOperation("绑定")
    @PostMapping("/axb")
    public void setPhoneNumberProtectionService(String phoneA, String phoneB, LocalDateTime localDateTime) throws Exception {
        // 请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID 和 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
        // 工程代码泄露可能会导致 AccessKey 泄露,并威胁账号下所有资源的安全性。以下代码示例使用环境变量获取 AccessKey 的方式进行调用,仅供参考,建议使用更安全的 STS 方式,更多鉴权访问方式请参见:https://help.aliyun.com/document_detail/378657.html
        com.aliyun.dyplsapi20170525.Client client = phoneNumberProtectionService.createClient(accessKeyId, accessKeySecret);
        com.aliyun.dyplsapi20170525.models.BindAxbRequest bindAxbRequest = new com.aliyun.dyplsapi20170525.models.BindAxbRequest()
                .setPoolKey(poolKey)
                .setPhoneNoA(phoneA)
                .setPhoneNoB(phoneB)
                .setExpiration(localDateTime);
        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
        try {
            // 复制代码运行请自行打印 API 的返回值
            BindAxbResponse bindAxbResponse = client.bindAxbWithOptions(bindAxbRequest, runtime);
            System.out.println(bindAxbResponse);
        } catch (TeaException error) {
            // 如有需要,请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // 如有需要,请打印 error
            com.aliyun.teautil.Common.assertAsString(error.message);
        }
    }
    @Value("${aliyun.pnp.AccessKeyID}")
    private String accessKeyId;
    @Value("${aliyun.pnp.AccessKeySecret}")
    private String accessKeySecret;

    /**
     * 使用AK&SK初始化账号Client
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    @Override
    public com.aliyun.dyplsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填,您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 必填,您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // Endpoint 请参考 https://api.aliyun.com/product/Dyplsapi
        config.endpoint = "dyplsapi.aliyuncs.com";
        return new com.aliyun.dyplsapi20170525.Client(config);
    }
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐