Skip to content

Commit b3529ac

Browse files
master-websmaster-webs
master-webs
authored and
master-webs
committed
git push
0 parents  commit b3529ac

15 files changed

+1653
-0
lines changed

push/ baza.txt

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
-- phpMyAdmin SQL Dump
2+
-- version 4.0.10.7
3+
-- http://www.phpmyadmin.net
4+
--
5+
-- ����: localhost
6+
-- ����� ��������: ��� 19 2016 �., 03:57
7+
-- ������ �������: 5.5.45-cll-lve
8+
-- ������ PHP: 5.4.31
9+
10+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
11+
SET time_zone = "+00:00";
12+
13+
--
14+
-- ���� ������: `push`
15+
--
16+
17+
-- --------------------------------------------------------
18+
19+
--
20+
-- ��������� ������� `users`
21+
--
22+
23+
CREATE TABLE IF NOT EXISTS `users` (
24+
`id` int(20) NOT NULL AUTO_INCREMENT,
25+
`Token` varchar(200) NOT NULL,
26+
`phone` varchar(255) NOT NULL,
27+
`data` datetime NOT NULL,
28+
`platform` varchar(255) NOT NULL,
29+
`deviceID` varchar(255) NOT NULL,
30+
PRIMARY KEY (`id`),
31+
UNIQUE KEY `Token` (`Token`)
32+
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=5 ;

push/push.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
function send_notification ($tokens, $message)
3+
{
4+
$url = 'https://fcm.googleapis.com/fcm/send';
5+
$fields = array(
6+
'registration_ids' => $tokens,
7+
'priority' =>'high',
8+
'notification' => $message, //для устройств ios
9+
'data' => $message // для устройств android
10+
);
11+
$headers = array(
12+
'Authorization:key = api_key ',
13+
'Content-Type: application/json'
14+
);
15+
$ch = curl_init();
16+
curl_setopt($ch, CURLOPT_URL, $url);
17+
curl_setopt($ch, CURLOPT_POST, true);
18+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
19+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
20+
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
21+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
22+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
23+
$result = curl_exec($ch);
24+
if ($result === FALSE) {
25+
die('Curl failed: ' . curl_error($ch));
26+
}
27+
curl_close($ch);
28+
return $result;
29+
}
30+
$conn = mysqli_connect("localhost","root","","push");
31+
$sql = " Select Token From users";
32+
$result = mysqli_query($conn,$sql);
33+
$tokens = array();
34+
if(mysqli_num_rows($result) > 0 ){
35+
while ($row = mysqli_fetch_assoc($result)) {
36+
$tokens[] = $row["Token"];
37+
}
38+
}
39+
mysqli_close($conn);
40+
$message = array("body" => " Тестовое сообщение",
41+
'title' => 'Заголовок',
42+
'vibrate' => 1,
43+
'sound' => 1);
44+
$message_status = send_notification($tokens, $message);
45+
echo $message_status;
46+
?>

push/register.php

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
function new_token_ios ($tokens)
3+
{
4+
$url = 'https://iid.googleapis.com/iid/v1:batchImport';
5+
$fields =array(
6+
'application'=>'package_name',
7+
'sandbox'=>false,
8+
'apns_tokens' =>array($tokens)
9+
);
10+
$headers = array(
11+
'Authorization:key = api_key',
12+
'Content-Type: application/json'
13+
);
14+
$ch = curl_init();
15+
curl_setopt($ch, CURLOPT_URL, $url);
16+
curl_setopt($ch, CURLOPT_POST, true);
17+
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
18+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
19+
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
20+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
21+
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
22+
$result = curl_exec($ch);
23+
if ($result === FALSE) {
24+
die('Curl failed: ' . curl_error($ch));
25+
}
26+
curl_close($ch);
27+
$res=json_decode($result, TRUE);
28+
return $res['results'][0]['registration_token'];
29+
30+
}
31+
32+
if (isset($_POST["token"])) {
33+
34+
$_uv_Token=$_POST["token"];
35+
$push_key=$_POST["push_key"];
36+
$platform=$_POST["platform"];
37+
$data=date("Y-m-d H:i:s");
38+
$deviceid=$_POST["deviceid"];
39+
if ($_POST["platform"]=='ios'){ // есть устройство IOS получаем новый токен FCM
40+
$_uv_Token= new_token_ios($_uv_Token);
41+
}
42+
$conn = mysqli_connect("localhost","root","","push") or die("Error connecting");
43+
$q="INSERT INTO users (deviceID, Token, phone, data, platform) VALUES ('$deviceid', '$_uv_Token','$push_key','$data','$platform' ) "
44+
." ON DUPLICATE KEY UPDATE deviceID ='$deviceid' ,Token = '$_uv_Token',phone = '$push_key',data = '$data',platform = '$platform';";
45+
46+
mysqli_query($conn,$q) or die(mysqli_error($conn));
47+
mysqli_close($conn);
48+
}
49+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<%getTaskAllowKey%>
6+
<%applicationIdentifier%>
7+
<%pushNotificationKey%>
8+
<%keychainAccessGroups%>
9+
</dict>
10+
</plist>

push_exemple_delphi/Unit2.fmx

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
object Form2: TForm2
2+
Left = 0
3+
Top = 0
4+
Caption = 'Form2'
5+
ClientHeight = 480
6+
ClientWidth = 612
7+
FormFactor.Width = 320
8+
FormFactor.Height = 480
9+
FormFactor.Devices = [Desktop]
10+
DesignerMasterStyle = 0
11+
object ToolBar1: TToolBar
12+
Size.Width = 612.000000000000000000
13+
Size.Height = 40.000000000000000000
14+
Size.PlatformDefault = False
15+
TabOrder = 0
16+
object Button1: TButton
17+
Align = Right
18+
Position.X = 532.000000000000000000
19+
Size.Width = 80.000000000000000000
20+
Size.Height = 40.000000000000000000
21+
Size.PlatformDefault = False
22+
TabOrder = 0
23+
Text = 'GCM'
24+
OnClick = Button1Click
25+
end
26+
object Edit1: TEdit
27+
Touch.InteractiveGestures = [LongTap, DoubleTap]
28+
Align = Client
29+
TabOrder = 1
30+
KeyboardType = PhonePad
31+
Margins.Left = 2.000000000000000000
32+
Margins.Top = 2.000000000000000000
33+
Margins.Right = 2.000000000000000000
34+
Margins.Bottom = 2.000000000000000000
35+
Size.Width = 463.000000000000000000
36+
Size.Height = 36.000000000000000000
37+
Size.PlatformDefault = False
38+
end
39+
object Label1: TLabel
40+
Align = Left
41+
Size.Width = 65.000000000000000000
42+
Size.Height = 40.000000000000000000
43+
Size.PlatformDefault = False
44+
StyleLookup = 'toollabel'
45+
Text = 'Phone'
46+
end
47+
end
48+
object Memo1: TMemo
49+
Touch.InteractiveGestures = [Pan, LongTap, DoubleTap]
50+
DataDetectorTypes = []
51+
TextSettings.WordWrap = True
52+
Align = Client
53+
Size.Width = 612.000000000000000000
54+
Size.Height = 440.000000000000000000
55+
Size.PlatformDefault = False
56+
TabOrder = 1
57+
Viewport.Width = 608.000000000000000000
58+
Viewport.Height = 436.000000000000000000
59+
end
60+
end

push_exemple_delphi/Unit2.pas

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
unit Unit2;
2+
3+
interface
4+
5+
uses
6+
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
7+
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
8+
FMX.ScrollBox, FMX.Memo, FMX.Controls.Presentation,
9+
System.PushNotification, FMX.Edit
10+
{$IFDEF ANDROID},fmx.PushNotification.android {$ENDIF}{$IFDEF IOS},FMX.PushNotification.iOS{$ENDIF};
11+
12+
type
13+
TForm2 = class(TForm)
14+
ToolBar1: TToolBar;
15+
Memo1: TMemo;
16+
Button1: TButton;
17+
Edit1: TEdit;
18+
Label1: TLabel;
19+
procedure OnReceiveNotificationEvent(Sender: TObject; const ANotification : TPushServiceNotification);
20+
procedure OnServiceConnectionChange(Sender: TObject; AChange : TPushService.TChanges);
21+
procedure Button1Click(Sender: TObject);
22+
private
23+
{ Private declarations }
24+
public
25+
{ Public declarations }
26+
APushService : TPushService;
27+
AServiceConnection : TPushServiceConnection;
28+
end;
29+
30+
var
31+
Form2: TForm2;
32+
33+
implementation
34+
uses global;
35+
{$R *.fmx}
36+
procedure TForm2.Button1Click(Sender: TObject);
37+
var
38+
ADeviceID, AdeviceToken, push_key: String;
39+
begin
40+
{$IFDEF ANDROID}
41+
// Äëÿ Android
42+
APushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.GCM);
43+
APushService.AppProps[TPushService.TAppPropNames.GCMAppID] := 'FCM ID';
44+
45+
{$ENDIF}{$IFDEF IOS}
46+
// Äëÿ iOS
47+
APushService := TPushServiceManager.Instance.GetServiceByName(TPushService.TServiceNames.APS);
48+
{$ENDIF}
49+
50+
AServiceConnection := TPushServiceConnection.Create(APushService);
51+
AServiceConnection.Active := True;
52+
AServiceConnection.OnChange := OnServiceConnectionChange;
53+
AServiceConnection.OnReceiveNotification := OnReceiveNotificationEvent;
54+
55+
ADeviceID := APushService.DeviceIDValue[TPushService.TDeviceIDNames.DeviceID];
56+
AdeviceToken := APushService.DeviceTokenValue[TPushService.TDeviceTokenNames.DeviceToken];
57+
push_key:=Edit1.Text;
58+
Memo1.Lines.Add('ADeviceID: '+ADeviceID);
59+
Memo1.Lines.Add('AdeviceToken: '+AdeviceToken);
60+
Memo1.Lines.Add('push_key: '+push_key);
61+
if (ADeviceID <> '') AND (ADeviceToken <> '') then
62+
begin
63+
RegisterDevice(ADeviceID, ADeviceToken, push_key);
64+
end;
65+
66+
end;
67+
/// Óñòðîéñòâà íå âñåãäà óñïåâàþò ïîëó÷èòü òîêåí,
68+
/// ïîýòîìó ïðè èçìåíåíèè ñîñòîÿíèÿ îïÿòü ïðîâåðÿåì òîêåí
69+
procedure TForm2.OnServiceConnectionChange(Sender: TObject;
70+
AChange : TPushService.TChanges);
71+
var
72+
ADeviceID, AdeviceToken, push_key: String;
73+
begin
74+
// Ïðè èçìåíèè ñîñòîÿíèÿ êîìïîíåíòà
75+
ADeviceID := APushService.DeviceIDValue[TPushService.TDeviceIDNames.DeviceID];
76+
AdeviceToken := APushService.DeviceTokenValue[TPushService.TDeviceTokenNames.DeviceToken];
77+
push_key:=Edit1.Text;
78+
79+
if (ADeviceID <> '') AND (ADeviceToken <> '') then
80+
begin
81+
RegisterDevice(ADeviceID, ADeviceToken, push_key);
82+
end;
83+
end;
84+
/// Ïðîöåäóðà âûâîäà ñîîáùåíèå ïðè ïîëó÷åíèè Push óâåäîìëåíèÿ îò ñåðâåðà
85+
procedure TForm2.OnReceiveNotificationEvent(Sender: TObject;
86+
const ANotification : TPushServiceNotification);
87+
var
88+
MessageText : string;
89+
begin
90+
// Ïîëó÷àåì òåêñò ñîîáùåíèÿ â çàâèñèìîñòè ëü ïëàòôîðìû
91+
{$ifdef ANDROID}
92+
MessageText := ANotification.DataObject.GetValue('message').Value;
93+
{$else}
94+
MessageText := ANotification.DataObject.GetValue('alert').Value;
95+
{$endif};
96+
97+
// Âûâîäèì ñîîáùåíèå
98+
ShowNotification(MessageText, 0);
99+
end;
100+
end.

0 commit comments

Comments
 (0)