我有个问题。我已经在 PHP 中设置了 Twilio 帮助程序库来发送 SMS,并且一切正常。但我需要做点什么,我不知道该怎么做。
这是工作代码:
try {
$errorIds = array(); //user ids array which had broken phones
$count = 0;
foreach($listUsers as $user){
$sms = $service->account->sms_messages->create(
$fromPhone,
$user['phone'], // From user phone array
$message
);
if(!$sms){ //on error push userId in to error array
$count++;
array_push($errorIds, $user['userId']);
} else {
$count=0;
}
if($count>20){ //if 20 errors in row give back errors
$data['results'] = "error";
$data['message'] = "Encountered to many failed messages in row";
$data['error_id_array'] = $errorIds;
$data['error_id'] = $user['userId'];
echo json_encode($data);
}
}
$data['results'] = "success";
$data['message'] = "Your message have been sent successfully";
$data['error_id_array'] = $errorIds;
echo json_encode($data);
} catch (Services_Twilio_RestException $e) {
$data['results'] = "error";
$data['message'] = $e->getMessage();
$data['error_id'] = $user['userId'];
echo json_encode($data);
}
一切正常。问题是当由于电话损坏而发生错误时,通过阵列的循环中断并且发送停止。我需要继续发送,我该怎么做?这是控制器,请求是从 ajax 调用发送的,这就是为什么会有 echo 语句!