起步软件技术论坛
搜索
 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 6194|回复: 1

发送手机短信获取验证码功能第三步

[复制链接]

6

主题

6

帖子

12

积分

新手上路

Rank: 1

积分
12
QQ
发表于 2019-7-1 09:46:38 | 显示全部楼层 |阅读模式
嗯,没错ApiSendMobile这货是我已经封装好的一个类。先来说说目前我们常用的发送短信方法,
1、与运营商联系,调用运营商的接口,把要发送的内容与手机号给运营商,让运营商去发送。(例如Mas机)
2、自己去买设备,然后在基于它进行二次开
3、专门的短信服务公司,让后通过网络服务形式调用第三方接口发送(例如广州首易)

   我们言归正传,本文的例子就是用了第一种方法,上代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package com.xiaoxm.util;
import java.io.BufferedReader;
import com.jasson.im.api.APIClient;
/**
* ApiTestDemo
*/
public class ApiSendMobile
{
    private long smId = 1;
    private int smType = 0;
    private String host = "mas地址";
    private String dbName = "mas";
    private String apiId = "用户apid";
    private String name = "用户名";
    private String pwd = "密码";
    private APIClient handler = new APIClient();
    BufferedReader in = null;
                                                                                                                                                                                                               
    public ApiSendMobile()
    {
                                                                                                                                                                                                                  
    }
    public void init()
    {
        int connectRe = handler.init(host, name, pwd, apiId,dbName);
        if(connectRe == APIClient.IMAPI_SUCC)
            info("初始化成功");
        else if(connectRe == APIClient.IMAPI_CONN_ERR)
            info("连接失败");
        else if(connectRe == APIClient.IMAPI_API_ERR)
            info("apiID不存在");
        if(connectRe != APIClient.IMAPI_SUCC)
        {
            System.exit(-1);
        }
    }
                                                                                                                                                                                                               
    public void release()
    {
        handler.release();
        Thread.currentThread().interrupt();
    }
                                                                                                                                                                                                               
                                                                                                                                                                                                               
                                                                                                                                                                                                               
                                                                                                                                                                                                               
    public String  sendSM(String mobile,String sendContent)
    {
        init(); //初始化 相关参数
        String  msg = "";
        int result = 0;
        result = handler.sendSM(mobile, sendContent, smId );
        if(result == APIClient.IMAPI_SUCC)
        {     
            msg = "发送成功";
        }
        else if(result == APIClient.IMAPI_INIT_ERR)
            msg = "未初始化";
        else if(result == APIClient.IMAPI_CONN_ERR)
            msg = "数据库连接失败";
        else if(result == APIClient.IMAPI_DATA_ERR)
            msg = "参数错误";
        else if(result == APIClient.IMAPI_DATA_TOOLONG)
            msg = "消息内容太长";
        else if(result == APIClient.IMAPI_INS_ERR)
            msg = "数据库插入错误";
        else
            msg = "出现其他错误";
                                                                                                                                                                                                                  
                                                                                                                                                                                                                  
        release();  //释放资源
                                                                                                                                                                                                                  
        return msg;
    }
                                                                                                                                                                                                               
    public void error(Object obj , Throwable thr)
    {
        info(obj);
        thr.printStackTrace();
    }
    public void info(Object obj)
    {
        System.out.println(obj);
    }
                                                                                                                                                                                                               
    public void quit()
    {
        release();
        System.exit(0);
    }
}


53

主题

313

帖子

1134

积分

金牌会员

Rank: 6Rank: 6

积分
1134
QQ
发表于 2020-4-2 13:47:13 | 显示全部楼层
有哪些营运商啊?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|X3技术论坛|Justep Inc.    

GMT+8, 2024-9-28 07:32 , Processed in 0.073956 second(s), 23 queries .

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表