Notification send in codeigniter 4

Admin
1 minute read
0

 
 


 गूगल Farebase से notification सेंड करना बहुत ही आसन है आप ये कोड उपयोग कर सेंड कर सकते है

 

Code Start :

 function notification($id=null) {
/* login check  */
        if (!$this->auth->isLogged()) { redirect('admin'); exit; }

 

        $data['title'] = 'News';

        $result = $this->cms_model->getCmsOne($id);



//The URL of the API.
$url = 'http://api.foxlabz.com/v1/notification/pushToTopic';

//Initiate cURL.
$ch = curl_init($url);

//The JSON data.
$jsonData = array(
    'serverKey' => 'AAAAAAAAKj_Mh80:APA91bFCYe3t6OdM1U7Q921tVGo3cHbel-8Cwt3V1QQk7uoN0-a3qdefBGx5OW_w0a3Jt6qV_aa854b04BWtae0VHO6w_Fx8gMi6QlsMkCibIEga_dxyDf8qdx6jqZVQ-oqO2Gc1d5iYAX',
    'title' => $result['title'],
    'body' => '',
    'image' =>  base_url().'media/news/'.$result['path'],
    'topic' => 'news',
    'accessToken' => ''
);

//Encode the array into JSON.
$jsonDataEncoded = json_encode($jsonData);

//Tell cURL that we want to send a POST request.
curl_setopt($ch, CURLOPT_POST, 1);

//Attach our encoded JSON string to the POST fields.
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonDataEncoded);

//Set the content type to application/json
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));

//Execute the request
curl_exec($ch);

//print_r($result);
//echo 'Send App Notification';


 

        $this->session->set_flashdata('msg', '<div class="alert alert-success text-left">Successfully Sent.</div>');
        //redirect("admin/cms/active");
        
        echo '<br/><br/><br/><a href="https://domainname.online/admin/cms/active"> <center><h1> <= Back </h1></center></a>';

}

 

Code End :



Post a Comment

0 Comments
Post a Comment (0)
Our website uses cookies to fast experience.
Accept !