Using CodeIgniter cURL to send a push notification via UrbanAirship

And*_*ndy 5 curl codeigniter urbanairship.com

I have an urbanairship account set up to send push notifications to my app. This is all working, but now I'm trying to integrate it with my codeigniter admin site so that push notifications are sent by UA and stored to a database in one step. I'm trying to use the cURL library and following the UA API documentation,(http://urbanairship.com/docs/push.html), but each time I get a 404 error. However if I take the cURL lines out, the data is added to the database fine, (so it is receiving the data correctly from the form).

Here's the function in my controller:

function saveAnnouncement() {

  $this->load->helper('html');
  $this->load->library('session');
  $this->load->helper('json');
  $this->load->library('curl');

  $new_announcement = $this->input->post('announcement_text');

  if($this->session->userdata('logged_in') != true)
  {
      redirect('/admin/login');
  }

  $this->curl->create('https://go.urbanairship.com/api/push/broadcast/');
  $this->curl->http_login('<application key>', '<master secret>');
  $announcement_push = array('aps'=>array('alert'=>$new_announcement, 'sound'=>'default'));
  $announcement_push['encoded_data'] = json_encode($announcement_push);
  $this->curl->post($announcement_push);
  $this->curl->execute();

  $this->load->model('Announcements');
  $this->Announcements->Add($new_announcement);
  redirect('/admin/announcements');
Run Code Online (Sandbox Code Playgroud)

}

I'm new to codeigniter, curl and urbanairship, so as you can imagine this is a bit of a nightmare. Will be grateful for any help available!

Thanks!

Jar*_*zyk 1

您是否将curl 配置设置为信任您尝试连接的站点的ssl 证书?首先尝试这个

 curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false); 
Run Code Online (Sandbox Code Playgroud)

如果它有效——那就是问题所在。然后你应该正确设置你的curl 连接并添加特定的证书。