public function SendPushIOS($token,$title,$message){
$rs=false;
$notification_payload = [
"aps" => [
"alert" => [
//"title" => "Зарядись!",
"body" => $message,
// "action-loc-key" => "PLAY"
],
"badge" => 0,
"sound" => "bingbong.aiff"
]
];
$token_key = $this->server_key_ios;
//echo "!! token_id IOS: $this->server_token_id_ios\n";
$jwt_header = [
'alg' => 'ES256',
'kid' => $this->server_token_id_ios
];
//echo "!!team_id:$this->server_team_id_ios\n";
$jwt_payload = [
'iss' => $this->server_team_id_ios,
'iat' => time()
];
$raw_token_data = self::b64($jwt_header, true).".".self::b64($jwt_payload, true);
$signature = '';
openssl_sign($raw_token_data, $signature, $token_key, 'SHA256');
$jwt = $raw_token_data.".".self::b64($signature);
// send push
$request_body = json_encode($notification_payload);
$endpoint = 'https://api.push.apple.com/3/device';
$url = "$endpoint/$token";
$ch = curl_init($url);
//echo "!!server_bandle_id_ios:$this->server_bandle_id_ios\n";
curl_setopt_array($ch, [
CURLOPT_POSTFIELDS => $request_body,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2_0,
CURLOPT_HTTPHEADER => [
"content-type: application/json",
"authorization: bearer $jwt",
"apns-topic: $this->server_bandle_id_ios"
]
]);
$result_curl=curl_exec($ch);
$result = json_decode($result_curl);
if (is_null($result)) {
$log= new TLog($this->api);
$log->InsertLogBoiler([
"source_id"=> TLog::S_Messages,
"comment"=>"Ошибка отправки PUSH IOS",
"raw_package"=>curl_error($ch).$result_curl,
"reason"=> TLog::R_Error
]);
} else {
if ((int)$result>0){
//if ($result->success>0){
$rs=true;
};
};
curl_close($ch);
return $rs;
}
public function b64($raw, $json=false){
if($json) $raw = json_encode($raw);
return str_replace('=', '', strtr(base64_encode($raw), '+/', '-_'));
}