<?php

use Illuminate\Support\Facades\DB;
use Melipayamak\MelipayamakApi;

function sendsms($phone, $code, $name)
{

    // $url = 'https://console.melipayamak.com/api/send/simple/f1f64d955e624d4486a180c50a29141b';
    // $data = array('from' => '50002710029914', 'to' => $phone, 'text' => 'کد ورود به سامانه فیش حقوقی : ' . $code);
    // $data_string = json_encode($data);
    // $ch = curl_init($url);
    // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
    // curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

    // // Next line makes the request absolute insecure
    // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // // Use it when you have trouble installing local issuer certificate
    // // See https://stackoverflow.com/a/31830614/1743997

    // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // curl_setopt(
    //     $ch,
    //     CURLOPT_HTTPHEADER,
    //     array(
    //         'Content-Type: application/json',
    //         'Content-Length: ' . strlen($data_string)
    //     )
    // );
    // $result = curl_exec($ch);
    // curl_close($ch);
    // // to debug
    // // if(curl_errno($ch)){
    // //     echo 'Curl error: ' . curl_error($ch);
    // // }

    //GitHub نمونه کدهای
    $username = '09219029914';
    $password = 'b02baefd-0609-4e47-bc9e-71e52d5dbd41';
    $api = new MelipayamakApi($username, $password);
    $smsSoap = $api->sms('soap');
    $to = $phone;
    $text = [];
    array_push($text, $name, $code);
    $smsSoap->sendByBaseNumber($text, $to, 336545);
}

function getval()
{
    // $url = 'https://console.melipayamak.com/api/receive/credit/f1f64d955e624d4486a180c50a29141b';
    // $ch = curl_init($url);
    // curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");

    // // Next line makes the request absolute insecure
    // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    // // Use it when you have trouble installing local issuer certificate
    // // See https://stackoverflow.com/a/31830614/1743997

    // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    // curl_setopt(
    //     $ch,
    //     CURLOPT_HTTPHEADER,
    //     array(
    //         'Content-Type: application/json',
    //         'Content-Length: 0'
    //     )
    // );
    // $result = curl_exec($ch);
    // curl_close($ch);
    // dd($result);
    // // to debug
    // // if(curl_errno($ch)){
    // //     echo 'Curl error: ' . curl_error($ch);
    // // }


    $username = '09219029914';
    $password = 'b02baefd-0609-4e47-bc9e-71e52d5dbd41';
    $api = new MelipayamakApi($username, $password);
    $sms = $api->sms();
    $a = $sms->getCredit();
    $a = json_decode($a);
    return floor($a->Value);
}


function checkkarkard($sal, $code)
{
    $k = DB::table('karkard')->where('Salandmah', '=', $sal)->where('Code', '=', $code)->get();
    if (count($k) > 0) {
        return true;
    } else {
        return false;
    }
}
