FLogin.java
2.2 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
package login;
import java.util.HashMap;
import java.util.Map;
import com.agent.entity.system.UserEntity;
import com.alibaba.fastjson.JSONObject;
import tools.HttpTools;
public class FLogin {
public static LoginData login(UserEntity user){
LoginData logindata = new LoginData();
InfoData info = new InfoData();
String param = "ssid=5672813&data=";
InterfaceData id = new InterfaceData();
id.setKey("owenkasduf");
//id.setUsername("wangshan");
//id.setPwd("123456");
id.setUsername(user.getLoginaccount());
id.setPwd(user.getPassword());
id.setType("2");
//System.out.println(Security.getKey());
//构造请求数据包(并且加密data数据)
String data = Security.encrypt(JSONObject.toJSONString(id), Security.getKey());
param = param + data;
System.out.println(param);
//发送登录消息
//String receive = HttpRequest.sendPost("http://10.50.2.24/index.php?r=api/index", param);
//String receive = HttpRequest.sendPost("http://10.50.2.20/index.php?r=api/index", param);
//String receive = HttpRequest.sendPost("http://www.zzcargo.com/index.php?r=api/index", param);
Map<String, String> map = new HashMap<String, String>();
map.put("ssid", "5672813");
map.put("data", data);
String receive = HttpTools.sendPost("http://www.zzcargo.com/index.php?r=api/index", map, "UTF-8");
///index.php?r=site/login
System.out.println(receive);
try{
//转换接收到的数据
FJSON.JsonToObject(logindata, receive);
//验证通过
if(logindata.getCode() == 20000)
{
//对传回的数据解密
String raw = Security.decrypt(logindata.getInfo(), Security.getKey());
//show message
//System.out.println(raw);
logindata.setInfo(raw);
//将解密后的数据转回json
FJSON.JsonToObject(info, logindata.getInfo());
logindata.setInfodata(info);
}
}catch(Exception e){
//数据返回异常
logindata.setCode(0);
}
//测试的数据
// InfoData id = new InfoData();
//
// id.setMobile("fadf");
// id.setCompany_info("flasdjf");
// id.setQq("fasdf");
// id.setContact("fffffffff");
// id.setAddress("fafda");
// id.setCompany("fafdadf");
// logindata.setCode(20000);
// logindata.setInfodata(id);
return logindata;
}
}