阿里云号码隐私保护

号码隐私保护(Phone Number Protection)是一款基于基础运营商通信网络能力的互联网产品,可以帮忙使用本产品的企业保护其客户电话号码不泄露、通过对虚拟号码服务过程进行录音来管理客户电话服务质量,同时该产品适用于出行、物流、外卖、招聘等多种业务场景,API接口简单易用,可以快速实现平台客户保护用户隐私的需求。

本文采用的产品类型为 阿里云AXB中间号,有更多定制需求请移步官方文档查看详细介绍。
官方文档地址: https://help.aliyun.com/document_detail/59773.html

1、引入pom依赖

        <!--阿里云sdk-->
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-core</artifactId>
            <version>4.5.16</version>
        </dependency>
        <dependency>
            <groupId>com.aliyun</groupId>
            <artifactId>aliyun-java-sdk-dyplsapi</artifactId>
            <version>1.3.0</version>
        </dependency>

2、配置参数

aliyun:
    # phone protect
    dypls:
        accessKeyId: LTAxxxxxAA4
        accessKeySecret: 5EbUxxxxxVCv2Ia
        poolKey: FC1xxxxxxx59     #号码池ID

3、注入参数

    @Value("${aliyun.dypls.accessKeyId}")
    private String accessKeyId;
    @Value("${aliyun.dypls.accessKeySecret}")
    private String accessKeySecret;
    @Value("${aliyun.dypls.poolKey}")
    private String poolKey;

4、调用

        String phoneX;
        String phoneA;//要绑定的号码A
        String phoneB;//要绑定的号码B

        DefaultProfile profile = DefaultProfile.getProfile("cn-qingdao", accessKeyId, accessKeySecret);
        IAcsClient client = new DefaultAcsClient(profile);
        BindAxbRequest request = new BindAxbRequest();
        request.setPoolKey(poolKey);
        request.setPhoneNoA(phoneA);
        request.setPhoneNoB(phoneB);
        int timerange = 2 * 60;  //绑定2分钟
        String endTime = getTargetTime(timerange);
        request.setExpiration(endTime);
        System.out.println(JSONUtil.objectToJson(request));
        BindAxbResponse response;
        try {
            response = client.getAcsResponse(request);
        } catch (ServerException e) {
            e.printStackTrace();
            log.error("发生ServerException错误:errorCode:{},errorMsg:{},requestId:{}", e.getErrCode(), e.getErrMsg(), e.getRequestId());
            throw new BusinessException(BusinessStatus.FAIL);
        } catch (ClientException e) {
            log.error("发生ClientException错误:errorCode:{},errorMsg:{},requestId:{}", e.getErrCode(), e.getErrMsg(), e.getRequestId());
            throw new BusinessException(BusinessStatus.FAIL, e.getErrMsg());
        }
        phoneX = response.getSecretBindDTO().getSecretNo();

5、为了充分利用号码资源,建议将绑定的号码资源缓存起来,短期内重复获取直接从缓存返回,过期后再重新绑定。

6、表结构

CREATE TABLE `binding` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `phoneA` varchar(15) DEFAULT NULL COMMENT '手机号A',
  `phoneX` varchar(15) DEFAULT NULL COMMENT '中间隐私号X',
  `phoneB` varchar(15) DEFAULT NULL COMMENT '手机号B',
  `time` datetime DEFAULT NULL COMMENT '过期时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='手机号绑定关系';

7、表操作

@Repository
public interface BindingDao {

    @Select("select phoneX from binding " +
            "where ((phoneA=#{phoneA} and phoneB=#{phoneB}) or " +
            "(phoneA=#{phoneB} and phoneB=#{phoneA}) ) " +
            "and time>now() order by id desc limit 1")
    String checkBindingX(String phoneA, String phoneB);

    @Insert("insert into binding(phoneA,phoneX,phoneB,time) values (#{phoneA},#{phoneX},#{phoneB},#{endtime})")
    void insert(String phoneA, String phoneX, String phoneB, Date endtime);

    @Delete("delete from binding where time<now()")
    void deleteUnbind();
}
posted @ 2021-02-25 18:29  shih945  阅读(203)  评论(0编辑  收藏  举报