Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CHAPTER 1
INTRODUCTION
As per TRAI data of May, 2014, though there are about 38 crore mobile
telephone connections in rural areas, internet penetration in the countryside is still
abysmally low (in single digit percentage). Therefore, mobile messaging is the most
effective tool so far having pervasive outreach to nearly 8.93 crore farm
families. Mobi Agri USSD Portal for farmers enables all Central and State government
organizations in agriculture and allied sectors to give information/services/advisories to
farmers by USSD in their language, preference of agricultural practices and location.
Mobile telephony (with or without internet) is the most potent and omnipresent tool of
agricultural extension
The project conceptualized, designed and developed in-house within the Department
of Agriculture & Cooperation has widened the outreach of scientists, experts and
Government officers posted down to the Block level to disseminate information, give
advisories and to provide advisories to farmers through their mobile telephones. In this
project, we investigate the extendibility of our approach to other systems by studying the
relevance of these attributes for predicting disengagement in a different messaging
system. To this end we go for USSD. The main technology used during the project was
PHP. Apache server in the WAMP bundle was used as the web server. WAMP is an easy
to install Apache distribution containing MySQL, PHP.
CHAPTER 2
ORGANIZATION PROFILE
2.1 ABOUT THE DEPARTMENT
Government of Tamil Nadu Department of Agriculture
The Department of Agriculture is a master setup to cater to the entire needs of the
farmers in respect of crop cultivation and allied activities. Agricultural Extension in its
way back from 60s soon after the First Green Revolution has undergone many structural
changes both in its form and in function.
Originally the Research, Marketing, Horticulture, Engineering were all the official
organs of the single authority, wherein the farmers had the privilege of seeking the
assistance of a single person at the block level for all his requirements relating to
cropping and allied activities.
CHAPTER 3
SYSTEM ANALYSIS
3.1 THE EXISTING SYSTEM
Push SMS
Although there are about 38 crore mobile telephone connections in rural areas,
however internet penetration in the countryside is still very low. Mobile messaging is still
the most effective tool so far having pervasive outreach to nearly nine crore farm
families. mKisan SMS Portal for farmers enables all Central and State government
organizations in agriculture and allied sectors to give information/services/advisories to
farmers by SMS in their language, preference of agricultural practices and location. Push
SMS portal was inaugurated by the Honble President of India and since then nearly 49
crore messages or more than 152 crore SMSs have been sent to farmers throughout the
length and breadth of the country.
Officers from different departments and organizations of Central and State
Governments can register themselves for sending advisories to farmers through this
portal. Detailed procedure for registration of users is given in the User Manual at login
page. On approval of registration request by superior/designated officer of the intended
user, he can commence using this application for reaching out to the farmers under his/her
jurisdiction.
Farmers can register themselves for receiving these messages on their mobiles as per
their specific needs & relevance at a particular point of time. They can register
themselves for this service through any of these channels:1. Web Registration at http://farmer.gov.in/Advs/WebRegistration/WebReg.aspx
2. Kisan Call Centers (KCC) - by calling on Toll free number - 1800-180-1551
3. Sending SMS at 51969 or 9212357123
4. Common Service Centers (CSCs)
5. State/District or block agriculture offices
A user dials a short code from his/her handset and chooses among various options
provided in a set of response menus during a session of up to 3 minutes in case of
mKisan.
The progress of one session into the next depends on the user's response. USSD
messages in English are 150 alphanumeric characters in length and up to 45 to 60
characters in Unicode (for local language). Local language support depends on type of
handset.
USSD
SMS
Session Based
CHAPTER 4
SYSTEM CONFIGURATION
4.1 HARDWARE CONFIGURATION
Processor
Hard Disk
80 GB
Ram
2 GB
Monitor
15 inch
Mouse
Optical
Keyboard
102 Keys
Windows 7
Language
PHP
Backend
MySQL
Apache Server
Wamp
Simulator
Its fast due to the fact that its embedded into the HTML code.
Its quite easy to use in that it only contains elements of a programming language
needed to interact with a database and to generate dynamic web-pages.
MAKE
MAKE INSTALL
Configuration
In order for Apache to recognise the PHP files, change have to me made to the
httpd.conf file. You must tell Apache what file types might contain PHP code. You
can do this by adding the following entry into the httpd.conf file:
ADDTYPE APPLICATION/X-HTTPD-PHP. PHP
Testing
To test PHP the following PHP file (test.php) was created:
</php
echo PHP is working correctly;
8
?>
Next save this file on the server. Point the browser at the test.php. PHP
is working properly if the PHP is working correctly string is
displayed in the browser window.
Apache Testing
In order to test Apache, you must first start apache. To start apache type:
/ETC/RC.D/INIT.D/HTTPD START
To test if Apache is running properly type
MOZILLA HTTP://LOACLHOST
If Apache is working properly you will be presented with an Apache test page.
CHAPTER 5
Project Management
5.1 Introduction
Good project management will able to reduce the risk of project failure. Time,
scope, and cost are the triple constraint in project management. In addition, a good
project management should including five process and nine knowledge area. The
project manage must understand the organization structure and develop good
relationship with all stakeholders.
This chapter will describe the project management on this project, including project
plan, project scope, and project schedule.
10
Content prepared for SMS and USSD needs to be actionable. For example
when sending weather information via USSD, it should provide some
advice alongside the weather forecast for the different crops for which
information is provided through the service.
11
Task #
Task Name
Duration
Project Selection
4 M
collection of literture
summaries literture
8 M
10
requirement collection
11 M
requirement specification
12
25
13
14 M
15
database analysis
16 M
17
10
18
19 M
49
20
21
coding of system
24
22
23 M
test plan
24
program testing
25
evaluation of project
26 M
27
28
29
56
56
0
Start
End
12
13
CHAPTER 6
PROJECT DESCRIPTION
6.1 PROBLEM DEFINITION
Text messaging facilitates the exchange of short messages. Text messaging can serve
as a substitute to phone calling, could be used in a remote control system, participation in
a contest, service requests, advertising, and so forth. However, text messaging has some
disadvantages.
Limited storage: There is a limit to the number of text messages that could be stored in
the phone. If your inbox gets full, your phone can no longer receive anymore messages
unless you delete some of them. If your SIM card or phone goes bad, you could lose your
messages, if not backed up. However, some service providers have deployed a way
around this, for example, Glo SMS4Ever.
Length: Text messaging when the content is lengthy is not convenient. A page of a text
message could contain 160, 140 or 70 characters [including spaces] depending on the bit
of the characters. Although you can send a multi-page text message, the higher the
number of pages, the higher the probability of delivery failure.
Content: A text message is what it is; it can contain only text. It does not support other
media, including videos, pictures, melodies or animations. To be able to send a
multimedia message, you must use Enhanced Messaging Service (EMS) or MMS.
Not suitable in emergencies: In situations that require immediate response, text
messaging may not be the most viable option.
Security issues: Gartner has recommended that confidential messages shouldn't be sent
using the regular consumer SMS as the contents of a common text message could be seen
by the network's systems and personnel.
14
15
USSD technology is the key solution in all cases. It is a messaging service that is
almost seven times faster than SMS and is highly cost effective. The operations involved
in using USSD are simple and handset independent, which means the service can be
accessed from almost any mobile device (from old cell phones to the latest smartphones).
From the core network to the internet, the reach of modern USSD services is rapidly
transforming the telecom cloud into a services cloud. USSD is fast emerging as the
communication protocol, which can ouster the dependency on SMS for quick messaging
services.
Need For USSD
USSD is a highly cost effective and fast technology and is seven times faster in
operating speed than SMS. USSD has several advantages as a bearer technology, such as:
1. USSD provides a cost-effective and flexible mechanism for offering various
interactive and non-interactive mobile services to a wide subscriber base.
2. USSD supports menu-based applications facilitating more user interactions.
16
3. USSD is neither a phone-based nor a SIM-based feature. It works on almost all GSM
mobile phones (from old handsets to new smartphones)
4. With USSD, messages can even be initiated during calls, allowing simultaneous voice
and data communication.
5. USSD allows faster communication between users and network applications because
messages are sent directly to the receiver allowing an instant response.
6. USSD services available on the home network are also accessible while roaming.
Unlike SMS, there are no charges for this.
USSD is increasingly being adopted to develop interactive applications like mobile
chatting, roaming with prepaid service, callback service, simultaneous software upgradation of huge customer base, prepaid recharge, mobile banking, etc. Competitive
pressure to deploy innovative services is driving the demand for USSD. USSD is proving
to be the ideal medium for quickly deploying a variety of new services and applications.
17
1. The network part that includes the Home Location Register (HLR), Visitor Location
Register (VLR), and MSC
2. Complex logic to support multiple applications within a single USSD platform
3. Simple Messaging Peer-Peer (SMPP) interface for applications to enable services
4. USSD Gateway and all specific USSD application servers
USSD Gateway (USSD Center) is totally open and can be integrated with any telecom
system/device and the internet. These features allow rapid deployment of new services
and encourage existing messaging applications to leverage the USSD technology.
Figure 4 - USSD Architecture
USSD services reside as applications in the mobile network. These applications can
reside in MSC, VLR, HLR, or an independent application server that is connected
through a USSD Gateway (using SMPP).
If a USSD message is not destined for an application in the MSC, VLR, or HLR, a
USSD handler in these nodes routes the message to the USSD Gateway using the MAP
protocol based on the service code. The gateway interprets the code and routes it to the
specific USSD application server to fetch the necessary information requested by the
18
user. In response, the application sends the relevant information to the USSD Gateway,
which in turn converts the message to MAP format, and then sends to the mobile
terminal.
Applications under the mobile operators control will typically reside in the GSM
network (MSC, VLR, HLR), while third-party applications may reside elsewhere such as
on the internet. The application can also be a hyperlink to an internet site or information
stored locally in the Service Application System. In a mobile-initiated service request, a
session is created between the network and the mobile terminal. This session is used for
all information transfers and must be released before another session can be started.
Additionally, an application in the network (residing in the MSC, VLR, HLR, or external
application server) may at any time send a message to a mobile terminal. This can be a
request for information or a notification. Again, the session must be released upon
completion.
19
20
2. Push services
Voting/polling
3. Reservations (train/movies)
4. Sponsored menu items/advertisements
Companies/shops/theaters can get listed on the menu and promote their services
5. To indicate the account balance information from network to user after each call
6. Direct balance inquiry by user without using IVR
7. Prepaid recharge (even while roaming) through registered credit card
21
8. Card validity time information
9. Prepaid balance transfer: prepaid subscriber can transfer money to another prepaid
users account (e.g., press *short code*Security Code*other party number*Amount#
and dial)
USSD in Agri:
A typical illustration of USSD Session has been given in the following slide in which
a farmer selects appropriate kind of machine for the crop sown by him / her and gets contact
details of dealers and product prices.
Figure 7 USSD Billing Plan
22
23
SDP clients can send requests to the SDP Simulator. Created applications can be used
to send requests to the simulator.
USSD MT
Once connected to the application, the USSD prompt will be shown with the options.
The Messages sent to Customer section shows the messages with the details (message sent
time, destination phone number and message content) as shown in the figure below.
24
User can still test the MT part alone (without MO) with any application provided that it can
send MT messages.
For that, send the MT message to the following URL (which accepts USSD MT) and the MT
message will be displayed in the simulator.
http://localhost:7000/ussd/send
USSD MO
To send a message to the application, the CP can use the provided interface in the
simulator. Refer the figure below.
25
Enter the details as follows.
Field name
URL
Application ID
Description
The URL where the
application is hosted
Unique ID of the
Application
Sample value
http://localhost:5555/mo-ussd
APP_00001
Password
Password
of
the password
application.
The
application password
will be autogenerated
when the application is
created.
Customer
Number
94775576481
Service Code
*141#
Status/Error
Code
Once the values are entered correctly, click on the Send button.
The messages sent to the application will be displayed with its sent time, phone number,
message content and status under Message sent to Application section.
26
HTTP REST
In this context, both requests/responses used to exchange information are with content type
"application/json".
JSON Objects
JSON objects are used as content type to communicate between application and Idea Mart. JSON
is an open, text-based data exchange format; it is human-readable, platform independent, and supports a
wide availability of implementations.
A USSD service can be invoked either by the mobile user or by a USSD platform.
Send Service
This service lets the user send USSD to one or more terminals from the application.
Send service supports only POST HTTP requests. This is used when sending USSD
messages to a mobile phone from an application.
Request
Following is a sample request for send service.
{
"applicationId": "APP_000001",
"password": "password",
"message": "1. Press One
2. Press two
3. Press three
4. Exit",
"sessionId": "1330929317043",
"ussdOperation": "mt-cont",
"destinationAddress": "tel:94771122336"
}
Description
Application ID as given
when provisioned
String
String
Type
/O
M
M
O
27
sessionId
ussdOperation
destinationAddress
String
Enumerator
Destination
String
address
should be a telephone
number
tel
for
MSISDN
tel: 94771122336
Note : tel might be a masked
number depending on the type of
application
encoding
Enumerated
number to 2
O
Charging amount specified for
decimal places
variable charging applications only
E.g., 78.05
Shall be considered only in system
currency
28
Comprehensive sample request:
{
"applicationId": "APP_000001",
"password": "password",
"version": "1.0",
"message": "1. Press One
2. Press two
3. Press three
4. Exit",
"sessionId": "1330929317043",
"ussdOperation": "mt-cont",
"destinationAddress": "tel:94771122336",
"encoding": "440",
"chargingAmount": "5"
}
Response
USSD-Send-Response is a response from the Idea Mart to the application, which will be sent
as a response to the USSD-Send-Request message.
Following are the response parameters of send service
Parameter
Name
Description
Type
M/
O
version
String
String
requestId
timeStamp
Processed timestamp
statusCode
String
statusDetail
String
29
Comprehensive sample response:
{
"statusCode": "S1000",
"timeStamp": "1203051205",
"statusDetail": "Success",
"requestId": "1330929317059",
"version": "1.0"
}
Receive Service
The ReceiveUssd service allows Idea Mart to deliver MO messages to the application using
HTTP based API. The flow of messages is initiated by a MO request sent to an application,
the Idea Mart will deliver the message to the application as an acknowledgement. Hence it
could be either request-response exchange or a request-exception exchange.
Receive USSD request is a MO message which will be sent to the application through the
Idea Mart as a delivery request.
Request
Following is a sample request for receive service
{
"message": "*141#",
"ussdOperation": "mt-cont",
"requestId": "1330933229901",
"sessionId": "1330929317043",
"encoding": "440",
"sourceAddress": "tel:94771122336",
"applicationId": "APP_000001",
"version": "1.0"
}
30
Following are the request parameters of deliver service.
Description
Type
M/O
version
String
applicationId
String
String
Integer
String
Parameter
Name
sessionId
ussdOperation
sourceAddress
sender address sourceAddress:
tel:94771122336
vlrAddress
String
message
String
Enumerated
encoding
String
31
Comprehensive sample request:
{
"message": "*141#",
"ussdOperation": "mo-init",
"requestId": 1330933229901,
"vlrAddress": "some vlr address",
"sessionId": "1330929317043",
"encoding": "440",
"sourceAddress": "tel:94771122336",
"applicationId": "APP_000001",
"version": "1.0"
}
Response
Deliver-USSD-Response should be the response given by the Application to the Idea Mart as
an acknowledgement on the receipt of a MO message submitted by Idea Mart.
Parameter
Name
Description
Type
M/O
statusCode
String
statusDetail
String
{
"statusCode": "S1000",
"statusDetail": "Success"
}
32
CHAPTER 7
SOFTWARE TESTING
7.1 SYSTEM MAINTENANCE
The objectives of this maintenance work are to make sure that the system gets into
work all time without any bug. Provision must be for environmental changes which may
affect the computer or software system. This is called the maintenance of the system.
Nowadays there is the rapid change in the software world. Due to this rapid change, the
system should be capable of adapting these changes. In our project the process can be added
without affecting other parts of the system. Maintenance plays a vital role. The system liable
to accept any modification after its implementation. This system has been designed to favor
all new changes. Doing this will not affect the systems performance or its accuracy.
7.2 SYSTEM TESTING
Testing is done for each module. After testing all the modules, the modules are
integrated and testing of the final system is done with the test data, specially designed to
show that the system will operate successfully in all its aspects conditions. The procedure
level testing is made first. By giving improper inputs, the errors occurred are noted and
eliminated. Thus the system testing is a confirmation that all is correct and an opportunity to
show the user that the system works. The final step involves Validation testing, which
determines whether the software function as the user expected. The end-user rather than the
system developer conduct this test most software developers as a process called Alpha and
Beta test to uncover that only the end user seems able to find.
This is the final step in system life cycle. Here we implement the tested error-free
system into real-life environment and make necessary changes, which runs in an online
fashion. Here system maintenance is done every months or year based on company policies,
and is checked for errors like runtime errors, long run errors and other maintenances like
table verification and reports.
33
7.3 UNIT TESTING
Unit testing verification efforts on the smallest unit of software design, module. This
is known as Module Testing. The modules are tested separately. This testing is carried out
during programming stage itself. In these testing steps, each module is found to be working
satisfactorily as regard to the expected output from the module.
7.4 INTEGRATION TESTING
Integration testing is a systematic technique for constructing tests to uncover error
associated within the interface. In the project, all the modules are combined and then the
entire programmer is tested as a whole. In the integration-testing step, all the error uncovered
is corrected for the next testing steps.
7.5 VALIDATION TESTING
To uncover functional errors, that is, to check whether functional characteristics
confirm to specification or not specified.
34
CHAPTER 8
Implementation
8.1 Introduction
This part will describe the system implementation, including g train users, implement,
review business aspects, and user approval guidelines.
8.2 Timebox
The functional model interaction will use thirteen days to complete. It will start from
2014/07/01 to 2014/11/17.
Duration
Set up database
1 Days
1 Days
User documentation
1 Days
User training
3 Days
Project Review
3 Days
Start Day
End Day
Project proposal
Project report
These document will assist the users to use the system, and able to keep a record
about this project. The system use handbook and system usage policy able to provide
clearly guideline to different users. The project proposal, project report will provide
reference information to other project in the future.
35
8.4 User Training
User training is the important activity of this project. It is because the system is
providing to user to use. If users not understand how to use the system or user not suite to
use the system, the performance will not achieve, and the project may be failure. The
methods of user training including provide training course and user handbook to user.
8.5 Project Review
When the project will be completed, the project team should make a project
review. The project review will help the project team to understand the good points and
the weak points of this project. In addition, the project risk will be finding via the project
review.
36
Chapter 10
Conclusion
37
Programming
I weak in programming due to I have never take course to learn. I read the
reference book and view the website to learn PHP program. Some complex
system function is difficult to develop, such as bar chart of student latest course
evaluation result. I write a SQL statement to count the data for each bar chart. I
know this is low efficiency method, but I only able to do this due to I dont know
how to write more complex PHP web page.
Times
This project has about four months to complete, so I should enough time to
complete this project. However, I choice to use more time do housework and look
after my father due to he has cancer. Therefore, I lost a lot of time but I think my
choice is right.
Methodology
In order to complete this project and choose the suite methodology, I read any
reference books and view any website. After this project, I learn more methodology
38
knowledge especially USSD.
Project Management
Time management and scope management is very important in this project. After this
project, I understand how to handle a small project and use project management
method to reduce the risk of project failure.
PHP program
Before this project, I only know how to use PHP program to build up a simple web
page. After to complete this project, I learn how to build up a server side scripting
and also use MySQL statement to build up a session data.
Project Scope
Define the project scope also is important. It is because when the scope is large, then
it will use more time to complete. Otherwise, if the scope is narrow, it may not
achieve the objective of this project. Therefore, define the suite scope is important.
39
CHAPTER 11
APPENDICES
11.1 SAMPLE CODE
USSDAPP.PHP
1 <?php
2
3 include_once '../../lib/ussd/MoUssdReceiver.php' ;
4 include_once '../../lib/ussd/MtUssdSender.php' ;
5 include_once '../log.php' ;
6 ini_set ('error_log' , 'ussd-app-error.log' );
7
8 $receiver = new MoUssdReceiver (); // Create the Receiver object
9
10 $receiverSessionId = $receiver ->getSessionId ();
11 session_id ($receiverSessionId ); //Use received session id to create a unique session
12 session_start ();
13
14 $content = $receiver ->getMessage (); // get the message content
15 $address = $receiver ->getAddress (); // get the sender's address
16 $requestId = $receiver ->getRequestID (); // get the request ID
17 $applicationId = $receiver ->getApplicationId (); // get application ID
18 $encoding = $receiver ->getEncoding (); // get the encoding value
19 $version = $receiver ->getVersion (); // get the version
20 $sessionId = $receiver ->getSessionId (); // get the session ID;
21 $ussdOperation = $receiver ->getUssdOperation (); // get the ussd operation
22
23 logFile ("[ content=$content, address=$address, requestId=$requestId,
applicationId=$applicationId, encoding=$encodin
g, version=$version, sessionId=$sessionId, ussdOperation=$ussdOperation ]" );
24
25 //your logic goes here......
26 $responseMsg = array (
27 "main" => "
40
1.
28 2.English
29 3.Contact
30 000.Exit" ,
31 "tamil" => "
32 1.
33 2.
34 3.
35 4.
36 99.Back" ,
37 "english" => " Welcome
38 1.Season
39 2.Weather info
40 3.Market Price
41 4.Govt.Assistance
42 99.Back" ,
43 "contacts" => "for any quries contact
44 1.tna
45 2.tngov
46 99.Back" ,
47 "seas" => "1.
48 2
49 3.
50 4.
51 5.
52 99.Back" ,
53 "karr" =>"1.
54 2.
55 3.
56 4.
57 99.Back" ,
58 "kuruvaii" =>"1.
59 2.
60 3.
61 4.
62 99.Back" ,
63 "sambaa" =>"1.
64 2
41
65 3.
66 4.
67 99.Back" ,
68 "sornnaa" =>"1.
69 2.
70 3.
71 4.
72 99.Back" ,
73 "moree" =>"6.
74 7.
75 99.Back" ,
76 "weat" => " .
77 99.Back" ,
78 "mark" => "
79 99.Back" ,
80 "assi" => "
81 99.Back" ,
82
83
84
85
86 "season" => "1.Kar
87 2.Kuruvai
88 3.Sornawari
89 4.Samba
90 5.More
91 99.Back" ,
92 "kar" =>"1.Crop
93 2.Technology
94 3.Pest
95 4.Disease
96 99.Back" ,
97 "kuruvai" =>"1.Crop
98 2.Technology
99 3.Pest
100 4.Disease
101 99.Back" ,
102 "sorna" =>"1.Crop
103 2.Technology
42
104 3.Pest
105 4.Disease
106 99.Back" ,
107 "samba" =>"1.Crop
108 2.Technology
109 3.Pest
110 4.Disease
111 99.Back" ,
112 "more" =>"1.Thirthawari
113 2.Parugai" ,
114
115 "weather" => "Enter your area pincode to know the weather condition
116 99.Back" ,
117 "market" => "Enter your area pincode to know the market prices.
118 99.Back" ,
119 "assist" => "for more details visit your nearest AEC.
120 99.Back" ,
121 "tna" => "Agriculture Directorate,Chepauk,Chennai600005 Ph No:28524894
122 99.Back" ,
123 "tngov" => "http://www.tn.gov.in/department/2
124 99.Back"
125
126
127
128 );
129
130 logFile ("Previous Menu is := " . $_SESSION['menu-Opt' ]); //Get previous menu number
131 if (($receiver ->getUssdOperation ()) == "mo-init" ) { //Send the main menu
132 loadUssdSender ($sessionId , $responseMsg ["main" ]);
133 if (!(isset ($_SESSION['menu-Opt' ]))) {
134 $_SESSION['menu-Opt' ] = "main" ; //Initialize main menu
135 }
136
137 }
138 if (($receiver ->getUssdOperation ()) == "mo-cont" ) {
139 $menuName = null;
140
141 switch ($_SESSION['menu-Opt' ]) {
142 case "main" :
143 switch ($receiver ->getMessage ()) {
43
144 case "1" :
145 $menuName = "tamil" ;
146 break ;
147 case "2" :
148 $menuName = "english" ;
149 break ;
150 case "3" :
151 $menuName = "contacts" ;
152 break ;
153 default :
154 $menuName = "main" ;
155 break ;
156 }
157 $_SESSION['menu-Opt' ] = $menuName ; //Assign session menu name
158 break ;
159 case "tamil" :
160 $_SESSION['menu-Opt' ] = "tamil-hist" ;
161 switch ($receiver ->getMessage ()) {
162 case "1" :
163 $menuName = "seas" ;
164 break ;
165 case "2" :
166 $menuName = "weat" ;
167 break ;
168 case "3" :
169 $menuName = "mark" ;
170 break ;
171 case "4" :
172 $menuName = "assi" ;
173 break ;
174 case "99" :
175 $menuName = "main" ;
176 $_SESSION['menu-Opt' ] = "main" ;
177 break ;
178 default :
179 $menuName = "main" ;
180 break ;
181 }
182 $_SESSION['menu-Opt' ] = $menuName ; //Assign session menu name
183 break ;
44
184 case "seas" :
185 $_SESSION['menu-Opt' ] = "season-hist" ;
186 switch ($receiver ->getMessage ()) {
187 case "1" :
188 $menuName = "karr" ;
189 break ;
190 case "2" :
191 $menuName = "kuruvaii" ;
192 break ;
193 case "3" :
194 $menuName = "sambaa" ;
195 break ;
196 case "4" :
197 $menuName = "sornnaa" ;
198 break ;
199
200 case "5" :
201 $menuName = "moree" ;
202 break ;
203 case "99" :
204 $menuName = "main" ;
205 $_SESSION['menu-Opt' ] = "main" ;
206 break ;
207 default :
208 $menuName = "main" ;
209 break ;
210 }
211
212 break ;
213 case "english" :
214 $_SESSION['menu-Opt' ] = "english-hist" ;
215 switch ($receiver ->getMessage ()) {
216 case "1" :
217 $menuName = "season" ;
218 break ;
219 case "2" :
220 $menuName = "weather" ;
221 break ;
222 case "3" :
223 $menuName = "market" ;
45
224 break ;
225 case "4" :
226 $menuName = "assist" ;
227 break ;
228 case "99" :
229 $menuName = "main" ;
230 $_SESSION['menu-Opt' ] = "main" ;
231 break ;
232 default :
233 $menuName = "main" ;
234 break ;
235 }
236 $_SESSION['menu-Opt' ] = $menuName ; //Assign session menu name
237 break ;
238 case "season" :
239 $_SESSION['menu-Opt' ] = "season-hist" ;
240 switch ($receiver ->getMessage ()) {
241 case "1" :
242 $menuName = "kar" ;
243 break ;
244 case "2" :
245 $menuName = "kuruvai" ;
246 break ;
247 case "3" :
248 $menuName = "sorna" ;
249 break ;
250 case "4" :
251 $menuName = "samb" ;
252 break ;
253 case "5sss" :
254 $menuName = "more" ;
255 break ;
256 case "99" :
257 $menuName = "main" ;
258 $_SESSION['menu-Opt' ] = "main" ;
259 break ;
260 default :
261 $menuName = "main" ;
262 break ;
263 }
46
264 break ;
265 case "contacts" :
266 $_SESSION['menu-Opt' ] = "contact-hist" ;
267 switch ($receiver ->getMessage ()) {
268 case "1" :
269 $menuName = "tna" ;
270 break ;
271 case "2" :
272 $menuName = "tngov" ;
273 break ;
274 case "99" :
275 $menuName = "main" ;
276 $_SESSION['menu-Opt' ] = "main" ;
277 break ;
278 default :
279 $menuName = "main" ;
280 break ;
281 }
282 break ;
283 case "tamil-hist" || "english-hist" || "contact-hist" :
284 switch ($_SESSION['menu-Opt' ]) { //Execute menu back sessions
285 case "tamil-hist" :
286 $menuName = "tamil" ;
287 break ;
288 case "english-hist" :
289 $menuName = "english" ;
290 break ;
291 case "contact-hist" :
292 $menuName = "contacts" ;
293 break ;
294 }
295 $_SESSION['menu-Opt' ] = $menuName ; //Assign previous session menu name
296 break ;
297 }
298
299 if ($receiver ->getMessage () == "000" ) {
300 $responseExitMsg = " !
301 Thank You!" ;
302 $response = loadUssdSender ($sessionId , $responseExitMsg );
303 session_destroy ();
47
304 } else {
305 logFile ("Selected response message := " . $responseMsg [$menuName ]);
306 $response = loadUssdSender ($sessionId , $responseMsg [$menuName ]);
307 }
308
309 }
310 /*
311 Get the session id and Response message as parameter
312 Create sender object and send ussd with appropriate parameters
313 **/
314
315 function loadUssdSender ($sessionId , $responseMessage )
316 {
317 $password = "password" ;
318 $destinationAddress = "tel:94771122336" ;
319 if ($responseMessage == "000" ) {
320 $ussdOperation = "mt-fin" ;
321 } else {
322 $ussdOperation = "mt-cont" ;
323 }
324 $chargingAmount = "5" ;
325 $applicationId = "APP_000001" ;
326 $encoding = "440" ;
327 $version = "1.0" ;
328
329 try {
330 // Create the sender object server url
331
332 // $sender = new MtUssdSender("http://fcms.tn.gov.in/ussd/send/"); // Application ussd-mt
sending http url
333 $sender = new MtUssdSender ("https://localhost:7443/ussd/send/" ); // Application ussd-mt
sending https url
334 $response = $sender ->ussd ($applicationId , $password , $version , $responseMessage ,
335 $sessionId , $ussdOperation , $destinationAddress , $encoding , $chargingAmount );
336 return $response ;
337 } catch (UssdException $ex) {
338 //throws when failed sending or receiving the ussd
339 error_log ("USSD ERROR: {$ex->getStatusCode()} | {$ex->getStatusMessage()}" );
340 return null;
341 }
48
342 }
343
344 ?>
USSD SENDER.PHP
1 <?php
2
3 class MtUssdSender {
4 var $server ;
5
6 public function __construct ($server ){
7 $this ->server = $server ; // Assign server url
8}
9
10 /*
11 Get parameters form the application
12 check one or more addresses
13 Send them to ussdMany
14 **/
15
16 public function ussd ($applicationId , $password , $version , $responseMsg ,
17 $sessionId , $ussdOperation , $destinationAddress , $encoding , $chargingAmount ){
18 if (is_array ($destinationAddress )) { //Check destination address is a array or not
19 return $this ->ussdMany ($applicationId , $password , $version , $responseMsg ,
20 $sessionId , $ussdOperation , $destinationAddress , $encoding , $chargingAmount );
21 } else if (is_string ($destinationAddress ) && trim ($destinationAddress ) != "" ) {
22 return $this ->ussdMany ($applicationId , $password , $version , $responseMsg ,
23 $sessionId , $ussdOperation , $destinationAddress , $encoding , $chargingAmount );
24 } else {
25 throw new Exception ("address should a string or a array of strings" );
26 }
27 }
28
29 /*
30 Get parameters form the ussd
31 Assign them to an array according to json format
49
32 encode that array to json format
33 Send json to sendRequest
34 **/
35
36 private function ussdMany ($applicationId , $password , $version , $message ,
37 $sessionId , $ussdOperation , $destinationAddress , $encoding , $chargingAmount ){
38
39 $arrayField = array ("applicationId" => $applicationId ,
40 "password" => $password ,
41 "message" => $message ,
42 "destinationAddress" => $destinationAddress ,
43 "sessionId" => $sessionId ,
44 "ussdOperation" => $ussdOperation ,
45 "encoding" => $encoding ,
46 "version" => $version ,
47 "chargingAmount" => $chargingAmount );
48
49 $jsonObjectFields = json_encode ($arrayField );
50 return $this ->sendRequest ($jsonObjectFields );
51 }
52
53 /*
54 Get the json request from ussdMany
55 use curl methods to send Ussd
56 Send the response to handleResponse
57 **/
58
59 private function sendRequest ($jsonObjectFields ){
60 $ch = curl_init ($this ->server );
61 curl_setopt ($ch , CURLOPT_POST, 1 );
62 curl_setopt ($ch , CURLOPT_SSL_VERIFYPEER , false );
63 curl_setopt ($ch , CURLOPT_HTTPHEADER, array ('Content-Type: application/json' ));
64 curl_setopt ($ch , CURLOPT_POSTFIELDS , $jsonObjectFields );
65 curl_setopt ($ch , CURLOPT_RETURNTRANSFER, true );
66 $res = curl_exec ($ch ); //Send request and get response
67 curl_close ($ch );
68 return $this ->handleResponse ($res );
69 }
70
71 /*
50
72 Get the response from sendRequest
73 check response is empty
74 return response
75 **/
76
77 private function handleResponse ($resp ){
78 if ($resp == "" ) {
79 throw new UssdException
80 ("Server URL is invalid" , '500' );
81 } else {
82 echo $resp ;
83 }
84 }
85
86 }
87
88 class UssdException extends Exception { // Ussd Exception Handler
89
90 var $code ;
91 var $response ;
92 var $statusMessage ;
93
94 public function __construct ($message , $code , $response = null ){
95 parent :: __construct ($message );
96 $this ->statusMessage = $message ;
97 $this ->code = $code ;
98 $this ->response = $response ;
99 }
100
101 public function getStatusCode (){
102 return $this ->code;
103 }
104
105 public function getStatusMessage (){
106 return $this ->statusMessage;
107 }
108
109 public function getRawResponse (){
110 return $this ->response;
111 }
51
112
113 }
114
115 ?>
USSD RECEIVER.PHP
1 <?php
2
3 class MoUssdReceiver {
4
5 private $sourceAddress ; // Define required parameters to receive response
6 private $message ;
7 private $requestId ;
8 private $applicationId ;
9 private $encoding ;
10 private $version ;
11 private $sessionId ;
12 private $ussdOperation ;
13 private $vlrAddress ;
14
15 /*
16 decode the json data an get them to an array
17 Get data from Json objects
18 check the validity of the response
19 **/
20
21 public function __construct (){
22 $array = json_decode (file_get_contents ('php://input' ), true );
23 $this ->sourceAddress = $array ['sourceAddress' ];
24 $this ->message = $array ['message' ];
25 $this ->requestId = $array ['requestId' ];
26 $this ->applicationId = $array ['applicationId' ];
27 $this ->encoding = $array ['encoding' ];
28 $this ->version = $array ['version' ];
29 $this ->sessionId = $array ['sessionId' ];
30 $this ->ussdOperation = $array ['ussdOperation' ];
31 $this ->vlrAddress = $array ['vlrAddress' ];
32
52
33 if (!((isset ($this ->sourceAddress ) && isset ($this ->message )))) {
34 throw new Exception ("Some of the required parameters are not provided" );
35 } else {
36 // Success received response
37 $responses = array ("statusCode" => "S1000" , "statusDetail" => "Success" );
38 header ("Content-type: application/json" );
39 echo json_encode ($responses );
40 }
41 }
42
43 /*
44 Define getters to return receive data
45 **/
46
47 public function getAddress (){
48 return $this ->sourceAddress;
49 }
50
51 public function getMessage (){
52 return $this ->message;
53 }
54
55 public function getRequestID (){
56 return $this ->requestId;
57 }
58
59 public function getApplicationId (){
60 return $this ->applicationId;
61 }
62
63 public function getEncoding (){
64 return $this ->encoding;
65 }
67 public function getVersion (){
68 return $this ->version;
69 }
71 public function getSessionId (){
72 return $this ->sessionId;
73 }
75 public function getUssdOperation (){
53
76 return $this ->ussdOperation;
77 }
79 }
81 ?>
LOG.PHP
1 <?php
2 /**
3 * (C) Copyright 1997-2013 hSenid International (pvt) Limited.
4 * All Rights Reserved.
5*
6 * These materials are unpublished, proprietary, confidential source code of
7 * hSenid International (pvt) Limited and constitute a TRADE SECRET of hSenid
8 * International (pvt) Limited.
9*
10 * hSenid International (pvt) Limited retains all title to and intellectual
11 * property rights in these materials.
12 */
13
14 function logFile ($rtn ){
15 $f=fopen ("log.txt" ,"a" );
16 fwrite ($f, $rtn . "\n" );
17 fclose ($f);
18 }
19
20 ?>
MySQL.PHP
1 <?php
2 $link = mysql_connect('hostname','dbuser','dbpassword');
3 if (!$link) {
4 die('Could not connect to MySQL: ' . mysql_error());
5}
6 echo 'Connection OK'; mysql_close($link);
7 ?>
54