function send_sms($username, $password, $msisdn, $message, $sender = "COE Alert!", $ScheduledDelivery = "", $force = "premium") { $url = "http://www.thaibulksms.com/sms_api.php"; if (extension_loaded('curl')) { $data = array('username' => $username, 'password' => $password, 'msisdn' => $msisdn, 'message' => $message, 'sender' => $sender, 'ScheduledDelivery' => $ScheduledDelivery, 'force' => $force); $data_string = http_build_query($data); $agent = "ThaiBulkSMS API PHP Client"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); $xml_result = curl_exec($ch); $code = curl_getinfo($ch); curl_close($ch); if ($code['http_code'] == 200) { if (function_exists('simplexml_load_string')) { $sms = new \SimpleXMLElement($xml_result); $count = count($sms->QUEUE); if ($count > 0) { $count_pass = 0; $count_fail = 0; $used_credit = 0; for ($i = 0; $i < $count; $i++) { if ($sms->QUEUE[$i]->Status) { $count_pass++; $used_credit += $sms->QUEUE[$i]->UsedCredit; } else { $count_fail++; } } if ($count_pass > 0) { $msg_string = "สามารถส่งออกได้จำนวน {$count_pass} หมายเลข, ใช้เครดิตทั้งหมด {$used_credit} เครดิต"; } if ($count_fail > 0) { $msg_string = "ไม่สามารถส่งออกได้จำนวน {$count_fail} หมายเลข"; } } else { $msg_string = "เกิดข้อผิดพลาดในการทำงาน, (" . $sms->Detail . ")"; } } else { if (function_exists('xml_parse')) { $xml = sms::xml2array($xml_result); $count = count($xml['SMS']['QUEUE']); if ($count > 0) { $count_pass = 0; $count_fail = 0; $used_credit = 0; for ($i = 0; $i < $count; $i++) { if ($xml['SMS']['QUEUE'][$i]['Status']) { $count_pass++; $used_credit += $xml['SMS']['QUEUE'][$i]['UsedCredit']; } else { $count_fail++; } } if ($count_pass > 0) { $msg_string = "สามารถส่งออกได้จำนวน {$count_pass} หมายเลข, ใช้เครดิตทั้งหมด {$used_credit} เครดิต"; } if ($count_fail > 0) { $msg_string = "ไม่สามารถส่งออกได้จำนวน {$count_fail} หมายเลข"; } } else { $msg_string = "เกิดข้อผิดพลาดในการทำงาน, (" . $xml['SMS']['Detail'] . ")"; } } else { $msg_string = "เกิดข้อผิดพลาดในการทำงาน: <br /> ระบบไม่รองรับฟังก์ชั่น XML"; } } } else { //$http_codes = parse_ini_file("http_code.ini"); //$msg_string = "เกิดข้อผิดพลาดในการทำงาน: <br />" . $code['http_code'] . " " . $http_codes[$code['http_code']]; $msg_string = "เกิดข้อผิดพลาดในการทำงาน: <br />" . $code['http_code']; } } else { if (function_exists('fsockopen')) { $msg_string = $this->sending_fsock($username, $password, $msisdn, $message, $sender, $ScheduledDelivery, $force); } else { $msg_string = "cURL OR fsockopen is not enabled"; } } return $msg_string; }
function send_sms($username, $password, $msisdn, $message, $sender = "THAIBULKSMS", $ScheduledDelivery = "", $force = "standard") { $url = "http://www.thaibulksms.com/sms_api.php"; //$url = "https://secure.thaibulksms.com/sms_api_test.php"; if (extension_loaded('curl')) { $data = array('username' => $username, 'password' => $password, 'msisdn' => $msisdn, 'message' => $message, 'sender' => $sender, 'ScheduledDelivery' => $ScheduledDelivery, 'force' => $force); $data_string = http_build_query($data); $agent = "ThaiBulkSMS API PHP Client"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15); $xml_result = curl_exec($ch); $code = curl_getinfo($ch); curl_close($ch); echo $xml_result; if ($code['http_code'] == 200) { if (function_exists('simplexml_load_string')) { $sms = new SimpleXMLElement($xml_result); $count = count($sms->QUEUE); if ($count > 0) { $count_pass = 0; $count_fail = 0; $used_credit = 0; for ($i = 0; $i < $count; $i++) { if ($sms->QUEUE[$i]->Status) { $count_pass++; $used_credit += $sms->QUEUE[$i]->UsedCredit; } else { $count_fail++; } } if ($count_pass > 0) { $msg_string = "Can export the {$count_pass} number, Take all the credit {$used_credit} credit"; } if ($count_fail > 0) { $msg_string = "Can not be exported to the {$count_fail} number"; } } else { $msg_string = "An error occurred in the workplace, (" . $sms->Detail . ")"; } } else { if (function_exists('xml_parse')) { $xml = sms::xml2array($xml_result); $count = count($xml['SMS']['QUEUE']); if ($count > 0) { $count_pass = 0; $count_fail = 0; $used_credit = 0; for ($i = 0; $i < $count; $i++) { if ($xml['SMS']['QUEUE'][$i]['Status']) { $count_pass++; $used_credit += $xml['SMS']['QUEUE'][$i]['UsedCredit']; } else { $count_fail++; } } if ($count_pass > 0) { $msg_string = "Can export the {$count_pass} number, Take all the credit {$used_credit} Credit"; } if ($count_fail > 0) { $msg_string = "Can not be exported to the {$count_fail} number"; } } else { $msg_string = "An error occurred in the workplace., (" . $xml['SMS']['Detail'] . ")"; } } else { $msg_string = "An error occurred in the workplace: <br /> The system does not support this function.... XML"; } } } else { //$http_codes = parse_ini_file("http_code.ini"); //$msg_string = "เกิดข้อผิดพลาดในการทำงาน: <br />" . $code['http_code'] . " " . $http_codes[$code['http_code']]; $msg_string = "An error occurred in the workplace: <br />" . $code['http_code']; } } else { if (function_exists('fsockopen')) { $msg_string = $this->sending_fsock($username, $password, $msisdn, $message, $sender, $ScheduledDelivery, $force); } else { $msg_string = "cURL OR fsockopen is not enabled"; } } return $msg_string; }