SMS cho khách hàng trên CI

Xin chào các bạn hôm nay mình sẽ hướng dẫn các bạn cách sử dụng sms cho khách hàng

Yêu cầu : Cần 1 điện thoại android ,1 tài khoản https://smsgateway.me/

Các bước sử dụng

Upload file lên trên máy android

Bước 2 up load file smsGatewayV4.php vào mục third_party/sms

<?php

class SmsGateway {

    static $baseUrl = "https://smsgateway.me";

    function __construct($apiKeyAuthorization, $email=null,$password=null) {
        $this->email = $email;
        $this->password = $password;
        $this->authorization = $apiKeyAuthorization;
    }

    function createContact ($name,$number) {
        return $this->makeRequest('/api/v4/contact','POST',['name' => $name, 'phoneNumbers' => $number]);
    }

    function getContact ($id) {
        return $this->makeRequest('/api/v4/contact/'.$id,'GET');
    }

    function getDevice ($id)
    {
        return $this->makeRequest('/api/v4/device/'.$id,'GET');
    }

    function getMessage($id)
    {
        return $this->makeRequest('/api/v4/message/'.$id,'GET');
    }

    function sendMessageToNumber($to, $message, $device, $options=[]) {
        $query = array_merge(['phone_number'=>$to, 'message'=>$message, 'device_id' => $device], $options);
        return $this->makeRequest('/api/v4/message/send','POST',$query);
    }

    function sendManyMessages ($data) {
        $query['data'] = $data;
        return $this->makeRequest('/api/v4/message/send','POST', $query);
    }

    private function makeRequest ($url, $method, $fields=[]) {

        $url = smsGateway::$baseUrl.$url;

        $curl = curl_init();
        curl_setopt_array($curl, array(
            CURLOPT_URL => $url,
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_ENCODING => "",
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 30,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => $method,
            CURLOPT_POSTFIELDS => "[  " . json_encode($fields) . "]",
            CURLOPT_HTTPHEADER => array(
                "authorization: $this->authorization",
                "cache-control: no-cache"
            ),
        ));
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

        $result = curl_exec ($curl);

        $return['response'] = json_decode($result,true);

        if($return['response'] == false)
            $return['response'] = $result;

        $return['status'] = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        curl_close ($curl);

        return $return;
    }
}

?>

thêm dòng : require_once APPPATH.’third_party/sms/smsGatewayV4.php’; vào trong controller :

if ($sale_status =='completed'  &&  $sale_status_old=='pending' )
      {
                            
                            $token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXX';
                            $phone_number = $sdthoai;
                            // thiet bi phone cu
                            //$deviceID = 108808; 
                            $options = [];
                            $message_sms = "LYLYSEXY.COM : Don hang ban dat da duoc gui ban vui long cho 2,3 ngay de nhan hang a .Ho tro : 0838105009 .Cam on quy khach";
                            $deviceID_sms = 113281;
                            $smsGateway = new SmsGateway($token);
                            $result = $smsGateway->sendMessageToNumber($phone_number, $message_sms, $deviceID_sms, $options);
                            $trave= $result["response"][0];
                            $sms_id = $trave ["id"];
                        
      }

Thêm token của bạn vào là ok

Be the first to comment

Leave a Reply

Your email address will not be published.


*