示例#1
0
function send_task()
{
    require_once '../../../wp-load.php';
    include_once 'MyDataBase.php';
    global $wpdb;
    // Get the secrete code from the database
    // $config_table = new MyDataBase('sms_config');
    // $result = (array)$config_table->get_by(array('conf_type' => 'Secret'))[0];
    // $Secret_Code = $result['conf_value'];
    $Secret_Code = '123456';
    if (isset($_GET['task']) and $_GET['task'] == 'send') {
        $msgs = array();
        $message_table = new MyDataBase('messages');
        // connect to a table that contains messages to be sent
        $Pending_Messages = $result = (array) $message_table->get_by(array('pending' => 1, 'incoming' => 0));
        foreach ($Pending_Messages as $msg) {
            $the_msg = (array) $msg;
            $Current_Time = date("m-d-y G:i:s");
            if (strtotime($the_msg['expire_date']) > $Current_Time) {
                array_push($msgs, ["to" => $the_msg['sent_to'], "message" => $the_msg['message'], "uuid" => $the_msg['message_id']]);
            }
            //delete all pending messages after sending to SMSSync
            $message_table->update(array('pending' => 0), array('message_id' => $the_msg['message_id']));
        }
        // Send JSON response back to SMSsync
        $response = json_encode(["payload" => ["success" => true, "task" => "send", "secret" => $Secret_Code, "messages" => array_values($msgs)]]);
        write_message_to_file($response);
        send_response($response);
    }
}
/**
 * Get status delivery report on sent messages
 *
 */
function get_sms_delivery_report()
{
    if ($_GET['task'] === 'result' and $_GET['secret'] === '123456') {
        $message_results = file_get_contents('php://input');
        write_message_to_file("message " . $message_results . "\n\n");
    }
}