阅读背景:

服务端短信验证

来源:互联网 

接口部分

 /**
     * 发送验证码
     * @param request
     * @param response
     * @param loginName  手机号
     * @param type   类型
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "sendmessage")
    public JsonResult sendmessage(HttpServletRequest request, HttpServletResponse response, String loginName,String type) throws Exception {
        //手机号存在则直接返回
        SingleInstance singleInstance = SingleInstance.getInstance();
        User userExist = this.userService.loginByloginName(loginName);
        //检查是否已经注册过了
        if(userExist!=null&&type.equals("register")){
            throw new MyException(ResultCode.ERROR_USER_ADDFALIE);
        }
            int one = (int) Math.floor(Math.random()*10);
            int two = (int) Math.floor(Math.random()*10);
            int three = (int) Math.floor(Math.random()*10);
            int four = (int) Math.floor(Math.random()*10);
            //随机生成的4位安全码
            String securityCode = one+""+two+""+three+""+four;
            //手机号+类型做为key
            String key = loginName+"_"+type;
            //短信发送验证码
            singleInstance.concurrentHashMap.put(key,securityCode);
            JavaSmsApi.tplSendSms(JavaSmsApi.apikey,JavaSmsApi.tpl_id,securityCode,loginName);

        return new JsonResult(ResultCode.SUCCESS);
    } /**
     * 发送验证码
     * @param reque



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: