我创建了这个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'));
}
获得的错误响应
由于系统没有接收我的变量,请告知我做错了什么。谢谢。学习使用CakePHP。
答案 0 :(得分:1)
文档说:
{
"from":"InfoSMS",
"to":"41793026727",
"text":"My first Infobip SMS"
}
并发送数组"to":["41793026727"]
您将$recipient
分解为数组$to
,因此请尝试"to" => $to[0],