云之讯java短信验证码真小白教程

准备:eclipse,浏览器

第一步:打开云之讯官网,先注册,注册后,如下图(可以看到送了些钱):

加载中

第二步:认证个人开发者/企业开发(认证后可以创建应用),如下图:

加载中
认证之后

第三步:创建应用,如图:

QQ

第四步:开通短信验证功能,如图我开通了:

问问

第五步:创建模板,提交审核(短信-模板库),如图:

啊啊

第六步:审核通过后,下载sdk,下载后解压,eclipse导入,如图:

说说

第七步(最后一步,恭喜你,你即将成功完成测试,接收到短信):

双击打开sdk中RestTest.java,里面的代码如下:

/**
 * @author Tony

 * @date 2018-01-10
 * @project rest_demo
 */
package com;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import org.apache.commons.lang.StringUtils;

import com.ucpaas.restDemo.client.AbsRestClient;
import com.ucpaas.restDemo.client.JsonReqClient;

public class RestTest {

    static AbsRestClient InstantiationRestAPI() {
        return new JsonReqClient();
    }
    
    public static void testSendSms(String sid, String token, String appid, String templateid, String param, String mobile, String uid){
        try {
            String result=InstantiationRestAPI().sendSms(sid, token, appid, templateid, param, mobile, uid);
            System.out.println("Response content is: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void testSendSmsBatch(String sid, String token, String appid, String templateid, String param, String mobile, String uid){
        try {
            String result=InstantiationRestAPI().sendSmsBatch(sid, token, appid, templateid, param, mobile, uid);
            System.out.println("Response content is: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    public static void testAddSmsTemplate(String sid, String token, String appid, String type, String template_name, String autograph, String content){
        try {
            String result=InstantiationRestAPI().addSmsTemplate(sid, token, appid, type, template_name, autograph, content);
            System.out.println("Response content is: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
     
    
    public static void testGetSmsTemplate(String sid, String token, String appid, String templateid, String page_num, String page_size){
        try {
            String result=InstantiationRestAPI().getSmsTemplate(sid, token, appid, templateid, page_num, page_size);
            System.out.println("Response content is: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    public static void testEditSmsTemplate(String sid, String token, String appid, String templateid, String type, String template_name, String autograph, String content){
        try {
            String result=InstantiationRestAPI().editSmsTemplate(sid, token, appid, templateid, type, template_name, autograph, content);
            System.out.println("Response content is: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    public static void testDeleterSmsTemplate(String sid, String token, String appid, String templateid){
        try {
            String result=InstantiationRestAPI().deleterSmsTemplate(sid, token, appid, templateid);
            System.out.println("Response content is: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    
    
    /**
     * 测试说明  启动main方法后,请在控制台输入数字(数字对应 相应的调用方法),回车键结束
     * 参数名称含义,请参考rest api 文档
     * @throws IOException 
     * @method main
     */
    public static void main(String[] args) throws IOException{
        
        System.out.println("请输入方法对应的数字(例如1),Enter键结束:");
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        
        String methodNumber = br.readLine();
        
        if (StringUtils.isBlank(methodNumber)){
            System.out.println("请输入正确的数字,不可为空");
            return;
        }
        
        if (methodNumber.equals("1")) {  //指定模板单发
            String sid = "";
            String token = "";
            String appid = "";
            String templateid = "";
            String param = "";
            String mobile = "";
            String uid = "";
            testSendSms(sid, token, appid, templateid, param, mobile, uid);
        } else if (methodNumber.equals("2")) { //指定模板群发
            String sid = "";
            String token = "";
            String appid = "";
            String templateid = "";
            String param = "";
            String mobile = "";
            String uid = "";
            testSendSmsBatch(sid, token, appid, templateid, param, mobile, uid);
        } else if (methodNumber.equals("3")) {  //增加模板
            String sid = "";
            String token = "";
            String appid = "";
            String type = "";
            String template_name = "";
            String autograph = "";
            String content = "";
            testAddSmsTemplate(sid, token, appid, type, template_name, autograph, content);
        } else if (methodNumber.equals("4")) {  //查询模板
            String sid = "";
            String token = "";
            String appid = "";
            String templateid = "";
            String page_num = "";
            String page_size = "";
            testGetSmsTemplate(sid, token, appid, templateid, page_num, page_size);
        } else if (methodNumber.equals("5")) {  //编辑模板
            String sid = "";
            String token = "";
            String appid = "";
            String templateid = "";
            String type = "";
            String template_name = "";
            String autograph = "";
            String content = "";
            testEditSmsTemplate(sid, token, appid, templateid, type, template_name, autograph, content);
        } else if (methodNumber.equals("6")) {  //删除模板
            String sid = "";
            String token = "";
            String appid = "";
            String templateid = "";
            testDeleterSmsTemplate(sid, token, appid, templateid);
        }     
    }
}
其中,在下面这些代码(选自RestTest.java)编辑参数,后提交运行,记得开网络:

     if (methodNumber.equals("1")) {  //指定模板单发
            String sid = "";//这个参数可以在 -短信 中找到(后面附图片)
            String token = "";//这个参数可以在 -短信 中找到(后面附图片)
            String appid = "";//这个参数可以在 -短信 中找到(后面附图片)
            String templateid = "";//模板名称,就是刚刚通过审核的模板名称
            String param = "";//特别提醒,这里什么鬼?这里填(看下面附图)
            String mobile = "";//手机号码
            String uid = "";//测试,不用填
            testSendSms(sid, token, appid, templateid, param, mobile, uid);
        } else if (methodNumber.equals("2")) { //指定模板群发

111

说说

  • 1
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
在uniapp中实现手机验证码,可以使用以下代码段作为参考:([3-9])[0-9]{9}$/); if (!checkPhone.test(this.loginForm.phoneNum)) { this.$refs.loginToast.show({ message: '请输入正确的手机号', type: 'warning', position:'top' }); return } if(this.oneMin<60 && this.oneMin>0){ uni.showToast({ title:`请${this.oneMin}s后重新获取`, icon:'none' }) return } let data = { password: '', phone: this.loginForm.phoneNum, userName: '' } let clock = setInterval(() => { this.oneMin-- this.codeTips = this.oneMin if(this.oneMin<1){ clearInterval(clock) this.oneMin = "获取验证码" } }, 1000) loginReq.sendSms(data).then(res => { console.log("获取到的验证码", res) }).catch(err => { this.oneMin = "重新发送" uni.showToast({ title: '发送验证码失败', icon: 'none' }) }) } ``` 在这段代码中,`getCode`函数用于获取手机验证码。首先,它会检查输入的手机号是否为空,如果为空,会显示一个警告提示。接下来,使用正则表达式来验证手机号的格式是否正确,如果不正确,同样会显示一个警告提示。然后,检查倒计时的时间,如果倒计时还未结束,会显示一个提示,要求用户在倒计时结束后再重新获取验证码。接着,创建一个包含手机号的数据对象,并使用定时器来控制倒计时的时间。在定时器的回调函数中,倒计时时间递减,并更新倒计时提示。当倒计时时间为0时,清除定时器,并将倒计时提示重置为"获取验证码"。最后,调用一个发送验证码的请求,并根据请求的结果进行相应的处理。 请注意,以上代码只是一个示例,具体实现可能会根据项目的需求和架构有所不同。<span class="em">1</span> #### 引用[.reference_title] - *1* [uni-app实现验证码登录-云之讯](https://blog.csdn.net/Stitch_xiao/article/details/125780267)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值