短信服务接口安全是在开发或对接短信接口时尤为关注的问题。部分***可能出于恶意竞争或短信轰炸他人的目的,***短信服务接口,盗刷验证短信,造成资金损失。那么应该如何避免短信接口被恶意调用?本文为大家介绍短信防火墙的使用方法。#短信防火墙#
➤ 如何使用风控防火墙
第一步:获取防火墙帐号密钥
进入 防火墙控制台,在左侧导航栏选择【网站管理】,进入网站管理页面,单击【发到邮箱】接收密钥。
第二步:下载防火墙服务器
前往防火墙官网,在顶部导航栏选择【解决方案】>【下载中心】,进入下载中心页面,找到短信防火墙服务器安装包,点击【下载链接】即可下载。
第三步:业务系统前后端接入
web 前端接入:
Java 在页面合适的位置(标签内)加入以下代码引入JS文件:
<script type="text/javascript" src="/NxtJsServlet"></script>
PHP 在页面合适的位置(标签内)加入以下代码引入JS文件:
<script id="finger" type="text/javascript" src="/nxt_inc/nxt_front.php"></script>
后端接入:
Java
修改配置(和业务系统同系统不需要修改):
newxt.ini (存放位置:"\src\resource")
修改参数(fireWareUrl)-->http://localhost:7502 (本地服务路径)
(isNginx)-->true(有无反向代理)
- 短信下发
public RetMsg smsSend(HttpServletRequest request, HttpServletResponse response, String clientMobile) {
RetMsg retMsg = new RetMsg(-1, "系统异常");
FwClient fwClient = new FwClientImpl();
try {
// 1 调用【短信防火墙】短信发送请求
HashMap < String, Object > paramMap = fwClient.getSendReq(request, clientMobile);
String jsonReq = fwClient.execReq(paramMap);
String smsSendRet = fwClient.getRetVaule(jsonReq, "riskResult");
if("REJECT".equals(smsSendRet)) {
retMsg.setRet(3);
retMsg.setMsg("请求过于频繁");
}
else {
// 业务 TODO
// 业务调用短信接口 TODO
// 调用短信接口 结束
if(smsRetMsg != null && smsRetMsg.getRet() == 0) {
// 2 调用【短信防火墙】成功结果
fwClient.execSucc(paramMap);
logger.debug("send succ");
retMsg.setRet(0);
retMsg.setMsg("发送验证码成功");
}
else {
// 2 调用【短信防火墙】失败结果
SmsVerifyCache.getInstance().remove(clientMobile);
fwClient.execFail(paramMap);
retMsg.setRet(-1);
retMsg.setMsg("发送验证码失败");
}
}
}
catch(Exception e) {
for(StackTraceElement elment: e.getStackTrace()) {
logger.error(elment.toString());
}
}
return retMsg;
}
- 短信验证
public RetMsg smsVerify(HttpServletRequest request, HttpServletResponse response, String clientMobile, String smsVerifyCode) {
FwClient fwClient = new FwClientImpl();
RetMsg retMsg = new RetMsg(-1, "系统异常");
if(smsVerifyCode == null || smsVerifyCode.isEmpty()) {
retMsg.setRet(1);
retMsg.setMsg("输入验证码为空");
}
else {
// 1 调用【短信防火墙】验证请求
HashMap < String, Object > paramMap = fwClient.getVerifyReq(request, clientMobile); // 请求防火墙
String jsonReq = fwClient.execReq(paramMap);
// 报文处理
String smsSendRet = fwClient.getRetVaule(jsonReq, "riskResult");
if("REJECT".equals(smsSendRet)) {
retMsg.setRet(3);
retMsg.setMsg("请求过于频繁");
}
// 业务 TODO
if(cacheSmsVerify != null && cacheSmsVerify.getVerifyCode() != null && !cacheSmsVerify.getVerifyCode().isEmpty()) {
if(cacheSmsVerify.getVerifyCode().equals(smsVerifyCode)) {
retMsg.setRet(0);
retMsg.setMsg("验证成功");
}
else {
retMsg.setRet(1);
retMsg.setMsg("验证码错误");
}
}
else {
retMsg.setRet(-9);
retMsg.setMsg("验证码超时");
}
if(retMsg.getRet() == 0) {
// 2 调用【短信防火墙】成功结果
fwClient.execSucc(paramMap);
}
else {
// 2 调用【短信防火墙】失败结果
fwClient.execFail(paramMap);
}
}
return retMsg;
}
PHP
修改配置文件(和业务系统同系统不需要修改):
nxt_ini.php (存放位置:"\nxt_inc") 修改参数(\$GLOBALS
["fireWareUrl"])-->$GLOBALS["fireWareUrl"]="http://localhost:7502"
- 短信下发
require_once $_SERVER['DOCUMENT_ROOT'].
"/nxt_inc/nxt_client.php";
/**
* 发送短信
* @param $mobile
*/
public
function send(string $mobile) {
$fwClient = new ClientApi();
// 获取下发短信报文
$paramMap = $fwClient - > getSendReq($phone);
// 执行下发短信请求
$jsonReq = $fwClient - > execReq($paramMap);
$fwRet = $fwClient - > getRetVaule($jsonReq, "riskResult");
if("REJECT" != $fwRet) {
// 发送短信业务 TODO
if(发送成功标记) {
// 下发短信成功
$fwClient - > execSucc($paramMap);
}
else {
// 下发短信失败
$fwClient - > execFail($paramMap);
}
}
}
- 短信验证
/**
* 短信验证
* @param $mobile
*/
public
function smsVerify(string $mobile) {
$fwClient = new ClientApi();
// 获取短信验证报文
$paramMap = $fwClient - > getVerifyReq($phone);
// 执行短信验证请求
$jsonReq = $fwClient - > execReq($paramMap);
$fwRet = $fwClient - > getRetVaule($jsonReq, "riskResult");
if("REJECT" != $fwRet) {
// 验证短信业务 TODO
if(验证成功标记) {
// 验证短信成功
$fwClient - > execSucc($paramMap);
}
else {
// 验证短信失败
$fwClient - > execFail($paramMap);
}
}
}
第四步:实时监控
防御拦截数据尽收眼底,实时查看当日数据详情与近期风险趋势。 通过风控数据看板,可查看1-30天的验证情况、风控拦截情况以及验证事件触发的AI模型情况。
进入防火墙控制台,在左侧导航栏选择【风险大盘】,进入风险大盘页面。
以上就是使用短信防火墙的全部过程,如需了解更多请关注防火墙官网:www.newxtc.com