smsgatewayme / client-php

PHP Client for smsgateway.me
26 stars 32 forks source link

Fatal error: Uncaught SMSGatewayMe\Client\ApiException #4

Closed savifon closed 2 years ago

savifon commented 6 years ago

Hello

When trying to run the sample code from readme.md, it gives the following error, even from this token:

Exception when calling CallbackApi->createCallback: API call to https://smsgateway.me/api/v4/callback timed out: a:26:{s:3:"url";s:37:"https://smsgateway.me/api/v4/callback";s:12:"content_type";N;s:9:"http_code";i:0;s:11:"header_size";i:0;s:12:"request_size";i:0;s:8:"filetime";i:-1;s:17:"ssl_verify_result";i:1;s:14:"redirect_count";i:0;s:10:"total_time";d:0.5;s:15:"namelookup_time";d:0.26600000000000001;s:12:"connect_time";d:0.48399999999999999;s:16:"pretransfer_time";d:0;s:11:"size_upload";d:0;s:13:"size_download";d:0;s:14:"speed_download";d:0;s:12:"speed_upload";d:0;s:23:"download_content_length";d:-1;s:21:"upload_content_length";d:-1;s:18:"starttransfer_time";d:0;s:13:"redirect_time";d:0;s:12:"redirect_url";s:0:"";s:10:"primary_ip";s:13:"54.229.39.139";s:8:"certinfo";a:0:{}s:12:"primary_port";i:443;s:8:"local_ip";s:15:"186.202.119.229";s:10:"local_port";i:60781;}

And when you try to send an SMS according to documentation, the following error is displayed:

Fatal error: Uncaught SMSGatewayMe\Client\ApiException: API call to https://smsgateway.me/api/v4/message/send timed out: a:26:{s:3:"url";s:41:"https://smsgateway.me/api/v4/message/send";s:12:"content_type";N;s:9:"http_code";i:0;s:11:"header_size";i:0;s:12:"request_size";i:0;s:8:"filetime";i:-1;s:17:"ssl_verify_result";i:1;s:14:"redirect_count";i:0;s:10:"total_time";d:0.25;s:15:"namelookup_time";d:9.9999999999999995E-7;s:12:"connect_time";d:0.25;s:16:"pretransfer_time";d:0;s:11:"size_upload";d:0;s:13:"size_download";d:0;s:14:"speed_download";d:0;s:12:"speed_upload";d:0;s:23:"download_content_length";d:-1;s:21:"upload_content_length";d:-1;s:18:"starttransfer_time";d:0;s:13:"redirect_time";d:0;s:12:"redirect_url";s:0:"";s:10:"primary_ip";s:13:"54.229.39.139";s:8:"certinfo";a:0:{}s:12:"primary_port";i:443;s:8:"local_ip";s:15:"186.202.119.229";s:10:"local_port";i:60798;} in E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\ApiClient.php:230 Stack trace: #0 E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\Api\MessageApi.php(525) in E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\ApiClient.php on line 230

hicarocastro commented 6 years ago

I have the same problem

sepehrs commented 6 years ago

Hi Can you provide me with the code you are using including the parameters your passing in and i'll try to figure out what the issue is.

savifon commented 6 years ago

I'm using the documentation code, just changing the token and phone number and device id.

<?php

require 'autoload.php';

use SMSGatewayMe\Client\ApiClient;
use SMSGatewayMe\Client\Configuration;
use SMSGatewayMe\Client\Api\MessageApi;
use SMSGatewayMe\Client\Model\SendMessageRequest;

// Configure client
$config = Configuration::getDefaultConfiguration();
$config->setApiKey('Authorization', 'TOKEN');
$apiClient = new ApiClient($config);
$messageClient = new MessageApi($apiClient);

// Sending a SMS Message
$sendMessageRequest1 = new SendMessageRequest([
    'phoneNumber' => 'PHONE NUMBER',
    'message' => 'test1',
    'deviceId' => ID DEVICE
]);
$sendMessageRequest2 = new SendMessageRequest([
    'phoneNumber' => 'PHONE NUMBER',
    'message' => 'test2',
    'deviceId' => ID DEVICE
]);
$sendMessages = $messageClient->sendMessages([
    $sendMessageRequest1,
    $sendMessageRequest2
]);
print_r($sendMessages);
?>

