0 Star 0 Fork 0

Oakhole / smscode-java

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

smscode-java

该repo作为http://smscode.cn短信接口的插件包;

使用httpclient发起post请求;

引用

<dependency>
  <groupId>cn.smscode</groupId>
  <artifactId>smscode-java</artifactId>
  <version>1.0.0</version>
</dependency>

使用http://maven.oschina.net的仓库;

<repository>
    <id>oschina</id>
    <name>oschina</name>
    <url>http://maven.oschina.net/content/groups/public/</url>
</repository>

接口文档

http://smscode.cn/docs/api

接口调用

SmsCaptchaService.getInstance("11", "test", "test").text("验证码:0000.[smscode]").to(“13800000000”).send();

[SmsCaptchaService][SmsCaptchaService]: 提供短信服务;

  • SmsCaptchaService getInstance(String userid, String account, String password): 生成实例;

  • SmsCaptchaService text(String content): 内容赋值;

  • SmsCaptchaService text(SmsMessage smsMessage),参考SmsMessage: 通过SmsMessage用来封装模版短信和验证码生成待发送内容,如模版短信:注册验证码:0000。[smscode],所需喜欢验证码内容:"0000",指定验证码字符串,或默认规则生成的4位数字验证码,参考Captcha;

验证码可自定义规则和使用默认规则进行生成;

SmsCaptchaService to(String cellPhoneNumber): 手机号码;

boolean send(): 调用PhoneTextHelper进行推送;

短信服务工具类

[PhoneTextHelper][PhoneTextHelper]

/**
 * 使用httpclient发起post请求
 *
 * @param mobile  目的号码,必须为手机号
 * @param content 短信内容信息
 * @return xml解析后的的hashMap
 */
public Map<String, String> phoneText(String mobile, String content) {

    // 验证参数是否正确, 错误则返回为空值
    if (!checkRequestParameter() || !StringUtils.isNotEmpty(mobile) || !StringUtils.isNotEmpty(content)) {
        return null;
    }

    // 封装post请求参数
    List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
    postParameters.add(new BasicNameValuePair("action", send_action));
    postParameters.add(new BasicNameValuePair("userid", userid));
    postParameters.add(new BasicNameValuePair("account", account));
    postParameters.add(new BasicNameValuePair("password", password));
    postParameters.add(new BasicNameValuePair("mobile", mobile));
    postParameters.add(new BasicNameValuePair("content", content));
    postParameters.add(new BasicNameValuePair("sendTime", ""));
    postParameters.add(new BasicNameValuePair("checkcontent", checkcontent));

    CloseableHttpClient httpClient = HttpClients.createDefault();
    CloseableHttpResponse closeableHttpResponse = null;
    HttpPost httpPost = new HttpPost(send_url);

    UrlEncodedFormEntity urlEncodedFormEntity;
    Map<String, String> responseMap = null;

    // 发送post请求
    try {
        // 根据文档提示,使用utf-8格式编码
        urlEncodedFormEntity = new UrlEncodedFormEntity(postParameters, "utf-8");
        httpPost.setEntity(urlEncodedFormEntity);
        closeableHttpResponse = httpClient.execute(httpPost);
        if (closeableHttpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            HttpEntity httpEntity = closeableHttpResponse.getEntity();
            if (httpEntity != null) {
                // 将响应返回的xml解析为HashMap
                responseMap = parseXML(httpEntity.getContent());
            }
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (DocumentException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            closeableHttpResponse.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            httpClient.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    return responseMap;
}
The MIT License (MIT) Copyright (c) 2015 Sms Code Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

smscode.cn短信接口的插件包; 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/oakhole/smscode-java.git
git@gitee.com:oakhole/smscode-java.git
oakhole
smscode-java
smscode-java
master

搜索帮助