接口文檔
代碼示例
<?php
// ① 該代碼僅供接入動力思維樂信短信接口參考使用,客戶可根據實際需要自行編寫; // ② 支持發送驗證碼短信、觸發通知短信等; // ③ 測試驗證碼短信、通知短信,請用默認的測試模板,默認模板詳見接口文檔。
class SendUtility { private $_config = array(); /** * 獲取相關配置 * Config.php文件中的樂信用戶名、密碼、簽名 */ public __construct($config) { $this->_config = $config; } /** * 拼接請求參數 */ function BuildContent($AimMobiles, $Content) { $str = "accName=" . urlencode($this->_config["UserName"]); $str .= "&accPwd=" . urlencode(strtoupper(md5($this->_config["Password"]))); $str .= "&aimcodes=" . urlencode($AimMobiles); $str .= "&content=" . urlencode($Content . $this->_config["Signature"]); return $str; } /** * 短信發送 * @param $AimMobiles 下行手機號 * @param $Content 短信內容 */ function Send($AimMobiles, $Content) { $content = $this->BuildContent($AimMobiles, $Content); $counter = 0; while ($counter < count($this->_config["Addresses"])) { $opts = array('http' => array("method" => "POST", "timeout" => $this->_config["HttpTimeout"], "header" => "Content-type: application/x-www-form-urlencoded", "content" => $content)); $message = file_get_contents($this->_config["Addresses"][$counter] . "/send", false, stream_context_create($opts)); if ($message == false) $counter++; else break; } if ($message == false) return "發送失敗"; $RtnString = explode(";", $message); if ($RtnString[0] != "1") return $RtnString[1]; return $RtnString[0]; } /** * 余額查詢 * @param $accName 用戶名 * @param $accPwd 密碼 */ function Query() { $content = "accName=" . urlencode($this->_config["UserName"]); $content .= "&accPwd=" . urlencode(strtoupper(md5($this->_config["Password"]))); $opts = array('http' => array("method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded", "content" => $content)); $message = file_get_contents($this->_config["Addresses"][0] . "/qryBalance", false, stream_context_create($opts)); if ($message == false) return "查詢失敗"; $RtnString = explode(";", $message); if ($RtnString[0] != "1") return $RtnString[1]; return $RtnString[2]; } }
<?php class SendUtility { private $_config = array(); /** * 獲取相關配置 * Config.php文件中的樂信用戶名、密碼、簽名 */ function __construct($config) { $this->_config = $config; } /** * 拼接請求參數 */ function BuildContent($AimMobiles, $Content) { $str = "accName=" . urlencode($this->_config["UserName"]); $str .= "&accPwd=" . urlencode(strtoupper(md5($this->_config["Password"]))); $str .= "&aimcodes=" . urlencode($AimMobiles); $str .= "&content=" . urlencode($Content . $this->_config["Signature"]); return $str; } /** * 短信發送 * @param $AimMobiles 下行手機號 * @param $Content 短信內容 */ function Send($AimMobiles, $Content) { $content = $this->BuildContent($AimMobiles, $Content); $counter = 0; while ($counter < count($this->_config["Addresses"])) { $opts = array('http' => array("method" => "POST", "timeout" => $this->_config["HttpTimeout"], "header" => "Content-type: application/x-www-form-urlencoded", "content" => $content)); $message = file_get_contents($this->_config["Addresses"][$counter] . "/send", false, stream_context_create($opts)); if ($message == false) $counter++; else break; } if ($message == false) return "發送失敗"; $RtnString = explode(";", $message); if ($RtnString[0] != "1") return $RtnString[1]; return $RtnString[0]; } /** * 余額查詢 * @param $accName 用戶名 * @param $accPwd 密碼 */ function Query() { $content = "accName=" . urlencode($this->_config["UserName"]); $content .= "&accPwd=" . urlencode(strtoupper(md5($this->_config["Password"]))); $opts = array('http' => array("method" => "POST", "header" => "Content-type: application/x-www-form-urlencoded", "content" => $content)); $message = file_get_contents($this->_config["Addresses"][0] . "/qryBalance", false, stream_context_create($opts)); if ($message == false) return "查詢失敗"; $RtnString = explode(";", $message); if ($RtnString[0] != "1") return $RtnString[1]; return $RtnString[2]; } } ?>