<?php

namespace App\Helpers\Sms;



class SmsIr
{

    private static $Key = "de2093bVA0Tprsx8XhQm6YOATLmylhgUPbvb4R9QxI0DgB7coXOEszWqWMaujJAP";

//    public function __construct()
//    {
//    }

    public static function send($data) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, "https://api.sms.ir/v1/send/verify");
        curl_setopt($ch, CURLOPT_HTTPHEADER, [
            'Content-Type: application/json',
            'x-api-key:' . self::$Key ,
            'Accept: text/plain'
        ]);
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        $res = curl_exec($ch);
        curl_close($ch);
        $res = json_decode($res);
        if ($res['status']) {
            return true;
        }
        return false;
    }

    public static function login($mobile, $randstring){
        $data = (object) [
            "Parameters" => [
                (object) [
                    'name' => 'VERIFY',
                    'value' => $randstring
                ]
            ],
            "Mobile" => $mobile,
            "TemplateId" => "701808"
        ];
        return self::send($data);
    }

}
