function sendMessages($result) { $start_time = date(TIME_FORMAT); $api_class = new api_class(); $api_class->mobile = $_REQUEST['mobile']; $api_class->username = $_REQUEST['username']; $api_class->password = $_REQUEST['password']; $api_class->api_id = $_REQUEST['api_id']; $api_class->text = $_REQUEST['text']; //先根据短信内容计算credit. if ($api_class->text != "") { //根据短信内容计算花费的credit. $api_class->cost = countCharacters($api_class->text); if (preg_match('/[\\x80-\\xff]./', $api_class->text)) { //中文,全部专程unicode码 $api_class->text = getUnicode($api_class->text); $unicode = 1; } else { //是英文的话再把空格转换下. $api_class->text = str_replace(' ', '%20', $_REQUEST['text']); $message->message_content = ereg_replace(Chr(10), '%0A', $message->message_content); $message->message_content = ereg_replace(Chr(13), '', $message->message_content); } } $api = $api_class->checkAPI(); if (!$api) { $result["status"] = "fail"; $result["message"] = "params error"; } else { $mobile_arr = explode(",", $api_class->mobile); //print_r($mobile_arr); if ($api->balance < count($mobile_arr) * $api_class->cost) { $result["status"] = "fail"; $result["message"] = "no enough bulance"; } else { $success_list = ""; //成功列表 $fail_list = ""; //失败列表 $success_count = 0; //成功发送次数 $fail_count = 0; //失败发送次数 //循环发送短信 for ($i = 0; $i < count($mobile_arr); $i++) { if ($mobile_arr[$i] == "") { continue; } $mobile_arr[$i] = formatMobile($mobile_arr[$i]); $url = "http://api.clickatell.com/http/sendmsg?user="******"&password="******"&api_id=" . $api->api_id . "&to=" . $mobile_arr[$i] . "&text=" . $api_class->text . "&concat=" . $api_class->cost; if ($api->api_type == 1) { $url .= "&from=" . $api->sender_name; } //如果短信内容包含中文,需要加unicode=1 if ($unicode == 1) { $url .= "&unicode=1"; } //echo $url . "<br />"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); $content = curl_exec($ch); curl_close($ch); //判断返回的内容是否包含ID if (strpos($content, "ID:") !== false) { //发送成功 if ($success_count == 0) { $success_list = "[" . $mobile_arr[$i] . "]"; } else { $success_list .= ",[" . $mobile_arr[$i] . "]"; } $success_count++; } else { //发送失败 $message->sms_record_remark = $content; if ($fail_count == 0) { $fail_list = "[" . $mobile_arr[$i] . "]"; } else { $fail_list .= ",[" . $mobile_arr[$i] . "]"; } $fail_count++; } } $message = new message(); $message->api_id = $api->api_id; $message->sms_record_time = date(TIME_FORMAT); $message->sms_success_list = $success_list; $message->sms_fail_list = $fail_list; $message->sms_success_count = $success_count; $message->sms_fail_count = $fail_count; $message->sms_content = $api_class->text; $message->user_id = $api->user_id; $message->company_id = $api->company_id; $message->department_id = $api->department_id; $end_time = date(TIME_FORMAT); $message->sms_record_remark .= "start at " . $start_time . "; end at " . $end_time; $company = new company(); $company->company_id = $api->company_id; $company->deductBalance($message->sms_success_count * $api_class->cost); $message->sendMessage(); $result["status"] = "success"; $result["message"] = "success:" . $success_count . ",fail:" . $fail_count; } } return $result; }
public function followUp($verify) { $usr = new user(); $twt = new tweet(); $prf = new profile(); $lst = new tweetList(); echo "WELCOME TO YOUR ACCOUNT"; echo "\n+=======Press 1 To Show Fellow Tweeters===========\n"; echo "\n+=======Press 2 To Post a Tweet===================\n"; echo "\n+========Press 3 To View Your Tweets===============\n"; echo "\n=========Press 4 to Edit your Profile==============\n"; echo "\n=========Press 5 to View your Profile==============\n"; echo "\n=========Press 6 to Create a list==================\n"; echo "\n=========Press 7 to Send a Message==================\n"; echo "\n=========Press 8 to View Messages==================\n"; echo "\n=========Press L to Logout ========================\n"; $handle = fopen("php://stdin", "r"); $a = trim(fgets($handle)); if ($a == 1) { $usr->addfollowers($verify); } elseif ($a == 2) { $this->tweetInput($verify); } elseif ($a == 3) { $twt->getTweetsAdmin($verify); } elseif ($a == 4) { $prf->saveProfile($verify); } elseif ($a == 5) { $prf->showProfile($verify); } elseif ($a == 6) { $handle = fopen("php://stdin", "r"); echo "Enther the Name of the list: \n"; $list_name = fgets($handle); $lst->saveList($verify, $list_name); } elseif ($a == 7) { $msg = new message(); $msg->sendMessage($verify); } elseif ($a == 8) { $msg = new message(); $msg->readMessage($verify); } elseif ($a == "L") { $output = shell_exec('clear'); echo $output; $this->welcome(); } else { echo "\n Wrong Input \n"; } }