【PHP】创蓝253云通讯平台国际短信API接口demo
PHP接口請(qǐng)求類 <?php |
?
header("Content-type:text/html;?charset=UTF-8"); |
?
?
/*?* |
?
?*?類名:ChuanglanSmsApi |
?
?*?功能:創(chuàng)藍(lán)接口請(qǐng)求類 |
?
?*?詳細(xì):構(gòu)造創(chuàng)藍(lán)短信接口請(qǐng)求,獲取遠(yuǎn)程HTTP數(shù)據(jù) |
?
?*?版本:1.3 |
?
?*?日期:2017-04-12 |
?
?*?說(shuō)明: |
?
?*?以下代碼只是為了方便客戶測(cè)試而提供的樣例代碼,客戶可以根據(jù)自己網(wǎng)站的需要,按照技術(shù)文檔自行編寫,并非一 定要使用該代碼。 |
?
?*?該代碼僅供學(xué)習(xí)和研究創(chuàng)藍(lán)接口使用,只是提供一個(gè)參考。 |
?
?*/ |
?
?
class?ChuanglanSmsApi?{ |
?
?
????//Interface?URL?Used?to?send?SMS |
?
????const?API_SEND_URL='http://intapi.253.com/send/json?'; |
?
?
????//Interface?URL?Used?to?Query?SMS?balance |
?
????const?API_BALANCE_QUERY_URL='http://intapi.253.com/balance/json?'; |
?
?
????const?API_ACCOUNT='';//Get?SMS?Account??from??https://zz.253.com/site/login.html? |
?
?
????const?API_PASSWORD='';//Get?SMS?Password??from?https://zz.253.com/site/login.html |
?
????/** |
?
?????*?發(fā)送短信 |
?
?????* |
?
?????*?@param?string?$mobile?????? 手機(jī)號(hào)碼 |
?
?????*?@param?string?$msg????????? 短信內(nèi)容 |
?
?????*/ |
?
????public?function?sendInternational(?$mobile,?$msg)?{ |
?
?
????????//創(chuàng)藍(lán)接口參數(shù) |
?
????????$postArr?=?array?( |
?
????????????'account'??=>??self::API_ACCOUNT, |
?
????????????'password'?=>?self::API_PASSWORD, |
?
????????????'msg'?=>?$msg, |
?
????????????'mobile'?=>?$mobile |
?
????????); |
?
?
????????$result?=?$this->curlPost(?self::API_SEND_URL?,?$postArr); |
?
????????return?$result; |
?
????} |
?
?
?
?
?
????/** |
?
?????*?查詢額度 |
?
?????* |
?
?????*??查詢地址 |
?
?????*/ |
?
????public?function?queryBalance()?{ |
?
?
????????//查詢參數(shù) |
?
????????$postArr?=?array?(? |
?
????????????'account'?=>?self::API_ACCOUNT, |
?
????????????'password'?=>?self::API_PASSWORD, |
?
????????); |
?
????????$result?=?$this->curlPost(self::API_BALANCE_QUERY_URL,?$postArr); |
?
????????return?$result; |
?
????} |
?
?
????/** |
?
?????*?通過(guò)CURL發(fā)送HTTP請(qǐng)求 |
?
?????*?@param?string?$url??//請(qǐng)求URL |
?
?????*?@param?array?$postFields?//請(qǐng)求參數(shù)? |
?
?????*?@return?mixed |
?
?????*/ |
?
????private?function?curlPost($url,$postFields){ |
?
????????$postFields?=?json_encode($postFields); |
?
????????$ch?=?curl_init?(); |
?
????????curl_setopt(?$ch,?CURLOPT_URL,?$url?);? |
?
????????curl_setopt(?$ch,?CURLOPT_HTTPHEADER,?array( |
?
????????????'Content-Type:?application/json;?charset=utf-8' |
?
????????????) |
?
????????); |
?
????????curl_setopt(?$ch,?CURLOPT_RETURNTRANSFER,?1?); |
?
????????curl_setopt(?$ch,?CURLOPT_POST,?1?); |
?
????????curl_setopt(?$ch,?CURLOPT_POSTFIELDS,?$postFields); |
?
????????curl_setopt(?$ch,?CURLOPT_TIMEOUT,1);? |
?
????????curl_setopt(?$ch,?CURLOPT_SSL_VERIFYHOST,?0); |
?
????????curl_setopt(?$ch,?CURLOPT_SSL_VERIFYPEER,?0); |
?
????????$ret?=?curl_exec?(?$ch?); |
?
????????if?(false?==?$ret)?{ |
?
????????????$result?=?curl_error(??$ch); |
?
????????}?else?{ |
?
????????????$rsp?=?curl_getinfo(?$ch,?CURLINFO_HTTP_CODE); |
?
????????????if?(200?!==?$rsp)?{ |
?
????????????????$result?=?"請(qǐng)求狀態(tài)?".?$rsp?.?"?"?.?curl_error($ch); |
?
????????????}?else?{ |
?
????????????????$result?=?$ret; |
?
????????????} |
?
????????} |
?
????????curl_close?(?$ch?); |
?
????????return?$result; |
?
????} |
?
?
} |
總結(jié)
以上是生活随笔為你收集整理的【PHP】创蓝253云通讯平台国际短信API接口demo的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Intellij IDEA设置向前和向后
- 下一篇: 【PHP】创蓝253云通讯paas平台短