Repository navigation
Expand file tree
/
Copy pathbipHandler.php
More file actions
executable file
·374 lines (284 loc) · 12.7 KB
/
Copy pathbipHandler.php
File metadata and controls
executable file
·374 lines (284 loc) · 12.7 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
<?php
error_reporting(E_ALL);
//header('Content-Type: application/json');
ini_set('display_errors', 1);
require("funcs/dbFunctions.php");
date_default_timezone_set('Europe/Istanbul');
if(strcasecmp($_SERVER['REQUEST_METHOD'], 'POST') != 0){
throw new Exception('Request method must be POST!');
}
//Make sure that the content type of the POST request has been set to application/json
$contentType = isset($_SERVER["CONTENT_TYPE"]) ? trim($_SERVER["CONTENT_TYPE"]) : '';
if(strcasecmp($contentType, 'application/json') != 0){
throw new Exception('Content type must be: application/json');
}
//Receive the RAW post data.
$contentFromBip = trim(file_get_contents("php://input"));
//Attempt to decode the incoming RAW post data from JSON.
$decoded = json_decode($contentFromBip, true);
//print_r($decoded);
foreach ($decoded as $key => $val) {
//print "$key = $val\n";
if ($key=="content"){
$keyword=$val;
}
if ($key=="msgid"){
$msgId=$val;
}
if ($key=="sender"){
$sender=$val;
}
if ($key=="sendtime"){
$sendtime=$val;
}
}
echo "\nkeyword is: ".$keyword;
echo "\nmsgId is: ".$msgId;
echo "\nsender is: ".$sender;
echo "\nsendtime id is: ".$sendtime;
$file="appony.log";
$log=date("Y-m-d h:i:sa")." - REQUEST - sender: ".$sender." keyword: ".$keyword." - msgid:".$msgId.PHP_EOL;
file_put_contents($file, $log, FILE_APPEND | LOCK_EX);
$bul = array('ç', 'ğ', 'ş', 'ö', 'ü','ı');
$degistir = array('c', 'g', 's', 'o', 'u','i');
$keyword = str_replace($bul, $degistir, $keyword);
//If json_decode failed, the JSON is invalid.
if(!is_array($decoded)){
throw new Exception('Received content contained invalid JSON!');
}
//$applist[]='yardim';
$applist[]='rbt';
$applist[]='lifebox';
$applist[]='RBT';
$applist[]='dergilik';
$applist[]='gnc';
$applist[]='fizy';
$applist[]='hesabim';
$applist[]='bip';
$applist[]='akademi';
$applist[]='spotify';
$applist[]='resmiislerim';
$applist[]='tty';
$applist[]='whatsapp';
$applist[]='dropbox';
$applist[]='dmags';
$applist[]='upcall';
$applist[]='platinum';
$applist[]='akademi';
$applist[]='yanimda';
$applist[]='turkcelltv';
$keyword=strtolower($keyword);
$keywords=explode(" ",$keyword);
$keywordLT=$keywords[0];
$keywordRT=$keywords[1];
$appControl=in_array($keywordLT,$applist);
$wordCount=str_word_count($keyword);
echo "\nkeyword word count: ".$wordCount;
echo "\nkeywordLT: ".$keywordLT;
echo "\nkeywordRT: ".$keywordRT;
echo "\napp control result 0/1: ".$appControl;
$appCresult=" CR: ";
//if ($appControl=0) {$appCresult="istek servis ismi icermiyor";}
echo "\nAppcontrol array printR: ";
print_r($appControl)." ".$appCresult;
print_r($applist);
echo "\napplist: ";
print_r($applist);
$receiver=$sender;
//content hazirla baslar
if (isset($keywordRT) and $appControl==1) {
echo "youm filter is activated keywordRT: ".$keywordRT;
if ($keywordRT=="yorum") {
$content="son 5 yorum gelecek";
$servername='46.101.113.44';
$username='appony';
$password='appony1020';
$dbname='appony';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "select appid from appony.app_list a WHERE a.appname='".$keywordLT."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$appIosID=$row["appid"];
echo "\napp ios id from db:".$appIosID;
}
$fizyUrl='https://itunes.apple.com/tr/rss/customerreviews/id='.$appIosID.'/sortBy=mostRecent/json';
$fizyGet = file_get_contents($fizyUrl);
$fizyJson=json_decode($fizyGet);
echo "\nApp comment get url: ".$fizyUrl;
$bul = array('ç', 'ı', 'ğ', 'ş', 'ö', 'ü');
$degistir = array('c', 'i', 'g', 's', 'o', 'u');
$y=6;
for ($x = 5; $x >=1 ; $x--) {
$y=$y-1;
$commentid=$fizyJson->feed->entry[$x]->id->label;
$author=$fizyJson->feed->entry[$x]->author->name->label;
$comment=$fizyJson->feed->entry[$x]->content->label;
$comment = str_replace($bul, $degistir, $comment);
$title=$fizyJson->feed->entry[$x]->title->label;
$ratingPlaceholder='im:rating';
$rating=$fizyJson->feed->entry[$x]->$ratingPlaceholder->label;
$versionPlaceholder='im:version';
$version=$fizyJson->feed->entry[$x]->$versionPlaceholder->label;
$content=$keywordLT." yorum ".$y;
$content=$content."\nkullanıcı adi: ".$author;
$content=$content."\npuani: ".$rating;
$content=$content."\nsurum: ".$version;
$content=$content."\nbaslik: ".$title;
$content=$content."\nYorum: ".$comment;
echo "\ncontent with reviews: ".$content;
$postResult=sendBipResponse($receiver,$content);
}
}
//getBipReviews($keywordLT);
} else if ($keywordRT=="son") {
$content="son 5 yorum gelecek";
$servername='46.101.113.44';
$username='appony';
$password='appony1020';
$dbname='appony';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "select appid from appony.app_list a WHERE a.appname='".$keywordLT."'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$appIosID=$row["appid"];
echo "\napp ios id from db:".$appIosID;
}
$bipURL='http://itunes.apple.com/lookup?id='.$appIosID.'&country=tr';
$bipGet= file_get_contents($bipURL);
$bipJson= json_decode($bipGet);
$releaseDate=$bipJson->results[0]->currentVersionReleaseDate;
$bipRating=$bipJson->results[0]->averageUserRatingForCurrentVersion;
$bipRaterNum=$bipJson->results[0]->userRatingCountForCurrentVersion;
$currentVersion=$bipJson->results[0]->version;
$releaseDate=substr($releaseDate, 0, 10);
echo "\nApp comment get url: ".$bipURL;
echo "\nApp comment release date: ".$releaseDate;
echo "\nApp comment rating: ".$bipRating;
echo "\nApp comment releasedata: ".$bipRaterNum;
$bul = array('ç', 'ı', 'ğ', 'ş', 'ö', 'ü');
$degistir = array('c', 'i', 'g', 's', 'o', 'u');
$content=$keywordLT." App Store guncel versiyon: ".$currentVersion;
$content=$content."\nlansman tarihi: ".$releaseDate;
$content=$content."\npuani: ".$bipRating;
$content=$content."\npuanlayan kullanici sayisi: ".$bipRaterNum;
echo "content for current version: ".$content;
$postResult=sendBipResponse($receiver,$content);
}
//getBipReviews($keywordLT);
} else {$content="Hatali istek girdin. Sorgulayabilecegin sihirli kelimeleri ogrenmek icin yardim yazip gonderebilirsin.";
$postResult=sendBipResponse($receiver,$content);
echo "\nYorum hata content is: ".$content;
}
}
else {
if ($keyword=="yardim") {
$content="\nStore puanlarini ogrenmek icin servisin ismini yaz gonder.\nOrnek: fizy \n\nApp store'da yayinlanan son versiyona ait bilgilere ulasmak icin servis ismi bosluk son yaz gonder\nOrnek: lifebox son \n\nApp store son 5 yoruma ulasmak icin servis ismi bosluk yorum yaz gonder.\nOrnek: bip yorum\n\nTüm servislerin puanini gorebilmek için hepsi yaz gonder. Sıralı almak için hepsi ios yada hepsi android yaz gonder.\nÖrnek: hepsi ios \n\nSorgulayabilecegin servisleri ogrenmek icin liste yaz gonder.\nOrnek: liste\n\nhttp://appony.ga";
$postResult=sendBipResponse($receiver,$content);
echo "\nyardim content is: ".$content;
} elseif ($keyword=="yorum") {
$content="Servis ismi bosluk yorum yazarak istedigin servise ait son 5 app store yorumuna ulasabilirsin. Ornek: fizy yorum \n\nSorgulayabilecegin servisler:\nfizy\nlifebox\nbip\nhesabim\ndergilik\nRBT\nupcall\nplatinum\ntty\ngnc\nakademi\nyanimda\nspotify\nwhatsapp\ndmags\nresmiislerim";
$postResult=sendBipResponse($receiver,$content);
echo "\nyorum content is: ".$content;
} elseif ($keyword=="liste") {
$content="Sorgulayabilecegin servisler:\nfizy\nlifebox\nbip\nhesabim\ndergilik\nRBT\nTurkcellTv\nupcall\nplatinum\ntty\ngnc\nakademi\nyanimda\nspotify\nwhatsapp\ndmags\nresmiislerim";
$postResult=sendBipResponse($receiver,$content);
echo "\nliste content is: ".$content;
}elseif ($appControl==1){
$content=getBipDetails($keyword);
$postResult=sendBipResponse($receiver,$content);
echo "\nServiceName case content is: ".$content;
//$URLmessage="http://turkcell.ga/details.php?app=".$keyword;
} elseif ($keywordLT=="hepsi"){
if ($keywordRT=="android") {$con="android";} else{$con="ios";}
$content=getBipAllDetails($con);
$postResult=sendBipResponse($receiver,$content);
echo "\nhepsi content is: ".$content;
//$URLmessage="http://turkcell.ga/details.php?app=".$keyword;
} elseif ($keywordLT=='Appony,' or $keyword==''){
$content="Hosgeldin ".$sender.". Senin icin neler yapabilecegimi gormek istersen yardim yazip gondermen yeterli.";
$postResult=sendBipResponse($receiver,$content);
echo "\nnull content is: ".$content;
}else {
$content="Hatali istek girdin. Sorgulayabilecegin sihirli kelimeleri ogrenmek icin yardim yazip gonderebilirsin.";
$postResult=sendBipResponse($receiver,$content);
echo "\nhata content is: ".$content;
}
}
//content bitis
//$receiver=$sender;
//date_default_timezone_set('Europe/Istanbul');
echo "\n\nINFO - ".date('d/m/Y h:i:s', time())." - receiver is ".$receiver." and message is:\n ".$content."\n\n";
// if ($appControl==1){
// $ImageURL=getImageUrl($keyword);
// $resultImage=sendBipImage($receiverArray,$content,$imageURL);
// } else {
//}
echo "\n\nINFO - POSTRESULT : ".date('d/m/Y h:i:s', time())." - \n".$postResult;
echo "\n\nINFO - POSTRESULT : ".date('d/m/Y h:i:s', time())." - \n".$postResult;
function sendBipResponse($receiver,$content){
//$postdataRaw ='{"txnid":"200","receiver":{"type":2, "address":"'.$receiver.'"}, "composition": {"list": [{"type":0,"message":"'.$content.'"}]}}';
$tnxid=rand(1000,9999);
$postdata['txnid']=$tnxid;
$receiverArray['type']=2;
$receiverArray['address']=$receiver;
$postdata['receiver']=$receiverArray;
$listArray0['type']=0;
$listArray0['message']=$content;
$listArray[0]=$listArray0;
$composition0['list']=$listArray;
$postdata['composition']=$composition0;
//echo "\npostdata array: ".$postdata;
//$postdataJson = "json=".json_encode($postdata)."&";
$postdataJson = json_encode($postdata);
echo "\n\npostdata json: ".$postdataJson."\n\n\n";
$file="appony.log";
$log=date("Y-m-d h:i:sa")." - RESPONSE - receiver: ".$receiver." jsonString: ".$postdataJson." - tnxid:".$tnxid.PHP_EOL;
file_put_contents($file, $log, FILE_APPEND | LOCK_EX);
// $contentArray=array(
// 'txnid' => '200',
// 'receiver' => array( 'type' => 2,'address' => $receiver),
// 'composition' => array('list' => 0 array (0 => array(
// 'type' => 0, 'message' => $content ))));
//$postdata=json_encode($contentArray);
//$postData=json_encode($bipRespArray);
$bipTesURL="http://tims.turkcell.com.tr/tes/rest/spi/sendmsgserv";
$username="user";
$password="pass";
// $curl = curl_init();
// curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
// curl_setopt($curl, CURLOPT_USERPWD, "user:pass");
// curl_setopt($curl, CURLOPT_POST, true);
// curl_setopt($curl, CURLOPT_POSTFIELDS, $postdataJson);
// curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($curl, CURLOPT_URL, $bipTesURL);
// //curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type : application/json","Accept: application/json"));
// $result=curl_exec($curl);
// curl_close($curl);
$ch = curl_init($bipTesURL);
//curl_setopt($ch, CURLOPT_POST, true);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC ) ;
curl_setopt($ch, CURLOPT_USERPWD, "bu2705614779894449:bu270562f6d5476");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdataJson);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
$result = curl_exec($ch);
//print_r($result);
//echo "statuscode: ".$status_code;
//echo $result;
return $result;
}
?>