怎么使用山东鼎信发送短信验证码

在自己写项目时,会用到短信验证功能,这时候我们就需要用到山东鼎信验证码功能

第一步:按照顺序找到山东鼎信,短信验证码功能

2.点击进去往下划,找到这个界面

3.AppCode :需要购买短信服务,新人第一次注册有免费5条,买完之后找到图片就可以找到了

 

4.根据上面的API生成自己的方法,

 重要提示如下: * HttpUtils请从 * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/src/main/java/com/aliyun/api/gateway/demo/util/HttpUtils.java * 下载 * *

相应的依赖请参照 * https://github.com/aliyun/api-gateway-demo-sign-java/blob/master/pom.xml */

String host = "http://dingxin.market.alicloudapi.com";
String path = "/dx/sendSms";
String method = "你的方法"; 
String appcode = "你的APPCode";
Map<String, String> headers = new HashMap<String, String>();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
Map<String, String> querys = new HashMap<String, String>();
//随机生成四位验证码,需要工具,看自己需求可以不加
String fourBitRandom = RandomUtil.getFourBitRandom();
querys.put("mobile", mobile);
querys.put("param", "code:"+fourBitRandom);
querys.put("tpl_id", "TP1711063");
Map<String, String> bodys = new HashMap<String, String>();

try {

    HttpResponse response = HttpUtils.doPost(host, path, method, headers, querys, bodys);
    redisTemplate.opsForValue().set(mobile,fourBitRandom,30, TimeUnit.DAYS);
        return  true;
} catch (Exception e) {
    return  false;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值