✏️ 正在编辑: Push.php
路径:
/srv/systems_dir/yuppiecred-lidernegocios/library/Core/PushNotification/Push.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_PushNotification_Push { /** * Método criado para notificar no app * @param type $deviceToken * @param type $message */ public function notify($deviceToken = array(), $message = null) { $data = array( 'tokens' => array( $deviceToken ), "profile" => "yuppiecredmobile", 'notification' => array( "message" => $message, 'alert' => 'message', 'title' => $message, 'vibrate' => 1, 'subtitle' => 'Subtitle', 'sound' => 1 ), "badge" => true ); $this->accessApi($data); } /** * Metódo criado para acessar a api via curl. * @param type $data */ public function accessApi($data = array()) { $url = 'https://api.ionic.io/push/notifications'; //token gerado da API Ionic $tokenIonicPush = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzMDI5MGEzOC1iZDdmLTQwOTUtOWIzYS05MDA0N2Y3NzgyYzcifQ.2nVuK9iX8bXoFiVA_AEh74wtftckO3ny1K51CL781d8"; //converte array para json $content = json_encode($data); $ch = curl_init(); $header = array(); $header[] = 'Content-type: application/json'; $header[] = 'Authorization: Bearer ' . $tokenIonicPush; $header[] = "'X-Ionic-Application-Id: 7806967c'"; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $content); curl_setopt($ch, CURLOPT_USERPWD, "Private Api key" . ": 7ba49d8b7361664d433b6f72bb829686f5f4a976369d2cef"); curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //para utilizar o print_r para debugar, usar o curl_getinfo($ch); curl_exec($ch); curl_close($ch); } /** * Prepara a notificação para o corretor * @param type $corretorId * @param type $mensagem * @throws Core_Exception */ public function prepareNotifyCorretor($corretorId = null, $mensagem = null) { return null;//adicionado pois a API do IONIC está desativada. $corretor = new Model_Corretor(); $dadosCorretor = $corretor->exibir($corretorId); if( !$dadosCorretor ){ throw new Core_Exception("Corretor não identificado"); } if( isset($dadosCorretor['id_mobile_token']) && !empty($dadosCorretor['id_mobile_token']) ){ $this->notify($dadosCorretor['id_mobile_token'], $mensagem); } } }
💾 保存文件
← 返回文件管理器