/
JAVA
65 lines (60 loc) · 3.66 KB
/
JAVA
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
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package demo;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import static org.apache.commons.codec.digest.DigestUtils.md5;
/**
*
*
*/
public class smsGateway {
public static void main(String[] args) {
/*
- Id: là message_id là số định danh cho 1 tin nhắn lên của khách hàng (id=0 là tin nhắn test từ hệ thống của VTDD) (is message_id is the identifier for a customer message (id = 0 is the test message from VTDD's system))
- Phone: là số điện thoại khách hàng (is the customer phone number)
- Shortcode: là đầu số mà khách hàng nhắn lên (is the number that the customer message)
- Gateway: là định danh cho nhà mạng (is the identifier for the operator)
- Sms: là nội dung tin nhắn của khách hàng nhắn lên. Tin nhắn phải được mã hóa hexa để loại trừ các trường hợp trong tin nhắn có ký tự đặc biệt không gửi qua webservices được. (is the content of a customer's message. The message must be hexadecoded to exclude the cases in which the special character message cannot be sent through webservices.)
- Checksum: là trường để tăng tính bảo mật cho web services. Hai bên thỏa thuận với nhau 1 key ví dụ “xxxxxxxxxx”. Công thức tính checksum là: (is a field to increase the security of web services. The two parties agree to each other a key for example "xxxxxxxxxx". The formula for calculating the checksum is:)
- checksum = MD5("xxxxxxxxxx "+Id+Phone+Shortcode+sms) Khi bên VTDD truyền tham số qua, bên ĐỐI TÁC kiểm tra lại xem checksum có hợp lệ không trước khi xử lý (When VTDD side passes the parameter, PARTNER checks if the checksum is valid before processing.)
*/
int id = 0;
String phone = "";
String shortcode = "";
String sms = ""; //Tin nhắn phải được mã hóa hexa
byte[] checksum = md5("xxxxxxxxxx " + id + phone + shortcode + sms);//trong đó xxxxxxxxxx : Hai bên thỏa thuận với nhau 1 key ví dụ “xxxxxxxxxx”
String gateway = "";
String link_get = "http://doitac.com/vtddsms/";
String content = link_get + "?id=" + id + "&phone=" + phone + "&shortcode=" + shortcode + "&gateway=" + gateway + ""
+ "&sms=" + sms + "&checksum=" + checksum + "";
System.out.println(content);
System.out.println(request(content));
}
public static String request(String urlget) {
String inputLine = "";
try {
URL u = new URL(urlget);
HttpURLConnection yc = (HttpURLConnection) u.openConnection();
yc.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.155 Safari/537.36");
yc.setRequestProperty("Accept-Charset", "UTF-8");
//yc.setRequestProperty("Accept-Charset", "UTF-8");
yc.setConnectTimeout(30 * 1000);
BufferedReader in = new BufferedReader(new InputStreamReader(
yc.getInputStream(), "UTF-8"));
inputLine = in.readLine();
} catch (Exception ex) {
System.out.println("Loi: " + ex.getMessage());
ex.printStackTrace();
inputLine = "-1";
} finally {
System.out.println(inputLine);
return inputLine;
}
}
}