首页 > 解决方案 > PHP Curl 请求运行两次

问题描述

不明白出了什么问题。该代码是直接来自服务提供商的代码片段,但它似乎仍然运行了两次。

// Define recipients
$recipients = ['##########'];

$url = "https://gatewayapi.com/rest/mtsms";
$api_token = "******";
$json = [
    'sender' => 'Sende name',
    'message' => 'message here',
    'recipients' => [],
];
foreach ($recipients as $msisdn) {
    $json['recipients'][] = ['msisdn' => $msisdn];
}
// time: 1587715200
print_r($json);


$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch,CURLOPT_USERPWD, $api_token.":");
curl_setopt($ch,CURLOPT_POSTFIELDS, json_encode($json));
curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
print($result);
$json = json_decode($result);
print_r($json->ids);

标签: phpcurlsms-gateway

解决方案


推荐阅读