Test.java
1.8 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
package tools;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import login.FJSON;
import login.InfoData;
import login.InterfaceData;
import login.LoginData;
import login.Security;
public class Test {
public static void main(String args[]) throws IOException{
String param = "ssid=5672813&data=";
/*System.out.println("key:"+Security.getKey());
System.out.println("加密前:"+JSONObject.toJSONString(id));
System.out.println("加密后:"+data);
param = param + data;*/
//固定写法
InterfaceData id = new InterfaceData();
id.setKey("owenkasduf");
id.setType("2");
//填充用户信息
id.setUsername("wangshan");
id.setPwd("123456");
//加密数据
String data = Security.encrypt(JSONObject.toJSONString(id), Security.getKey());
//将加密的数据添加到参数中
Map<String, String> map = new HashMap<String, String>();
map.put("ssid", "5672813"); map.put("data", data);
//发送登录请求
String str = HttpTools.sendPost("http://www.zzcargo.com/index.php?r=api/index", map, "UTF-8");
//解析登录
LoginData logindata = new LoginData();
//将返回的消息转换成对象
FJSON.JsonToObject(logindata, str);
//登录成功
if(logindata.getCode() == 2000)
{
//解密返回的io字段
String responseText = Security.decrypt(logindata.getInfo(), Security.getKey());
InfoData infoData = new InfoData();
//将json字符串转换成对象
FJSON.JsonToObject(infoData, responseText);
}
//String str = HttpRequest.sendPost("http://10.50.2.24/index.php?r=api/index", param);
//String str = HttpRequest.sendPost("http://www.zzcargo.com/index.php?r=api/index", param);
//String str = HttpTools.sendPost("http://www.zzcargo.com/index.php?r=api/index", param, null);
}
}