【发布时间】:2020-06-17 18:38:29
【问题描述】:
我有这个脚本,我需要使用邮递员来发送请求。但我不知道如何在这个脚本中实现它,文档在这里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);
【问题讨论】:
-
我很抱歉,但我并没有真正得到这个问题。您需要 Postman 做什么?您的代码有什么问题?它有效吗?你有错误吗?请阅读How to create a Minimal, Reproducible Example 和How do I ask a good question 并相应地编辑您的问题。