case 'def': $sql = "select * from " . $ecs->table("student") . " where is_active=1 "; //and license!='' $students = $db->getAll($sql); $smarty->assign("students", $students); $smarty->display('sms_def.htm'); exit; case 'send': $phones = trim($_POST["phones"]); $content = trim($_POST["content"]); $copy = trim($_POST["copy"]); $result = array("error" => 1, "msg" => "您选择的家长的电话号码全部为空"); if (str_len($phones) > 4) { if ($copy) { $admin = get_admin_by_id($_SESSION["admin_id"]); if (is_moblie($admin["cellphone"])) { $phones .= "," . $admin["cellphone"]; } } $sms = new sms(); $result = $sms->send($phones, $content, $school_code, $class_code, $_SESSION["admin_name"]); } make_json($result); exit; case 'record': $smarty->display('sms_list.htm'); exit; case 'ajax_list': $list = sms_list($class_code, $_SESSION["phone"]); make_json($list); exit;
/** * 封装短信发送接口 * url最长不能超过2083 */ function send($phones, $msg, $school_code, $class_code, $creator, $suf = '') { $result = array('error' => 0, 'msg' => ''); //检查手机号码是否正确,手机号总长度不超过1024 if (empty($phones) || str_len($phones) == 0) { return array('error' => 1, 'msg' => '手机号码不能为空'); } if (str_len($phones) > 1024) { return array('error' => 1, 'msg' => '手机号码过长,最多可同时发送给100个客户'); } $phones_tmp = explode(",", $phones); $error_phones = array(); foreach ($phones_tmp as $k => $p) { if (!is_moblie($p)) { $error_phones[] = $p; } } if (count($error_phones) > 0) { $erro = implode(",", $error_phones); return array('error' => 1, 'msg' => '您发送的号码中有错误号码:' . $erro . ''); } //对号码进行去重 $phones = removeRepeat($phones_tmp); //检查短信内容是否包含有敏感字符,短信内容不能超过512个字符 if (empty($msg) || str_len($msg) == 0) { return array('error' => 1, 'msg' => '短信内容不能为空'); } if (str_len($msg) > 512) { return array('error' => 1, 'msg' => '短信内容不能超过512个字符'); } //检查是否带了签名 if (stripos($msg, "【") <= -1 || stripos($msg, "】") <= -1) { if ($suf) { $this->suf = suf; } $msg .= $this->suf; } $error_words = array(); foreach ($this->sense as $k => $v) { if (stripos($msg, $v) > -1) { $error_words[] = $v; } } if (count($error_words) > 0) { $erro = implode("|", $error_words); return array('error' => 1, 'msg' => '您发送的短信内容中存在敏感词汇:' . $erro . ''); } /** * 1、将短信插入到短信队列 * 2、发送短信 * 3、更新短信队列中的状态 * 4、更新短信服务器的总条数记录 */ $school_code = $school_code != "super" ? $school_code : 'hteacher'; $database = $school_code ? $school_code : 'hteacher'; if ($database != "hteacher" && !strpos($database, "_school")) { $database = $database . '_school'; } $sql = "insert into " . $database . ".ht_sms (content,phones, status, class_code, creator, created ) \n\t\t\tvalues ('" . $msg . "','" . $phones . "',0,'" . $class_code . "','" . $creator . "',now())"; $this->db->query($sql); $sms_id = $this->db->insert_id(); $info = $this->sendSMS($phones, $msg); if (empty($info[0]) || $info[0] == 0) { $sql = "update " . $database . ".ht_sms set status=2 where sms_id=" . $sms_id; $this->db->query($sql); return array('error' => 1, 'msg' => '短信发送失败:' . $info[1] . ''); } $sql = "update " . $database . ".ht_sms set status=1, num='" . $info[1] . "',sended=now() where sms_id=" . $sms_id; $this->db->query($sql); $sql = "update hteacher.ht_sms_server set used=used+" . $info[1] . " where sms_server_id=" . $this->sms_server_id; $this->db->query($sql); return $result; }