为什么我的cakePHP函数没有将变量传递给InfoBip短信发送Api?

时间:2016-09-02 10:59:51

标签: php cakephp

我创建了这个cakePHP函数,通过infoBip网关系统发送短信,但似乎没有工作,因为错误代码一直给我空目的地。 to => null 这是他们的documentation link

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'));
}

请参阅附件我发送的变量以及我从网关variable and Error response from gateway

获得的错误响应

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

1 个答案:

答案 0 :(得分:1)

文档说:

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

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

您将$recipient分解为数组$to,因此请尝试"to" => $to[0],