php免费利用飞信发送验证码,PHP 使用飞信API发送免费短信示例
這篇文章主要為大家詳細介紹了PHP 使用飛信API發(fā)送免費短信示例,具有一定的參考價值,可以用來參考一下。
對PHP 使用飛信 API 來發(fā)送免費短信感興趣的小伙伴,下面一起跟隨512筆記的小編兩巴掌來看看吧!
/**
* PHP 使用飛信 API 來發(fā)送免費短信
*
* @param
* @arrange 512-筆記網(wǎng): 512PiC.com
**/
$data["username"] = 13812345678;
$data["password"] = "password123";
$data["sendto"] = 13512345678;
$data["message"] = "這是一條測試短信!";
$curl = new Curl_Class();
$result = @$curl->post("http://sms.api.bz/fetion.php", $data);
echo $result; //返回信息默認為UTF-8編碼的漢字,如果你的頁面編碼為gb2312,請使用下行語句輸出返回信息。
//echo iconv("UTF-8", "GBK", $result);
//curl類
class Curl_Class
{
function Curl_Class()
{
return true;
}
function execute($method, $url, $fields = '', $userAgent = '', $httpHeaders = '', $username = '', $password = '')
{
$ch = Curl_Class::create();
if (false === $ch)
{
return false;
}
if (is_string($url) && strlen($url))
{
$ret = curl_setopt($ch, CURLOPT_URL, $url);
}
else
{
return false;
}
//是否顯示頭部信息
curl_setopt($ch, CURLOPT_HEADER, false);
//
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($username != '')
{
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
}
$method = strtolower($method);
if ('post' == $method)
{
curl_setopt($ch, CURLOPT_POST, true);
if (is_array($fields))
{
$sets = array();
foreach ($fields AS $key => $val)
{
$sets[] = $key . '=' . urlencode($val);
}
$fields = implode('&',$sets);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
}
else if ('put' == $method)
{
curl_setopt($ch, CURLOPT_PUT, true);
}
//curl_setopt($ch, CURLOPT_PROGRESS, true);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
//curl_setopt($ch, CURLOPT_MUTE, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);//設(shè)置curl超時秒數(shù)
if (strlen($userAgent))
{
curl_setopt($ch, CURLOPT_USERAGENT, $userAgent);
}
if (is_array($httpHeaders))
{
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpHeaders);
}
$ret = curl_exec($ch);
if (curl_errno($ch))
{
curl_close($ch);
return array(curl_error($ch), curl_errno($ch));
}
else
{
curl_close($ch);
if (!is_string($ret) || !strlen($ret))
{
return false;
}
return $ret;
}
}
function post($url, $fields, $userAgent = '', $httpHeaders = '', $username = '', $password = '')
{
$ret = Curl_Class::execute('POST', $url, $fields, $userAgent, $httpHeaders, $username, $password);
if (false === $ret)
{
return false;
}
if (is_array($ret))
{
return false;
}
return $ret;
}
function get($url, $userAgent = '', $httpHeaders = '', $username = '', $password = '')
{
$ret = Curl_Class::execute('GET', $url, '', $userAgent, $httpHeaders, $username, $password);
if (false === $ret)
{
return false;
}
if (is_array($ret))
{
return false;
}
return $ret;
}
function create()
{
$ch = null;
if (!function_exists('curl_init'))
{
return false;
}
$ch = curl_init();
if (!is_resource($ch))
{
return false;
}
return $ch;
}
}
/*** 來自512筆記(www.512pic.com) ***/
注:關(guān)于PHP 使用飛信API發(fā)送免費短信示例的內(nèi)容就先介紹到這里,更多相關(guān)文章的可以留意512筆記的其他信息。
關(guān)鍵詞:短信
您可能感興趣的文章
總結(jié)
以上是生活随笔為你收集整理的php免费利用飞信发送验证码,PHP 使用飞信API发送免费短信示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android category 讲解
- 下一篇: pycharm(Idea)破解到2100