drasv0904 2017-04-11 07:57
浏览 128
已采纳

php curl中电报机器人的自签名证书

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

  • 写回答

4条回答 默认 最新

  • doukuang1950 2019-01-29 04:35
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划