first commit
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Onesignal_model extends CI_Model {
|
||||
|
||||
|
||||
public function __constructor() {
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function sendmemberMessage($member_id, $player_id_array, $message, $arrayData) {
|
||||
$ic = 0;
|
||||
$player_id_string = "";
|
||||
// print_r($player_id_array);
|
||||
|
||||
if (is_array($player_id_array) && $message != "" && count($player_id_array) > 0 && is_array($arrayData)) {
|
||||
|
||||
|
||||
foreach ($player_id_array as $pl) {
|
||||
$sprt = "";
|
||||
if ($pl != '') {
|
||||
$player_id_array = array($pl);
|
||||
$result = $this->postOneSignal($player_id_array, $message, $arrayData);
|
||||
var_dump($result);
|
||||
}
|
||||
}
|
||||
// $player_id_array = $stack;
|
||||
// $player_id_array = array("fba1b598-0197-4ae6-b57b-0e19e671904d","1160d56c-d22b-4222-b072-af05be86787c");
|
||||
// echo $player_id_string;
|
||||
// print_r($arrayData);
|
||||
// print_r($player_id_array);
|
||||
// $result = $this->postOneSignal($player_id_array, $message, $arrayData);
|
||||
// var_dump($result);
|
||||
} else {
|
||||
echo "Invalid PLAYER_ID and/or MESSAGE!";
|
||||
}
|
||||
}
|
||||
|
||||
private function postOneSignal($player_id_array, $message, $arrayData) {
|
||||
global $savvyext;
|
||||
$url = $savvyext->cfgReadChar('onesignal.url');
|
||||
$app_id = $savvyext->cfgReadChar('onesignal.app_id');
|
||||
|
||||
$url = "https://onesignal.com/api/v1/notifications";
|
||||
$app_id = "e9a7bb38-0a27-4250-9fb7-9bd7871d7b63";
|
||||
|
||||
$data = [
|
||||
'app_id' => $app_id,
|
||||
'contents' => ['en' => $message],
|
||||
'headings' => ['en' => 'Float Activities'],
|
||||
'subtitle' => ['en' => 'Your account activities message from Float.'],
|
||||
'content_available' => true,
|
||||
'mutable_content' => true,
|
||||
'include_player_ids' => $player_id_array,
|
||||
'data' => $arrayData
|
||||
];
|
||||
$opts = array(
|
||||
'http' => array(
|
||||
'method' => "POST",
|
||||
'header' =>
|
||||
"Content-Type: application/json; charset=utf-8\r\n" .
|
||||
"Accept: application/json\r\n",
|
||||
'content' => json_encode($data)
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
$body = file_get_contents($url, false, $context);
|
||||
error_log($body);
|
||||
$result = json_decode($body, true);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 'subtitle' => ['en' => 'You\'ve got push from Float'],
|
||||
}
|
||||
Reference in New Issue
Block a user