Send to mobile phone number in Java via SMS

Source: Internet
Author: User
Tags sendmsg

Package com.fetion.test;

Import Java.io.BufferedReader;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileReader;
Import java.io.IOException;
Import Java.io.InputStream;
Import Java.io.InputStreamReader;
Import java.util.Properties;

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;

/**
* API2.1 Call: f.php?phone=xxxxxx&pwd=xxx&to=xxxx&msg=xxxx&type=0
* Above interface parameter details VIP API
*1.phone: Mobile number
*2.PWD: fetion Password
*3.to: Who to send to (mobile phone number or flight signal)
*4.msg: fetion Content
*5.type: Action 0 (empty) Send SMS 1 Check Friends 2 Add Friends
*6.U: Alternate parameter: Add &u=1 at the end when sending content is garbled
*/
public class Fetion {
your phone number.
private static String PHONE = "";
Your own fetion password.
private static String PWD = "";
Each other's cell phone number
private static String to = "";
//
private static String configuration;

Private properties Config = new properties ();

Public Fetion () {
Init ();
}
Initializing the configuration file
public void init () {
try {
InputStream is = new FileInputStream ("Fetionconfig");
Config.load (New InputStreamReader (IS));
Configuration=config.getproperty ("weekendgreetings");
SYSTEM.OUT.PRINTLN (configuration);
Phone=config.getproperty ("Phone");
Pwd=config.getproperty ("pwd");
To=config.getproperty ("to");
Is.close ();
} catch (FileNotFoundException e) {
E.printstacktrace ();
} catch (IOException e) {
E.printstacktrace ();
}
}
public static void Sendmsg (String _phone,string _pwd,string _to,string _msg) throws HttpException, ioexception{
HttpClient client = new HttpClient ();
Postmethod post = new Postmethod ("http://3.ibtf.sinaapp.com/f.php");
Post.addrequestheader ("Content-type", "application/x-www-form-urlencoded;charset=utf-8");//Set transcoding in header file
namevaluepair[] Data ={
New Namevaluepair ("Phone", _phone),
New Namevaluepair ("pwd", _pwd),
New Namevaluepair ("to", _to),
New Namevaluepair ("MSG", _msg),
New Namevaluepair ("type", "0")
};
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 ("Utf-8"));
SYSTEM.OUT.PRINTLN (result);
System.out.println ("ok!");
Post.releaseconnection ();
}
public void Start () {
try {
FileReader FR = new FileReader (configuration);
BufferedReader br = new BufferedReader (FR);
String Msg=null;

while ((Msg=br.readline ())!=null) {
Fetion.sendmsg (PHONE, PWD, to, MSG);
}
Br.close ();
Fr.close ();
} catch (Exception e) {
E.printstacktrace ();
}

}
public static void Main (string[] args) {
Fetion f = new fetion ();
F.start ();
}

}

Send to mobile phone number in Java via SMS

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.