使用飞信api接口实现短信发送(只能发送好友)

找了很久才找到一个能用的飞信API接口(http://quanapi.sinaapp.com/fetion.php?u=飞信登录手机号&p=飞信登录密码&to=接收飞信的手机号&m=飞信内容),不过是第三方的API接口,飞信官方是没有发布API接口的,正在做一个环境监测系统,需要用到短信报警功能,当然使用短信猫也可以实现,不过毕竟能省则省,话不多说,这是我用C#写的一个程序:

1.界面如下

2.代码

 

  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. string fno = textBox_fno.Text; //发件人的号码
  4. string fp = textBox_fp.Text; //发件人密码
  5. string fto = textBox_fto.Text; //收件人号码
  6. string fm = textBox_fm.Text; //短信内容
  7. fm = UrlEncode(fm);
  8. string url = "http://quanapi.sinaapp.com/fetion.php?u=" + fno + "&p=" + fp + "&to=" + fto + "&m=" + fm;//破解API
  9. string res = getContent(url);
  10. MessageBox.Show("短信发送成功!");
  11. }
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("短信发送成功!");
        }
  1. public static string UrlEncode(string str)
  2. {
  3. StringBuilder sb = new StringBuilder();
  4. byte[] byStr = System.Text.Encoding.Default.GetBytes(str); //
  5. for (int i = 0; i < byStr.Length; i++)
  6. {
  7. sb.Append(@"%" + Convert.ToString(byStr[i], 16));
  8. }
  9. return (sb.ToString());
  10. }
  11. private static string getContent(string Url)
  12. {
  13. string strResult = "";
  14. try
  15. {
  16. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
  17. //声明一个HttpWebRequest请求
  18. request.Timeout = 30000;
  19. //设置连接超时时间
  20. request.Headers.Set("Pragma", "no-cache");
  21. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  22. Stream streamReceive = response.GetResponseStream();
  23. Encoding encoding = Encoding.GetEncoding("GB2312");
  24. StreamReader streamReader = new StreamReader(streamReceive, encoding);
  25. strResult = streamReader.ReadToEnd();
  26. streamReader.Close();
  27. }
  28. catch
  29. {
  30. throw;
  31. }
  32. return strResult;
  33. }    
posted @ 2014-01-15 10:58  梦的怒放ing  阅读(1411)  评论(0编辑  收藏  举报