fork download
  1. <?php
  2.  
  3. $secret = 'a82278f5ac0374d424aa374a1d7478778f4355d3';
  4. $method = 'POST';
  5. $contentType = 'application/json';
  6. $date = date(DateTimeInterface::RFC2822);
  7. $path = '/v2/origin/custom/748a042a-26fb-4016-9a62-7d12e9170790/connect';
  8.  
  9. $url = "https://a...content-available-to-author-only...m.ru" . $path;
  10.  
  11. $body = [
  12. 'account_id' => '0215634f-60a7-4ec2-ae29-6aaf9774b814',
  13. 'title' => 'First chat channel', //Название вашего канала, отображаемое пользователю
  14. 'hook_api_version' => 'v2',
  15. ];
  16. $requestBody = json_encode($body);
  17. $checkSum = md5($requestBody);
  18.  
  19. $str = implode("\n", [
  20. strtoupper($method),
  21. $checkSum,
  22. $contentType,
  23. $date,
  24. $path,
  25. ]);
  26.  
  27. $signature = hash_hmac('sha1', $str, $secret);
  28.  
  29. $headers = [
  30. 'Date' => $date,
  31. 'Content-Type' => $contentType,
  32. 'Content-MD5' => strtolower($checkSum),
  33. 'X-Signature' => strtolower($signature),
  34. ];
  35.  
  36. $curlHeaders = [];
  37. foreach ($headers as $name => $value) {
  38. $curlHeaders[] = $name . ": " . $value;
  39. }
  40.  
  41. echo $method . ' ' . $url . PHP_EOL;
  42. foreach ($curlHeaders as $header) {
  43. echo $header . PHP_EOL;
  44. }
  45. echo PHP_EOL . $requestBody . PHP_EOL;
  46.  
  47. $curl = curl_init();
  48. CURLOPT_URL => $url,
  49. CURLOPT_RETURNTRANSFER => true,
  50. CURLOPT_TIMEOUT => 5,
  51. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  52. CURLOPT_CUSTOMREQUEST => $method,
  53. CURLOPT_POSTFIELDS => $requestBody,
  54. CURLOPT_HTTPHEADER => $curlHeaders,
  55. ]);
  56.  
  57. $response = curl_exec($curl);
  58. $err = curl_error($curl);
  59. $info = curl_getinfo($curl);
  60. curl_close($curl);
  61. if ($err) {
  62. $result = "cURL Error #:" . $err;
  63. } else {
  64. echo "Status: " . $info['http_code'] . PHP_EOL;
  65. echo $response . PHP_EOL;
  66. }
Success #stdin #stdout 0.03s 26308KB
stdin
Standard input is empty
stdout
POST https://a...content-available-to-author-only...m.ru/v2/origin/custom/748a042a-26fb-4016-9a62-7d12e9170790/connect
Date: Tue, 30 Sep 2025 13:35:16 +0000
Content-Type: application/json
Content-MD5: b0516c4768b4527664824d030f729cb5
X-Signature: 3ba55dd00007c28881ad1834ae4db768516f5024

{"account_id":"0215634f-60a7-4ec2-ae29-6aaf9774b814","title":"First chat channel","hook_api_version":"v2"}