找了很久才找到一个能用的飞信API接口(http://quanapi.sinaapp.com/fetion.php?u=飞信登录手机号&p=飞信登录密码&to=接收飞信的手机号&m=飞信内容),不过是第三方的API接口,飞信官方是没有发布API接口的,正在做一个环境监测系统,需要用到短信报警功能,当然使用短信猫也可以实现,不过毕竟能省则省,话不多说,这是我用C#写的一个程序:
1.界面如下
2.代码
- private void button1_Click(object sender, EventArgs e)
- {
- string fno = textBox_fno.Text; //发件人的号码
- string fp = textBox_fp.Text; //发件人密码
- string fto = textBox_fto.Text; //收件人号码
- string fm = textBox_fm.Text; //短信内容
- fm = UrlEncode(fm);
- string url = "http://quanapi.sinaapp.com/fetion.php?u=" + fno + "&p=" + fp + "&to=" + fto + "&m=" + fm;//破解API
- string res = getContent(url);
- MessageBox.Show("短信发送成功!");
- }
private void button1_Click(object sender, EventArgs e) { string fno = textBox_fno.Text; //发件人的号码 string fp = textBox_fp.Text; //发件人密码 string fto = textBox_fto.Text; //收件人号码 string fm = textBox_fm.Text; //短信内容 fm = UrlEncode(fm); string url = "http://quanapi.sinaapp.com/fetion.php?u=" + fno + "&p=" + fp + "&to=" + fto + "&m=" + fm;//破解API string res = getContent(url); MessageBox.Show("短信发送成功!"); }
- public static string UrlEncode(string str)
- {
- StringBuilder sb = new StringBuilder();
- byte[] byStr = System.Text.Encoding.Default.GetBytes(str); //
- for (int i = 0; i < byStr.Length; i++)
- {
- sb.Append(@"%" + Convert.ToString(byStr[i], 16));
- }
- return (sb.ToString());
- }
- private static string getContent(string Url)
- {
- string strResult = "";
- try
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
- //声明一个HttpWebRequest请求
- request.Timeout = 30000;
- //设置连接超时时间
- request.Headers.Set("Pragma", "no-cache");
- HttpWebResponse response = (HttpWebResponse)request.GetResponse();
- Stream streamReceive = response.GetResponseStream();
- Encoding encoding = Encoding.GetEncoding("GB2312");
- StreamReader streamReader = new StreamReader(streamReceive, encoding);
- strResult = streamReader.ReadToEnd();
- streamReader.Close();
- }
- catch
- {
- throw;
- }
- return strResult;
- }