Update twilio.api.php
This commit is contained in:
parent
51b17a3059
commit
ebddf89ae3
|
@ -15,30 +15,50 @@ if(!check_function_exists("twilio_get_config")) {
|
|||
"sid" => get_value_in_array("twilio_sid", $config, ""),
|
||||
"token" => get_value_in_array("twilio_token", $config, ""),
|
||||
"from" => get_value_in_array("twilio_from", $config, ""),
|
||||
"block_size" => get_value_in_array("twilio_block_size", $config, 160)
|
||||
"char_limit" => get_value_in_array("twilio_char_limit", $config, 160)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if(!check_function_exists("twilio_get_message_blocks")) {
|
||||
function twilio_parse_messages($message) {
|
||||
$strings = array();
|
||||
|
||||
$cnf = twilio_get_config();
|
||||
|
||||
if(loadHelper("string.utils")) {
|
||||
$strings = get_splitted_strings($message, $cnf['char_limit']);
|
||||
} else {
|
||||
$strings[] = substr($messages, 0, $cnf['char_limit']);
|
||||
}
|
||||
|
||||
return $strings;
|
||||
}
|
||||
}
|
||||
|
||||
if(!check_function_exists("twilio_send_message")) {
|
||||
function twilio_send_message($message, $to) {
|
||||
$response = false;
|
||||
|
||||
$cnf = twilio_get_config();
|
||||
$messages = twilio_parse_messages($message);
|
||||
|
||||
if(loadHelper("webpagetool")) {
|
||||
$request_url = sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json", $cnf['sid']);
|
||||
$response = get_web_json($request_url, "post.cmd", array(
|
||||
"headers" => array(
|
||||
"Content-Type" => "application/x-www-form-urlencoded",
|
||||
"Authentication" => array("Basic", $cnf['sid'], $cnf['token']),
|
||||
),
|
||||
"data" => array(
|
||||
"Body" => $message,
|
||||
"From" => $cnf['from'],
|
||||
"To" => $to,
|
||||
)
|
||||
));
|
||||
|
||||
foreach($messages as $_message) {
|
||||
$response = get_web_json($request_url, "post.cmd", array(
|
||||
"headers" => array(
|
||||
"Content-Type" => "application/x-www-form-urlencoded",
|
||||
"Authentication" => array("Basic", $cnf['sid'], $cnf['token']),
|
||||
),
|
||||
"data" => array(
|
||||
"Body" => $_message,
|
||||
"From" => $cnf['from'],
|
||||
"To" => $to,
|
||||
)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
return $response;
|
||||
|
|
Loading…
Reference in New Issue
Block a user