Java Send SMS

Source: Internet
Author: User

1. Introduction of Interface Usage

Sending SMS is sure to use a third-party interface, and Java itself is definitely not able to send text messages directly. There are a lot of third-party interface, here directly to find a regular and reliable a little learning

China Network Construction (http://sms.webchinese.cn/) is used here.

After opening the URL, click Register now

2. Get the SMS Key

Once the registration is complete, check the red SMS key. Click Edit SMS Key

here is the key to remember the message, of course, you can also modify the SMS key

3. Using SMS API Interface

Click on the SMS API interface on the left, or enter http://sms.webchinese.cn/api.shtml directly

The following interface appears:

Find the Java sample program below

4. Java code

12345678910111213141516171819202122232425262728293031323334353637383940 package com.fz.http;import java.io.IOException;import org.apache.commons.httpclient.Header;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpException;import org.apache.commons.httpclient.NameValuePair;import org.apache.commons.httpclient.methods.PostMethod;/**  * 类说明 :利用中国网建接口发送短信 * @author   FangZheng * @version  时间:2015-8-30 下午6:21:10  * 1、打开:http://sms.webchinese.cn/ 注册一个用户,默认用户是5条短信 * 2、打开api短信接口,找到修改短信秘钥菜单,找到自己的短信秘钥 * 3、使用api接口来发送短信,官方给的有java,php等各种语言的例子即可发送短信 */public class SendMsgTest {    public static void main(String[] args) throws HttpException, IOException {        HttpClient client = new HttpClient();        PostMethod post = new PostMethod("http://gbk.sms.webchinese.cn");         post.addRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");//在头文件中设置转码        NameValuePair[] data ={ new NameValuePair("Uid", "zhangsan"),new NameValuePair("Key", "23825bbfbd73c539f05e"),new NameValuePair("smsMob","1307*******"),new NameValuePair("smsText","验证码:8888")};        post.setRequestBody(data);        client.executeMethod(post);        Header[] headers = post.getResponseHeaders();        int statusCode = post.getStatusCode();        System.out.println("statusCode:"+statusCode);        for(Header h : headers)        {        System.out.println(h.toString());        }        String result = new String(post.getResponseBodyAsString().getBytes("gbk"));         System.out.println(result); //打印返回消息状态        post.releaseConnection();    }}

The Java program runs on 3 jar packages, which can be downloaded directly on its page.

The final program ran successfully, and the corresponding mobile phone number also received a text message.



From for notes (Wiz)



Java Send SMS

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.