-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathMessageClient.java
More file actions
153 lines (113 loc) · 3.32 KB
/
Copy pathMessageClient.java
File metadata and controls
153 lines (113 loc) · 3.32 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
package pl.smsapi;
import pl.smsapi.message.Mms;
import pl.smsapi.message.Result;
import pl.smsapi.message.Sms;
import pl.smsapi.message.Account;
import pl.smsapi.message.Message;
import pl.smsapi.message.MessageInterface;
import pl.smsapi.message.Phonebook;
import pl.smsapi.message.Vms;
import pl.smsapi.sender.SenderHttp;
public final class MessageClient {
private static String username = null;
private static String password = null;
private static boolean auth = true;
public static boolean getAuth(){
return auth;
}
public static void setAuth(boolean val){
auth = val;
}
public static String getUsername() {
return username;
}
public static void setUsername(String username) {
MessageClient.username = username;
}
public static String getPassword() {
return password;
}
public static void setPassword(String password) {
MessageClient.password = password;
}
public static void setPassword(String password, boolean encodeMd5) {
if(encodeMd5 == true){
MessageClient.password = Message.MD5Digest(password);
}else{
MessageClient.password = password;
}
}
public static void main(String[] args) {
try {
if (args.length < 5) {
throw new SmsapiException("No exist args");
}
Sms sms = MessageClient.getSmsInstance();
sms.setUsername(args[0]);
sms.setPassword(args[1]);
String[] partsTo = args[2].split(",");
for (String phone : partsTo) {
sms.addTo(phone);
}
if (args[3].equals("eco")) {
sms.setEco(true);
}
sms.setMessage(args[4]);
sms.send();
for (Result result : sms.getResults()) {
System.out.println("start---------------------------");
System.out.println("Response http: " + result.getResponse());
System.out.println("Status: " + result.getStatus());
System.out.println("Error: " + result.getError());
System.out.println("Id: " + result.getId());
System.out.println("Points: " + result.getPoints());
System.out.println("Phone: " + result.getPhone());
System.out.println("end-----------------------------");
}
} catch (IllegalArgumentException ex) {
System.out.println(ex.getMessage());
} catch (SmsapiException ex) {
System.out.println(ex.getMessage());
}
}
private static void setDataAuth(MessageInterface message){
if(auth == true && (username != null && !username.isEmpty()) && (password != null && !password.isEmpty())){
message.setUsername(username);
message.setPassword(password);
}
}
public static Sms getSmsInstance() {
SenderHttp sender = new SenderHttp();
Sms sms = new Sms(sender);
setDataAuth(sms);
return sms;
}
public static Mms getMmsInstance() {
SenderHttp sender = new SenderHttp();
Mms mms = new Mms(sender);
setDataAuth(mms);
return mms;
}
public static Vms getVmsInstance() {
SenderHttp sender = new SenderHttp();
Vms vms = new Vms(sender);
setDataAuth(vms);
return vms;
}
public static Account getAccountInstance() {
SenderHttp sender = new SenderHttp();
Account account = new Account(sender);
setDataAuth(account);
return account;
}
public static Phonebook getPhonebookInstance() {
SenderHttp sender = new SenderHttp();
Phonebook phonebook = new Phonebook(sender);
//setDataAuth(phonebook);
return phonebook;
}
public static SenderHttp getSenderHttp() {
SenderHttp sender = new SenderHttp();
return sender;
}
}