我有这个脚本,我需要使用邮递员发送请求。但是我不知道如何在此脚本中实现它,文档在这里https://bongolive.co.tz/api/docs,但是由于我是初学者,所以我没有从中获得清晰的说明
<?php
//.... replace <api_key> and <secrete_key> with the valid keys obtained from the platform, under profile>authentication information
$api_key='<api_key>';
$secret_key = '<secret_key>';
// The data to send to the API
$postData = array(
'source_addr' => 'INFO',
'encoding'=>0,
'schedule_time' => '',
'message' => 'Hello World',
'recipients' => [array('recipient_id' => '1','dest_addr'=>'255700000001'),array('recipient_id' => '2','dest_addr'=>'255700000011')]
);
//.... Api url
$Url ='https://sms.bongolive.africa/api/v1/send';
// Setup cURL
$ch = curl_init($Url);
error_reporting(E_ALL);
ini_set('display_errors', 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt_array($ch, array(
CURLOPT_POST => TRUE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_HTTPHEADER => array(
'Authorization:Basic ' . base64_encode("$api_key:$secret_key"),
'Content-Type: application/json'
),
CURLOPT_POSTFIELDS => json_encode($postData)
));
// Send the request
$response = curl_exec($ch);
// Check for errors
if($response === FALSE){
echo $response;
die(curl_error($ch));
}
var_dump($response);
答案 0 :(得分:0)
我为您逐步构建了一个示例,请注意关键词quoted
。
对官方api文档的示例引用
https://bongolive.co.tz/api/docs/
关于Sample request data
。
Url
设置为API https://sms.bongolive.africa/api/v1/send
Method
更改为POST
Authorization
设置为Basic Auth
绿色块是{{
和}}
中的变量,表示您的api_key
和secret_key
Header
将Content-Type
设置为application-json
(如果更改了BODY的原始类型,则可能会更改)
而且您可以看到authorization
的标题也在这里
Body
原始数据 JSON
格式