手机注册(发送短信验证码)
去蚂蚁开通短信服务,用accesskey号制作签名
复制代码&; 粘贴即可使用,按照指导修改即可
如果有误报而无法使用,请谅解。 (未经作者同意,禁止修改或盗用代码;利用代码骗取金钱)免费参考)
联系QQ:913237269,添加时请说明
如果有问题或有用的地方请在评论区域评论
注册手机邮件发送控制层(controller )
package com.ljma.web.mng.phone registration.controller;
import com.aliyuncs.dysmsapi.model.v 2017 05 25.send SMS response;
import com.aliyuncs.exceptions.client exception;
import com.ljma.web.util.code util;
import com.ljma.web.util.SMS tool;
importorg.spring framework.web.bind.annotation.request mapping;
importorg.spring framework.web.bind.annotation.response body;
importorg.spring framework.web.bind.annotation.rest controller;
import javax.servlet.http.http servlet request;
import java.util.HashMap;
import java.util.Map;
//*
* @description:手机短信验证
* @author rxdyj
* @date 2019/7/11
/
@RestController
@requestmapping(value=“/phone”) ) ) ) )。
publicclassphoneregistrationcontroller {
/*
*发送邮件
* @param phone
* @param request
* @return
* @throws ClientException
*/
@requestmapping(value=“/smsxxs”) ) ) ) ) )。
@ResponseBody
public MapString,objectsmsxxs(stringphone,HttpServletRequest request ) throws ClientException {
MapString,Object map=new HashMap (;
//认证码(指定长度的随机数) )。
string code=code util.generate verify code (6;
stringtemplateparam=" {“code”: " ' code ' };
//SMS模板id
stringtemplatecode=“SMS _ 129650038”//无法使用的情况下(模板转换为属于自己的模板。 )
sendsmsresponseresponse=SMS tool.send SMS (phone,TemplateParam,TemplateCode );
map.put(「verifycode ",code );
map.put(「Phone”、phone );
request.getSession ().set attribute (" code phone ",map );
response.getcode ().equals (“确定”) ) 0
map.put(「isOK "、" ok " );
}
返回地图;
}
}
工具类(util ) )。
package com.ljma.web.util;
import java.util.Random;
//*
* @description:手机号码注册认证邮件
* @author rxdyj
* @date 2019/7/11
*/
公共类代码实用工具{
甚至使用了Algerian字体,如果系统中没有,就需要安装字体。 字体只显示大写字母,去掉了1,0,I,o几个容易混淆的文字
publicstaticfinalstringverify _ codes=" 1234567890 "
/** *使用系统默认字符源生成认证码* @param verifySize认证码长度* @ return */publicstaticstringenerateverifycode (intverifys
ize){ return generateVerifyCode(verifySize, VERIFY_CODES);}/** * 使用指定源生成验证码 * @param verifySize 验证码长度 * @param sources 验证码字符源 * @return */public static String generateVerifyCode(int verifySize, String sources){ if(sources == null || sources.length() == 0){ sources = VERIFY_CODES; } int codesLen = sources.length(); Random rand = new Random(System.currentTimeMillis()); StringBuilder verifyCode = new StringBuilder(verifySize); for(int i = 0; i < verifySize; i++){ verifyCode.append(sources.charAt(rand.nextInt(codesLen-1))); } return verifyCode.toString();}public static void main(String[] args) { System.out.println(generateVerifyCode(4));}}
工具类(新建一个文件名在util下面)
package com.ljma.web.util;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
/**
* @description: 手机号注册短信验证
* @author rxdyj
* @date 2019/7/11
*/
public class SmsTool {
}