-
Notifications
You must be signed in to change notification settings - Fork 0
/
daftarlogin.php
95 lines (84 loc) · 2.65 KB
/
daftarlogin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
//hello world
require_once('./lib/filemanipulation.php');
require_once('./lib/crypt.php');
require_once('./lib/GCMPushMessage.php');
include('./addr-path.php');
//konfigurasi
// $SIcallbackaddr = "http://red-trigger-44-141737.apse1.nitrousbox.com/SI/terimahash.php";
// $SIcallbackaddr = "http://192.168.2.107/SI/mobileid-SI/terimahash.php";
function cariapp($appid) {
return findline($appid,'./data/app.txt');
}
function daftarpid($appid,$data) {
$pidtrylimit = 100;
$i=0;
$j=0;
while ($i<1 && $j<$pidtrylimit) {
$pid=rand();
$OTP=rand(0,9999);
$filename = $appid.".".$pid;
if (file_exists("./data/pid/".$filename) == 0) {
//echo "Catat sebagai proses baru. PID = $pid".PHP_EOL;
//catat OTP
$data["META"]["OTP"] = $OTP;
$encode = json_encode($data);
//tulis ke file
if (!file_put_contents("./data/pid/".$filename, $encode)) {
echo "kesalahan menyimpan process id";
}
$i++;
$result=1;
}
if ($j>$pidtrylimit-2) {
echo "tidak mendapat PID unik";
$result=0;
}
$j++;
}
return array ($result,$pid,$OTP);
}
function kirimGCM ($data, $AppID, $PID, $OTP,$SIcallbackaddr) {
//mengirim pesan ke device (Pesan + AppID + PID + OTP)
$devices = $data["META"]["DeviceID"];
$message = $data["META"]["Message"];
$gcpm = new GCMPushMessage($devices);
$gcpm->fillDataIDverify($message,$AppID, $PID, $OTP,$SIcallbackaddr);
$response = $gcpm->sendGoogleCloudMessage();
//echo "Response:".$response."\n";
}
function response($IDNumber,$pid) {
$response['STATUS'] = array(
'Success' => TRUE,
'NIK' => $IDNumber,
'PID' => $pid,
);
return json_encode($response);
}
//reveice post message
//var_dump($_POST);
$data = json_decode(file_get_contents('php://input'), true);
$AppID = $data["META"]["AppID"];
$IDNumber = $data["KTP"]["NIK"];
//cek META field, apakah data lengkap
//process message
if (cariapp($AppID) >= 0) {
$encode = json_encode($data['KTP']);
$encode = preg_replace('/\s+/', '', $encode);
$data["META"]["signature"] = hitunghashdata($encode);
$daftar = daftarpid($AppID,$data);
if ($daftar[0] == 1) {
//mengirim pesan ke device (Pesan + AppID + PID + OTP + CallbackAddr)
kirimGCM($data,$AppID,$daftar[1],$daftar[2],$SIcallbackaddr);
//tampilkan response
header('Content-type: application/json');
echo response($IDNumber,$daftar[1]);
}
else {
echo "daftar[0] ngga 1";
}
}
else {
echo "App ID tidak terdaftar";
}
?>