Created
December 4, 2017 16:20
-
-
Save cjzamora/59aa6bbe1924fd0c1abbd4a9573691c7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // --> | |
$data = json_decode(file_get_contents('php://input'), true); | |
error_log(print_r($_POST, true)); | |
if(isset($_GET['access_token'])) { | |
$subscribers = file_get_contents('subscribers.txt'); | |
try { | |
$subscribers = json_decode($subscribers, true); | |
} catch(\Exception $e) {} | |
if(!$subscribers) { | |
$subscribers = array(); | |
} | |
$subscribers['tel:+63' . $_GET['subscriber_number']] = $_GET['access_token']; | |
file_put_contents('subscribers.txt', json_encode($subscribers)); | |
exit; | |
} | |
$subscribers = json_decode(file_get_contents('subscribers.txt'), true); | |
$sender = $data['inboundSMSMessageList']['inboundSMSMessage'][0]['senderAddress']; | |
$message = $data['inboundSMSMessageList']['inboundSMSMessage'][0]['message']; | |
error_log(print_r('SENDER:' . $sender, true)); | |
error_log(print_r('MESSAGE:' .$message, true)); | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_PORT => "8081", | |
CURLOPT_URL => "http://172.104.191.6:8081/?message=" . urlencode($message), | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => "", | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => "GET", | |
CURLOPT_HTTPHEADER => array( | |
"cache-control: no-cache", | |
"postman-token: e24503dc-da49-f6b4-578f-c2898a96b87c" | |
), | |
)); | |
$response = curl_exec($curl); | |
$err = curl_error($curl); | |
curl_close($curl); | |
if ($err) { | |
echo "cURL Error #:" . $err; | |
} else { | |
echo $response; | |
} | |
error_log(print_r('CHATBOT:' . $response, true)); | |
$response = json_decode($response, true); | |
$token = $subscribers[$sender]; | |
$data = array( | |
'message' => $response['message'], | |
'address' => $sender | |
); | |
$curl = curl_init(); | |
curl_setopt_array($curl, array( | |
CURLOPT_URL => "https://devapi.globelabs.com.ph/smsmessaging/v1/outbound/21580495/requests?access_token=" . $token, | |
CURLOPT_RETURNTRANSFER => true, | |
CURLOPT_ENCODING => "", | |
CURLOPT_MAXREDIRS => 10, | |
CURLOPT_TIMEOUT => 30, | |
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_POSTFIELDS => http_build_query($data), | |
CURLOPT_HTTPHEADER => array( | |
"cache-control: no-cache", | |
"content-type: application/x-www-form-urlencoded", | |
"postman-token: 5ceff292-29e6-c00a-6fb5-893f60944dab" | |
), | |
)); | |
$response = curl_exec($curl); | |
$err = curl_error($curl); | |
curl_close($curl); | |
if ($err) { | |
echo "cURL Error #:" . $err; | |
} else { | |
echo $response; | |
} | |
error_log(print_r('GLOBE REPLY RESPONSE:' . $response, true)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment