阿里雲號碼隱私保護


號碼隱私保護(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();
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM