栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

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

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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

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

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

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 headers = new HashMap();
//最后在header中的格式(中间是英文空格)为Authorization:APPCODE 83359fd73fe94948385f570e3c139105
headers.put("Authorization", "APPCODE " + appcode);
Map querys = new HashMap();
//随机生成四位验证码,需要工具,看自己需求可以不加
String fourBitRandom = RandomUtil.getFourBitRandom();
querys.put("mobile", mobile);
querys.put("param", "code:"+fourBitRandom);
querys.put("tpl_id", "TP1711063");
Map bodys = new HashMap();

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;
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/886005.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号