forked from rifkichaplin/php-chatbot-jabber-transaksi-pulsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
acceptmessage.php
168 lines (137 loc) · 7.99 KB
/
acceptmessage.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
<?php
// activate full error reporting
error_reporting(E_ALL & E_STRICT);
include 'connvoulec.php';
#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
#If this doesn't work, are you running 64-bit PHP with < 5.2.6?
$conn->autoSubscribe();
$vcard_request = array();
try {
//$conn->connect();
if(!$conn->isDisconnected()){
$conn->connect();
echo "Ada Koneksi..\n";
}
while(!$conn->isDisconnected()) {
$payloads = $conn->processUntil(array('message', 'presence', 'end_stream', 'session_start', 'vcard'));
foreach($payloads as $event) {
$pl = $event[1];
$query_cek_trx="select count(*) jmltrx from (select id_transaction, kind from transaction_multiple_req where request_date between subdate(current_date, 1) and subdate(current_date, 0) and status = 8 union all select id_transaction, kind from transaction_multiple_cron where request_date between subdate(current_date, 1) and subdate(current_date, 0) and status = 8 union all select id_transaction, kind from transaction_single where request_date between subdate(current_date, 1) and subdate(current_date, 0) and status = 8) A";
echo "CEK PROSES JOB ANTRIAN\n";
$result_cek = mysqli_query($connect_db, $query_cek_trx);
while($row_c = mysqli_fetch_assoc($result_cek)) {
$idjmltrx=$row_c["jmltrx"];
if($idjmltrx <= "30"){
$query_getdata = "select * from (select id_transaction id, concat(kind,id_transaction) id_transaction, request_date, msisdn, product_code_trx, kind, 'transaction_multiple_req' nm_table from transaction_multiple_req where request_date between subdate(current_date, 1) and subdate(current_date, 0) and status in (4,10) and msisdn not in (select msisdn from transaction_multiple_req where status = 8) union select id_transaction id, concat(kind,id_transaction) id_transaction, request_date, msisdn, product_code_trx, kind, 'transaction_multiple_cron' nm_table from transaction_multiple_cron where request_date between subdate(current_date, 1) and subdate(current_date, 0) and status in (4,10) and msisdn not in (select msisdn from transaction_multiple_cron where status = 8) union select id_transaction id,concat(kind,id_transaction) id_transaction, request_date, msisdn,product_code_trx, kind, 'transaction_single' nm_table from transaction_single where request_date between subdate(current_date, 1) and subdate(current_date, 0) and status in (4,10) and msisdn not in (select msisdn from transaction_single where status = 8) ) A where substr(now(),12,2) not in ('00','01','02','03','04','05') order by id asc limit 1 ";
echo $query_getdata."\n";
$result_q = mysqli_query($connect_db, $query_getdata);
if (mysqli_num_rows($result_q) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result_q)) {
$id_trx=$row["id"];
$id_transaction=$row["id_transaction"];
$request_date=$row["request_date"];
$msisdn=$row["msisdn"];
$product_code_trx=$row["product_code_trx"];
$kind=$row["kind"];
$nm_table=$row["nm_table"];
$query_ven="select A.product_code_trx, A.id_product_vendor, B.product_code, A.denom, A.operator, B.purchase_price, B.selling_price, C.id_ym, C.pin,C.dbl_code_trx,B.id_vendor,C.posisi_dbl,C.vendor_name from product_trx A left join product_vendor B on A.id_product_vendor = B.id_product_vendor left join vendor C on B.id_vendor = C.id_vendor where A.product_code_trx = '".$product_code_trx."' limit 1";
echo $query_ven."\n";
$result_v = mysqli_query($connect_db, $query_ven);
while($row_v = mysqli_fetch_assoc($result_v)) {
$product_code_trx_v=$row_v["product_code_trx"];
$id_product_vendor=$row_v["id_product_vendor"];
$product_code=$row_v["product_code"];
$denom=$row_v["denom"];
$id_ym=$row_v["id_ym"];
$pin=$row_v["pin"];
$operator=$row_v["operator"];
$id_vendor=$row_v["id_vendor"];
if($id_vendor == "1" || $operator == "AS" || $operator == "Simpati"){
$conn->message($id_ym, $body="SV".$denom.".".$msisdn.".".$pin , $type="chat");
$msgout="SV".$denom.".".$msisdn.".".$pin;
echo "KIRIM dengan Format:SV".$denom.".".$msisdn.".".$pin;
}else{
$conn->message($id_ym, $body=$product_code.".".$msisdn.".".$pin , $type="chat");
$msgout=$product_code.".".$msisdn.".".$pin;
echo "KIRIM dengan Format:".$product_code.".".$msisdn.".".$pin;
}
$t=time();
$query_ins_ym_out = 'INSERT INTO ym_out (id_ym,format_out,id_transaction,last_update) VALUES ("'.$id_ym.'","'.$msgout.'","'.$id_transaction.'","'.date('Y-m-d H:i:s',$t).'")';
mysqli_query($connect_db,$query_ins_ym_out);
$query_upd='UPDATE '.$nm_table.' set status = 17 where id_transaction ='.$id_trx;
mysqli_query($connect_db,$query_upd);
}
}
} else {
echo "0 results| Tidak ada Transaksi saat ini..\n";
}
}
}
sleep (5);
//$conn->close();
//tahan session agar aktif terus
$conn->message("[email protected]", $body=date('Y-m-d H:i:s',$t)."|RifkiChaplin Check.." , $type="chat");
switch($event[0]) {
case 'message':
$t=time();
$query_ins = 'INSERT INTO ym_in (id_ym,format_in,last_update,status) VALUES ("'.$pl['from'].'","'.$pl['body'].'","'.date('Y-m-d H:i:s',$t).'",0)';
if(!empty($pl['body']) && $pl['from'] != "[email protected]/xmpphp" ){
mysqli_query($connect_db,$query_ins);
}
print "---------------------------------------------------------------------------------\n";
print "Message from: {$pl['from']}\n";
if($pl['subject']) print "Subject: {$pl['subject']}\n";
print $pl['body'] . "\n";
print "---------------------------------------------------------------------------------\n";
//$conn->message($pl['from'], $body="Thanks for sending me \"{$pl['body']}\".", $type=$pl['type']);
//$conn->message($pl['from'], $body="DEP.1234" , $type=$pl['type']);
$cmd = explode(' ', $pl['body']);
//if($cmd[0] == 'quit') $conn->disconnect();
if($cmd[0] == 'break') $conn->send("</end>");
if($cmd[0] == 'vcard') {
if(!($cmd[1])) $cmd[1] = $conn->user . '@' . $conn->server;
// take a note which user requested which vcard
$vcard_request[$pl['from']] = $cmd[1];
// request the vcard
$conn->getVCard($cmd[1]);
}
break;
case 'presence':
print "Presence: {$pl['from']} [{$pl['show']}] {$pl['status']}\n";
break;
case 'session_start':
print "Session Start\n";
$conn->getRoster();
$conn->presence($status="I'm Machine made by RifkiChaplin");
break;
case 'vcard':
// check to see who requested this vcard
$deliver = array_keys($vcard_request, $pl['from']);
// work through the array to generate a message
print_r($pl);
$msg = '';
foreach($pl as $key => $item) {
$msg .= "$key: ";
if(is_array($item)) {
$msg .= "\n";
foreach($item as $subkey => $subitem) {
$msg .= " $subkey: $subitem\n";
}
} else {
$msg .= "$item\n";
}
}
// deliver the vcard msg to everyone that requested that vcard
foreach($deliver as $sendjid) {
// remove the note on requests as we send out the message
unset($vcard_request[$sendjid]);
$conn->message($sendjid, $msg, 'chat');
}
break;
}
}
}
} catch(XMPPHP_Exception $e) {
die($e->getMessage());
}