0

我创建了这个 cakePHP 函数来通过 infoBip 网关系统发送 SMS,但它似乎无法正常工作,因为错误代码一直给我空目的地。to=>null这是他们的文档链接

public function sendSMS($recipient, $sender, $message) {
   $url = 'https://api.infobip.com/sms/1/text/single';
    $to = explode(',', $recipient);
    $data = ["to" => $to, "from" => $sender, "text" => $message];
    $postData = array("messages" => array($data)); //message to send to gateway
    // encoding object
    $postDataJson = json_encode($postData);
            $request = array('header' => array(
            'accept' => 'application/json',
            'content-type' => 'application/json',
            'authorization' => 'Basic #################'
    ));
    $response = $this->cakeSocket($url, $postDataJson, $request);
     pr($postDataJson);
   ($response->body());
    return $response->body();
    //$this->redirect(array('action' => 'index'));
}

见附件我发送的变量和我从网关得到的错误响应来自网关的变量和错误响应

请告知我做错了什么,因为系统没有收到我的变量。谢谢。学习使用 CakePHP。

4

1 回答 1

1

文档说:

{  
   "from":"InfoSMS",
   "to":"41793026727",
   "text":"My first Infobip SMS"
}

你发送数组"to":["41793026727"]

你爆炸$recipient成数组$to,所以试试"to" => $to[0],

于 2016-09-02T12:45:24.017 回答