阿里云号码隐私保护
号码隐私保护(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();
}
作者:shih945
出处:https://www.cnblogs.com/shih945/p/14448555.html
版权:本作品采用「署名-非商业性使用-相同方式共享 4.0 国际」许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)