The following error is returned:

Fatal error: Uncaught SMSGatewayMe\Client\ApiException: API call to https://smsgateway.me/api/v4/message/send timed out: a:26:{s:3:"url";s:41:"https://smsgateway.me/api/v4/message/send";s:12:"content_type";N;s:9:"http_code";i:0;s:11:"header_size";i:0;s:12:"request_size";i:0;s:8:"filetime";i:-1;s:17:"ssl_verify_result";i:1;s:14:"redirect_count";i:0;s:10:"total_time";d:0.25;s:15:"namelookup_time";d:9.9999999999999995E-7;s:12:"connect_time";d:0.25;s:16:"pretransfer_time";d:0;s:11:"size_upload";d:0;s:13:"size_download";d:0;s:14:"speed_download";d:0;s:12:"speed_upload";d:0;s:23:"download_content_length";d:-1;s:21:"upload_content_length";d:-1;s:18:"starttransfer_time";d:0;s:13:"redirect_time";d:0;s:12:"redirect_url";s:0:"";s:10:"primary_ip";s:13:"54.229.39.139";s:8:"certinfo";a:0:{}s:12:"primary_port";i:443;s:8:"local_ip";s:15:"186.202.119.229";s:10:"local_port";i:49643;} in E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\ApiClient.php:230 Stack trace: #0 E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\Api\MessageApi.php(525) in E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\ApiClient.php on line 230

And it does not have in the documentation the adjustments that we must make in the previous version to work correctly.

savifon commented 6 years ago

I am running PHP version 7.0.29

sepehrs commented 6 years ago

Hi, So from the error message it seems that you can not connect to the endpoint at all (rather than it being an issue with the server rejecting your request). I'm trying to setup a PHP 7.029 environment now to test it and will get back to you soon.

In the meantime maybe check that your server has no issues making outward connections.

savifon commented 6 years ago

The server accepts external connections, yes. So much so that in the previous version, sending SMS worked normally.

Ludplay commented 6 years ago

Same here. @sepehrs I think we all are using same server as in V3. So, it's probably not a problem on our server. Please, check it out PHP 5.x too.

savifon commented 6 years ago

this @Ludplay code apparently solved my problem!!!

$array_fields['phone_number'] = '+00226497491';
$array_fields['message'] = 'Test';
$array_fields['device_id'] = 00000;

$token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOxxxxxxxxxxxxxxxxxxxxxxx";

$curl = curl_init();

curl_setopt_array($curl, array(
    CURLOPT_URL => "https://smsgateway.me/api/v4/message/send",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_ENCODING => "",
    CURLOPT_MAXREDIRS => 10,
    CURLOPT_TIMEOUT => 30,
    CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
    CURLOPT_CUSTOMREQUEST => "POST",
    CURLOPT_POSTFIELDS => "[  " . json_encode($array_fields) . "]",
    CURLOPT_HTTPHEADER => array(
        "authorization: $token",
        "cache-control: no-cache"
    ),
));
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
    echo "cURL Error #:" . $err;
} else {
    echo $response;
}
Ludplay commented 6 years ago

I've created a class similar to v3. Hope it helps. https://github.com/Ludplay/smsgatewayme-php-endpoint

LuqmanUddin0007 commented 6 years ago

savifon thank U so much............... You pulled me out of trouble guys follow his code

NNygren commented 6 years ago

For those having this error, all you need to do is change ../lib/Configuration.php line 143 from true to false protected $sslVerification = false; // this will fix it

nefibocet commented 6 years ago

Ludplay gracias me ayudo mucho

isolutionpl commented 6 years ago

It's not a good practice to modify vendor files. Instead of changing /lib/Configuration.php add one line of code in your file where are you sending sms:

require 'vendor/autoload.php';

use SMSGatewayMe\Client\ApiClient;
use SMSGatewayMe\Client\Configuration;
use SMSGatewayMe\Client\Api\MessageApi;
use SMSGatewayMe\Client\Model\SendMessageRequest;
$config = Configuration::getDefaultConfiguration();
$config->setSSLVerification(false); // add this line
...
vpetkar2 commented 5 years ago

