现在的位置: 首页 > 综合 > 正文

中国移动飞信免费发短信API接口(第三方)

2013年12月08日 ⁄ 综合 ⁄ 共 8270字 ⁄ 字号 评论关闭

  飞信是由中国移动通信集团公司推出的一款集商务应用和娱乐功能为一体的,基于手机应用以及与Internet深度互通的即时通讯产品,可免费给好友发送短信。

  1、下载中国移动飞信PC客户端软件(http://www.fetion.com.cn/downloads/pc.aspx),并注册开通飞信。注册成为飞信用户,下载飞信PC客户端、使用PC客户端基本功能,不收取费用。
  2、通过PC客户端,邀请并添加免费短信接收方的手机号码(仅限中国移动)到您的飞信好友,该手机号需要通过通过PC客户端、或回复短信接受您的邀请;
  3、通过 http://sms.api.bz/ 提供的 API 接口,即可免费给飞信好友或给你自己的手机发短信。利用本API接口可进行日程提醒、服务器监控、报警、故障通知或短信自动控制等功能。


  飞信免费发短信API接口在线演示: http://sms.api.bz/

  飞信免费发短信API接口调用方式(通过HTTP访问以下网址、支持GET和POST):

http://sms.api.bz/fetion.php?username=您的移动飞信登录手机号&password=您的移动飞信登录密码&sendto=接收短信的飞信好友手机号(也可以是你自己的手机号)&message=短信内容

  注:短信内容最大长度为180个汉字,超过180个汉字不发送。返回的信息为UTF-8编码的中文文本信息。


  例1:在Linux命令行下通过curl命令给自己的手机号(假设为13800138000)发送短信

curl "http://sms.api.bz/fetion.php?username=13800138000&password=123456&sendto=13800138000&message=短信内容"

  例2:在PHP5中通过file_get_contents函数发送短信(HTTP GET 方式)

  1. <?php  
  2. $url = "http://sms.api.bz/fetion.php?username=13812345678&password=123456&sendto=13512345678&message=短信内容";  
  3. $result = file_get_contents($url);  
  4. echo $result//返回信息默认为UTF-8编码的汉字,如果你的页面编码为gb2312,请使用下行语句输出返回信息。  
  5. //echo iconv("UTF-8", "GBK", $result);  
  6. ?>  


  例3:在PHP中通过curl发送短信(HTTP POST 方式)

  1. <?php  
  2. $data["username"] = 13812345678;  
  3. $data["password"] = "password123";  
  4. $data["sendto"] = 13512345678;  
  5. $data["message"] = "这是一条测试短信!";  
  6.   
  7. $curl = new Curl_Class();  
  8. $result = @$curl->post("http://sms.api.bz/fetion.php"$data);  
  9. echo $result//返回信息默认为UTF-8编码的汉字,如果你的页面编码为gb2312,请使用下行语句输出返回信息。  
  10. //echo iconv("UTF-8", "GBK", $result);  
  11.   
  12. //curl类  
  13. class Curl_Class  
  14. {  
  15.     function Curl_Class()  
  16.     {  
  17.         return true;  
  18.     }  
  19.   
  20.     function execute($method$url$fields = ''$userAgent = ''$httpHeaders = ''$username = ''$password = '')  
  21.     {  
  22.         $ch = Curl_Class::create();  
  23.         if (false === $ch)  
  24.         {  
  25.             return false;  
  26.         }  
  27.   
  28.         if (is_string($url) && strlen($url))  
  29.         {  
  30.             $ret = curl_setopt($ch, CURLOPT_URL, $url);  
  31.         }  
  32.         else  
  33.         {  
  34.             return false;  
  35.         }  
  36.         //是否显示头部信息  
  37.         curl_setopt($ch, CURLOPT_HEADER, false);  
  38.         //  
  39.         curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
  40.   
  41.         if ($username != '')  
  42.         {  
  43.             curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);  
  44.         }  
  45.   
  46.         $method = strtolower($method);  
  47.         if ('post' == $method)  
  48.         {  
  49.             curl_setopt($ch, CURLOPT_POST, true);  
  50.             if (is_array($fields))  
  51.             {  
  52.                 $sets = array();  
  53.                 foreach ($fields AS $key => $val)  
  54.                 {  
  55.                     $sets[] = $key . '=' . urlencode($val);  
  56.                 }  
  57.                 $fields = implode('&',$sets);  
  58.             }  
  59.             curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);  
  60.         }  
  61.         else if ('put' == $method)  
  62.         {  
  63.             curl_setopt($ch, CURLOPT_PUT, true);  
  64.         }  
  65.   
  66.         //curl_setopt($ch, CURLOPT_PROGRESS, true);  
  67.         //curl_setopt($ch, CURLOPT_VERBOSE, true);  
  68.         //curl_setopt($ch, CURLOPT_MUTE, false);  
  69.         curl_setopt($ch, CURLOPT_TIMEOUT, 10);//设置curl超时秒数  
  70.   
  71.         if (strlen($userAgent))  
  72.         {  
  73.             curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);  
  74.         }  
  75.   
  76.         if (is_array($httpHeaders))  
  77.         {  
  78.             curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);  
  79.         }  
  80.   
  81.         $ret = curl_exec($ch);  
  82.   
  83.         if (curl_errno($ch))  
  84.         {  
  85.             curl_close($ch);  
  86.             return array(curl_error($ch), curl_errno($ch));  
  87.         }  
  88.         else  
  89.         {  
  90.             curl_close($ch);  
  91.             if (!is_string($ret) || !strlen($ret))  
  92.             {  
  93.                 return false;  
  94.             }  
  95.             return $ret;  
  96.         }  
  97.     }  
  98.   
  99.     function post($url$fields$userAgent = ''$httpHeaders = ''$username = ''$password = '')  
  100.     {  
  101.         $ret = Curl_Class::execute('POST'$url$fields$userAgent$httpHeaders$username$password);  
  102.         if (false === $ret)  
  103.         {  
  104.             return false;  
  105.         }  
  106.   
  107.         if (is_array($ret))  
  108.         {  
  109.             return false;  
  110.         }  
  111.         return $ret;  
  112.     }  
  113.   
  114.     function get($url$userAgent = ''$httpHeaders = ''$username = ''$password = '')  
  115.     {  
  116.         $ret = Curl_Class::execute('GET'$url''$userAgent$httpHeaders$username$password);  
  117.         if (false === $ret)  
  118.         {  
  119.             return false;  
  120.         }  
  121.   
  122.         if (is_array($ret))  
  123.         {  
  124.             return false;  
  125.         }  
  126.         return $ret;  
  127.     }  
  128.   
  129.     function create()  
  130.     {  
  131.         $ch = null;  
  132.         if (!function_exists('curl_init'))  
  133.         {  
  134.             return false;  
  135.         }  
  136.         $ch = curl_init();  
  137.         if (!is_resource($ch))  
  138.         {  
  139.             return false;  
  140.         }  
  141.         return $ch;  
  142.     }  
  143.   
  144. }  
  145. ?>  

抱歉!评论已关闭.