Пример #1
0
Файл: SMS.php Проект: zwq/unpei
 /**
  * 给企业用户发送短信
  * @param string $SpCode 					企业编号
  * @param string $LoginName 			用户名称
  * @param string $Password 				用户密码
  * @param string $MessageContent 	短信内容, 最大700个字符
  * @param string $UserNumber 			手机号码(多个号码用”,”分隔),最多1000个号码
  * @param string $SerialNumber 			流水号,20位数字,唯一
  * @param string $ScheduleTime 			预约发送时间,格式:yyyyMMddhhmmss,如‘20090901010101’,立即发送请填空
  * @param string $ExtendAccessNum 	接入号扩展号
  * @param string $f 								提交时检测方式:为”1“ 提交号码中有效的号码仍正常发出短信,无效的号码在返回参数faillist中列出,不为1 或该参数不存在 --- 提交号码中只要有无效的号码,那么所有的号码都不发出短信,所有的号码在返回参数faillist中列出
  * 外部调用方法
  * $sms=new SMS();
  * $ret = $sms->sendMessage("200518", "zx_zshy", "zs0166", "发送测试", "15377076988", "", "", "", "1");
  */
 public function sendMessage($SpCode, $LoginName, $Password, $MessageContent, $UserNumber, $SerialNumber, $ScheduleTime, $ExtendAccessNum, $f)
 {
     if (empty($SpCode) || empty($LoginName) || empty($Password)) {
         return array("code" => "-1", "SMS" => "企业编号或者用户名或密码为空", "data" => array());
     }
     if (empty($MessageContent) || strlen($MessageContent) > 700) {
         return array("code" => "-1", "SMS" => "短信内容不能为空且最大字符为700个", "data" => array());
     }
     $MessageContent = iconv("UTF-8", "GB2312//IGNORE", $MessageContent);
     if ($UserNumber == '') {
         return array("code" => "-1", "SMS" => "手机号不能为空", "data" => array());
     }
     $phone_arr = explode(",", $UserNumber);
     if (empty($phone_arr) || count($phone_arr) > 1000) {
         return array("code" => "-1", "SMS" => "手机号不能为空且手机号码最大数量为1000", "data" => array());
     }
     $data["SpCode"] = $SpCode;
     $data["LoginName"] = $LoginName;
     $data["Password"] = $Password;
     $data["MessageContent"] = $MessageContent;
     $data["UserNumber"] = $UserNumber;
     $data["SerialNumber"] = $SerialNumber;
     $data["ScheduleTime"] = $ScheduleTime;
     $data["ExtendAccessNum"] = $ExtendAccessNum;
     $data["f"] = $f;
     $return = Sms::call(SMS::$SEND_URL, $data);
     $return = iconv("GB2312", "UTF-8", $return);
     $return = explode("&", $return);
     $ret_arr = array();
     foreach ($return as $val) {
         list($key, $value) = explode("=", $val);
         if ($key == "result") {
             $ret_arr["code"] = $value;
         } elseif ($key == "description") {
             $ret_arr["SMS"] = $value;
         } elseif ($key == "faillist") {
             $ret_arr["data"] = array("faillist" => $value);
         }
     }
     return $ret_arr;
 }