Thanks a lot Savifon. You saved my very very valuable time.

lekiend commented 5 years ago

Same issue `2019-05-07 19:22:47.377424 [NOTICE] [172.69.54.163:51016] [STDERR] PHP Fatal error: Uncaught SMSGatewayMe\Client\ApiException: [400] Error connecting to the API (https://smsgateway.me/api/v4/message/send) in /var/www/visit/public/dashboard/vendor/smsGateway/lib/ApiClient.php:247 Stack trace:

0 /var/www/visit/public/dashboard/vendor/smsGateway/lib/Api/MessageApi.php(525): SMSGatewayMe\Client\ApiClient->callApi('/message/send', 'POST', Array, '[{"phone_number...', Array, '\SMSGatewayMe\C...')

1 /var/www/visit/public/dashboard/vendor/smsGateway/lib/Api/MessageApi.php(459): SMSGatewayMe\Client\Api\MessageApi->sendMessagesWithHttpInfo(Array)

2 /var/www/visit/public/wp-content/themes/Avada-Child-Theme/functions.php(1300): SMSGatewayMe\Client\Api\MessageApi->sendMessages(Array)`

Any idea ?

Ludplay commented 5 years ago

It seems the server is down. My application does not send messages since 04/05/2019 (last saturday). Sad. I don't know who to appeal to.

alideoliveira commented 4 years ago

thank you @isolutionpl you save my day #4

$config->setSSLVerification(false); // add this line

jayimillena commented 2 years ago

I'm using the documentation code, just changing the token and phone number and device id.

<?php

require 'autoload.php';

use SMSGatewayMe\Client\ApiClient;
use SMSGatewayMe\Client\Configuration;
use SMSGatewayMe\Client\Api\MessageApi;
use SMSGatewayMe\Client\Model\SendMessageRequest;

// Configure client
$config = Configuration::getDefaultConfiguration();
$config->setApiKey('Authorization', 'TOKEN');
$apiClient = new ApiClient($config);
$messageClient = new MessageApi($apiClient);

// Sending a SMS Message
$sendMessageRequest1 = new SendMessageRequest([
    'phoneNumber' => 'PHONE NUMBER',
    'message' => 'test1',
    'deviceId' => ID DEVICE
]);
$sendMessageRequest2 = new SendMessageRequest([
    'phoneNumber' => 'PHONE NUMBER',
    'message' => 'test2',
    'deviceId' => ID DEVICE
]);
$sendMessages = $messageClient->sendMessages([
    $sendMessageRequest1,
    $sendMessageRequest2
]);
print_r($sendMessages);
?>

The following error is returned:

Fatal error: Uncaught SMSGatewayMe\Client\ApiException: API call to https://smsgateway.me/api/v4/message/send timed out: a:26:{s:3:"url";s:41:"https://smsgateway.me/api/v4/message/send";s:12:"content_type";N;s:9:"http_code";i:0;s:11:"header_size";i:0;s:12:"request_size";i:0;s:8:"filetime";i:-1;s:17:"ssl_verify_result";i:1;s:14:"redirect_count";i:0;s:10:"total_time";d:0.25;s:15:"namelookup_time";d:9.9999999999999995E-7;s:12:"connect_time";d:0.25;s:16:"pretransfer_time";d:0;s:11:"size_upload";d:0;s:13:"size_download";d:0;s:14:"speed_download";d:0;s:12:"speed_upload";d:0;s:23:"download_content_length";d:-1;s:21:"upload_content_length";d:-1;s:18:"starttransfer_time";d:0;s:13:"redirect_time";d:0;s:12:"redirect_url";s:0:"";s:10:"primary_ip";s:13:"54.229.39.139";s:8:"certinfo";a:0:{}s:12:"primary_port";i:443;s:8:"local_ip";s:15:"186.202.119.229";s:10:"local_port";i:49643;} in E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\ApiClient.php:230 Stack trace: #0 E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\Api\MessageApi.php(525) in E:\Vhosts\painell.com\httpdocs\testesmssavio\lib\ApiClient.php on line 230

And it does not have in the documentation the adjustments that we must make in the previous version to work correctly.

Thank you @savifon