-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathussdap.php
115 lines (91 loc) · 3.18 KB
/
ussdap.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
<?php
ini_set('error_log', 'ussd-app-error.log');
require 'libs/MoUssdReceiver.php';
require 'libs/MtUssdSender.php';
require 'class/operationsClass.php';
require 'log.php';
require 'db.php';
$production=false;
if($production==false){
$ussdserverurl ='http://localhost:7000/ussd/send';
}
else{
$ussdserverurl= 'https://api.dialog.lk/ussd/send';
}
$receiver = new UssdReceiver();
$sender = new UssdSender($ussdserverurl,'APP_000001','password');
$operations = new Operations();
$receiverSessionId = $receiver->getSessionId();
$content = $receiver->getMessage(); // get the message content
$address = $receiver->getAddress(); // get the sender's address
$requestId = $receiver->getRequestID(); // get the request ID
$applicationId = $receiver->getApplicationId(); // get application ID
$encoding = $receiver->getEncoding(); // get the encoding value
$version = $receiver->getVersion(); // get the version
$sessionId = $receiver->getSessionId(); // get the session ID;
$ussdOperation = $receiver->getUssdOperation(); // get the ussd operation
$responseMsg = array(
"main" =>
"T-Shirts
1. Small
2. Medium
3. Large
99. Exit"
);
if ($ussdOperation == "mo-init") {
try {
$sessionArrary=array( "sessionid"=>$sessionId,"tel"=>$address,"menu"=>"main","pg"=>"","others"=>"");
$operations->setSessions($sessionArrary);
$sender->ussd($sessionId, $responseMsg["main"],$address );
} catch (Exception $e) {
$sender->ussd($sessionId, 'Sorry error occured try again',$address );
}
}else {
$flag=0;
$sessiondetails= $operations->getSession($sessionId);
$cuch_menu=$sessiondetails['menu'];
$operations->session_id=$sessiondetails['sessionsid'];
switch($cuch_menu ){
case "main": // Following is the main menu
switch ($receiver->getMessage()) {
case "1":
$operations->session_menu="small";
$operations->saveSesssion();
$sender->ussd($sessionId,'Enter Your ID',$address );
break;
case "2":
$operations->session_menu="medium";
$operations->saveSesssion();
$sender->ussd($sessionId,'Enter Your ID',$address );
break;
case "3":
$operations->session_menu="large";
$operations->saveSesssion();
$sender->ussd($sessionId,'Enter Your ID',$address );
break;
default:
$operations->session_menu="main";
$operations->saveSesssion();
$sender->ussd($sessionId, $responseMsg["main"],$address );
break;
}
break;
case "small":
$operations->session_menu="medium";
$operations->session_others=$receiver->getMessage();
$operations->saveSesssion();
$sender->ussd($sessionId,'You Purchased a small T-Shirt Your ID '.$receiver->getMessage(),$address ,'mt-fin');
break;
case "medium":
$sender->ussd($sessionId,'You Purchased a medium T-Shirt Your ID '.$receiver->getMessage(),$address ,'mt-fin');
break;
case "large":
$sender->ussd($sessionId,'You Purchased a large T-Shirt Your ID '.$receiver->getMessage(),$address ,'mt-fin');
break;
default:
$operations->session_menu="main";
$operations->saveSesssion();
$sender->ussd($sessionId,'Incorrect option',$address );
break;
}
}