-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathexecuteLowLevelAPI.java
More file actions
102 lines (70 loc) · 4.3 KB
/
executeLowLevelAPI.java
File metadata and controls
102 lines (70 loc) · 4.3 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
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class executeLowLevelAPI {
private final String USER_AGENT = "Mozilla/5.0";
public static void main(String[] args) throws Exception {
String device = Constants.PM_DEVICE;
executeLowLevelAPI http = new executeLowLevelAPI();
http.smsME("hello",device);
}
public void smsME(String text,String Device)throws Exception
{
String execID = getExecID(Constants.PM_CLOUD,Constants.PM_USER,Constants.PM_PASSWORD);
String cmd = "https://"+Constants.PM_CLOUD+"/services/executions/"+execID+"?user="+Constants.PM_USER+"&password="+Constants.PM_PASSWORD+"&operation=command&command=gateway&subcommand=sms¶m.body="+text+"¶m.to.handset="+Device;
String res = htmlcall (cmd);
closeSession(execID);
}
public void callMe(String text,String Device)throws Exception
{
// <action command="gateway" subcommand="call" error-policy="CONTINUE">
String execID = getExecID(Constants.PM_CLOUD,Constants.PM_USER,Constants.PM_PASSWORD);
String cmd = "https://"+Constants.PM_CLOUD+"/services/executions/"+execID+"?user="+Constants.PM_USER+"&password="+Constants.PM_PASSWORD+"&operation=command&command=gateway&subcommand=call¶m.to.handset="+Device;
String res = htmlcall (cmd);
closeSession(execID);
}
public void closeSession(String execID) throws Exception
{
String closeURL = "https://"+Constants.PM_CLOUD+"/services/executions/"+execID+"?user="+Constants.PM_USER+"&password="+Constants.PM_PASSWORD+"&operation=end";
String res = htmlcall (closeURL);
}
public String getExecID(String cloud,String user,String Password) throws Exception
{
String openurl = "https://"+cloud+"/services/executions?user="+user+"&password="+Password+"&operation=start";
String res = htmlcall (openurl);
int start = res.indexOf("\":\"")+3;
int end = res.indexOf("\",\""); ;
System.out.println(res);
String execID = res.substring(start, end);
System.out.println(execID);
return execID;
}
public String htmlcall(String url) throws Exception
{
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
// optional default is GET
con.setRequestMethod("GET");
//add request header
con.setRequestProperty("User-Agent", USER_AGENT);
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " + url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
response.append("\n");
}
in.close();
//print result
return response.toString();
}
}