0

I just wanna send a simple request to telegram bot APIs my code is:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.telegram.org/bot332537240:MY_TOKEN/getUpdates",
  CURLOPT_CUSTOMREQUEST => "POST",
));

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

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

returns:

cURL Error #:SSL certificate problem: self signed certificate

I don't want use any ssl. I wont set any webhook for telegram. this is a simple request and I failed to handle this. please help me

reza
  • 1,746
  • 6
  • 16
  • 32

4 Answers4

1

I have the same problem and can be solved by copying file cacert.pem into my server and then insert the path of cacert file into my PHP script. In my case i put file cacert into drive C of my web server and then insert this script into my PHP File:

CURLOPT_CAINFO => "C:\cacert.pem"

So your PHP script should be like this:

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://api.telegram.org/bot332537240:MY_TOKEN/getUpdates",
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_CAINFO => "C:\cacert.pem",
));

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

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

You can download file cacert.pem from:

https://drive.google.com/open?id=1FCLH88MpKNLDXZg3pJUSAZ0BbUbNmBR2

If you still confuse, you can view my complete tutorial video on my youtube:

https://youtu.be/UNERvcCz-Hw

0

telegram webhook only work with ssl. you can simply use cloudflare free ssl. but it's not working for .ir domains. you can get update much more easier.

<?php 

date_default_timezone_set("Europe/Berlin");
define('BOT_TOKEN', 'yourtoken');

define('API_URL', 'https://api.telegram.org/bot'.BOT_TOKEN.'/');
//get update
$content = file_get_contents("php://input");

//json array
$update = json_decode($content, true);
//chatid
$chatID = $update["message"]["chat"]["id"];
?>
reza jafari
  • 1,228
  • 13
  • 14
0

You can use CURLOPT_SSL_VERIFYPEER and set it to false in curl_setopt_array.

CURLOPT_SSL_VERIFYPEER stop cURL from verifying the peer's SSL certificate.

Hope it should help.

  • Could you give a small explanation about what `CURLOPT_SSL_VERIFYPEER` does and how it solves the problem? This would greatly improve the quality of the answer – Shogunivar Apr 11 '17 at 08:50
  • Please add that explanation to your answer by editing it – Shogunivar Apr 11 '17 at 09:51
0

if you want playing with methods and get a overall understanding how telegram bot works,just put the url in browser and see the results.

https://api.telegram.org/bot<token>/METHOD_NAME

for your problem i think you are using really old curl library , get latest cacert file from here and replace it with the old one. if you are using xampp follow this link for more info

Arash
  • 639
  • 2
  • 9
  • 15