编程语言
首页 > 编程语言> > java中腾域联信通短信验证码demo

java中腾域联信通短信验证码demo

作者:互联网

需求:动态获取手机验证码。使用的第三方工具腾域联信通。文档说明如下
在这里插入图片描述

根据提供的文档,直接发送http请求即可,直接贴后台代码如下:

 @RequestMapping(value="/getCode",method = RequestMethod.GET)
        @ApiOperation("获取验证码(腾域联信通)")
        public  String idifyCode(@RequestParam("phone") String phone) throws IOException {
        log.info("获取手机验证码方法:{-------}"+phone);
            int code = (int) ((Math.random() * 9 + 1) * 100000);//随机生成6位数
            String encode = URLEncoder.encode("【英语竞赛】手机验证码为"+code+",如非本人操作,请忽略该短信。", "utf-8");
            String url=http://139.196.234.129:8888/sms.aspx(固定路径)+"&userid="+申请的用户id+"&account="+用户的账号+"&password="+用户密码+"&mobile="+获取验证码的手机号+"&content="+encode+"&sendTime=&extno=";
             HttpClient httpClient = new HttpClient();
            httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(15000);//设置httpclient连接主机服务器超时时间15秒
            PostMethod postMethod = new PostMethod(url);
            postMethod.getParams().setParameter(HttpMethodParams.SO_TIMEOUT,60000);//设置post请求超时时间
            postMethod.addRequestHeader("Content-Type","application/json");
            httpClient.executeMethod(postMethod);
            String result = postMethod.getResponseBodyAsString();
            postMethod.releaseConnection();
            return result;
        }

使用效果如下:
在这里插入图片描述

标签:String,demo,postMethod,验证码,中腾域,encode,httpClient,联信
来源: https://blog.csdn.net/weixin_44024814/article/details/100987303