日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > php >内容正文

php

【PHP】创蓝253云通讯平台国际短信API接口demo

發(fā)布時(shí)間:2024/1/1 php 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【PHP】创蓝253云通讯平台国际短信API接口demo 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

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)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。