class Common_Sms{ protected static $ms_conf = array(); public function __construct(){ self::$ms_conf = array( 'url' => '1212', 'username' => 'XXX', 'password' => 'OOO', 'veryCode' => 'KKK' ); } private static function curl_post($method = '', $param = array()) { do { if(! $method || empty($param)) { $ret = array( 'status' => 'failed', 'msg' => 'Invalid param', 'results'=> '無效的參數' ); break; } $url = self::$ms_conf['url'] .'?method='.$method; } while(0); return $url; } /** * 發送驗證碼簡訊 * @param [type] $mobile 手機號 * @param array $param captcha: array( 'code'=> , 'minute' => ) * @return array 回傳資訊 */ public static function send($mobile = '', $param = array()){ do{ if(!$mobile) { $result = array('status' => 'failed', 'results' => '缺少[mobile] 參數'); break; } if(!isset($param['code'])) { $result = array('status' => 'failed', 'results' => '錯誤的[code] 參數'); break; } $param_arr = array( 'mobile' => $mobile, 'content' => "@1@={$param['code']}", 'sendtime' => '', 'msgtype' => 2, 'tempid' => 'JSM40485-0001', 'code' => 'utf-8', ); $req_result = self::curl_post('sendMsg', $param_arr); if($req_result['status'] == 'success') { // $req_result = trim($req_result); // $back_result = explode('#', $req_result); // if($back_result[0] == 0) // { // $result = array('status' => 'success', 'results' => array('send' => $back_result[2], 'commit' => $back_result[1])); // } // else // { // $msg = self::sendError($back_result); // $result = array('status' => 'failed', 'results' => $msg); // } // return $req_result['results']; } else { $result = array('status' => 'failed', 'results' => $req_result['msg']); break; } } while(0); return $result; }}
A PHP Error was encountered
Severity: Notice
Message: Undefined index: url
Filename: common/sms.php
Line Number: 32
沒有系統的看過書,求解 !!!
回複內容:
class Common_Sms{ protected static $ms_conf = array(); public function __construct(){ self::$ms_conf = array( 'url' => '1212', 'username' => 'XXX', 'password' => 'OOO', 'veryCode' => 'KKK' ); } private static function curl_post($method = '', $param = array()) { do { if(! $method || empty($param)) { $ret = array( 'status' => 'failed', 'msg' => 'Invalid param', 'results'=> '無效的參數' ); break; } $url = self::$ms_conf['url'] .'?method='.$method; } while(0); return $url; } /** * 發送驗證碼簡訊 * @param [type] $mobile 手機號 * @param array $param captcha: array( 'code'=> , 'minute' => ) * @return array 回傳資訊 */ public static function send($mobile = '', $param = array()){ do{ if(!$mobile) { $result = array('status' => 'failed', 'results' => '缺少[mobile] 參數'); break; } if(!isset($param['code'])) { $result = array('status' => 'failed', 'results' => '錯誤的[code] 參數'); break; } $param_arr = array( 'mobile' => $mobile, 'content' => "@1@={$param['code']}", 'sendtime' => '', 'msgtype' => 2, 'tempid' => 'JSM40485-0001', 'code' => 'utf-8', ); $req_result = self::curl_post('sendMsg', $param_arr); if($req_result['status'] == 'success') { // $req_result = trim($req_result); // $back_result = explode('#', $req_result); // if($back_result[0] == 0) // { // $result = array('status' => 'success', 'results' => array('send' => $back_result[2], 'commit' => $back_result[1])); // } // else // { // $msg = self::sendError($back_result); // $result = array('status' => 'failed', 'results' => $msg); // } // return $req_result['results']; } else { $result = array('status' => 'failed', 'results' => $req_result['msg']); break; } } while(0); return $result; }}
A PHP Error was encountered
Severity: Notice
Message: Undefined index: url
Filename: common/sms.php
Line Number: 32
沒有系統的看過書,求解 !!!
請問你怎麼調用的?
你的那個 靜態方法 是 private
的, 你怎麼調用的這個方法?
靜態方法在調用的時候, 類的建構函式是不會被自動調用的.
所以你的 $ms_conf
是一個空數組, 所以結果你應該懂的吧?
執行結果:
tttarray(0) {}