Push Notification on IOS by tosawat
Jun0
วันนี้เราจะมานำเสนอเกี่ยวกับการส่ง Push Notification ให้กับมือถือที่ใช้ระบบปฏิบัติการ IOS กันนะครับ
$device_token = ’491956db82a4677a610d11e0574ed42efa686c0d3b5a7900b4eec810a2d42c97′;
// Put your private key’s passphrase here:
$is_dev = ServerVar::where(‘name’, ‘is_notification_on_sandbox’)->pluck(‘data’);
if($is_dev){
$passphrase = ‘onebyte’;
$key_path = base_path().’/key/BallroomDev.pem’;
$host = ‘ssl://gateway.sandbox.push.apple.com’;
$port = ’2195′;
}else{
$passphrase = ‘onebyte’;
$key_path = base_path().’/key/BallroomApp.pem’;
$host = ‘ssl://gateway.push.apple.com’;
$port = ’2195′;
}
$ctx = stream_context_create();
stream_context_set_option($ctx, ‘ssl’, ‘local_cert’, $key_path);
stream_context_set_option($ctx, ‘ssl’, ‘passphrase’, $passphrase);
// Open a connection to the APNS server
$fp = stream_socket_client($host.’:’.$port, $err, $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $ctx);
if($fp){
// Encode the payload as JSON
$payload = json_encode(array(
‘aps’ => array(
‘alert’ => ‘This is a book.’
),
‘news_id’ => ’253′,
‘cat_id’ => ’3′
));
// Build the binary notification
$binary = chr(0).pack(‘n’, 32).pack(‘H*’, $device_token).pack(‘n’, strlen($payload)).$payload;
// Send it to the server
fwrite($fp, $binary, strlen($binary));
}
// Close the connection to the server
@socket_close($fp);
@fclose($fp);
(ไทย) มาทำ Interaction Animation Unity กันเถอะ!! by Tony
Jun0
Sorry, this entry is only available in ไทย.