在自己写项目时,会用到短信验证功能,这时候我们就需要用到山东鼎信验证码功能
第一步:按照顺序找到山东鼎信,短信验证码功能
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; }