1
|
package com.xkl;
|
1
|
package com.xkl;
|
2
|
|
2
|
|
|
|
3
|
+import org.json.JSONObject;
|
3
|
import org.junit.Test;
|
4
|
import org.junit.Test;
|
4
|
|
5
|
|
5
|
import java.util.HashMap;
|
6
|
import java.util.HashMap;
|
|
@@ -11,9 +12,13 @@ import java.util.Map; |
|
@@ -11,9 +12,13 @@ import java.util.Map; |
11
|
public class OpenIdTest {
|
12
|
public class OpenIdTest {
|
12
|
private static final String URL_OPEN_ID = Constants.URL_PREFIX + "/openId";
|
13
|
private static final String URL_OPEN_ID = Constants.URL_PREFIX + "/openId";
|
13
|
private static final String URL_LOGIN = Constants.URL_PREFIX + "/openId/login";
|
14
|
private static final String URL_LOGIN = Constants.URL_PREFIX + "/openId/login";
|
14
|
-
|
15
|
+ private static final String URL_COMPARE = Constants.URL_PREFIX + "/report/compare";
|
15
|
@Test
|
16
|
@Test
|
16
|
public void testBind(){
|
17
|
public void testBind(){
|
|
|
18
|
+ bindWithOpenIdAndUser();
|
|
|
19
|
+ }
|
|
|
20
|
+
|
|
|
21
|
+ public static String bindWithOpenIdAndUser(){
|
17
|
Map<String,String> params = new HashMap<String, String>();
|
22
|
Map<String,String> params = new HashMap<String, String>();
|
18
|
params.put("username","user1");
|
23
|
params.put("username","user1");
|
19
|
params.put("password",EncodeTools.encode("MD5","pass1"));
|
24
|
params.put("password",EncodeTools.encode("MD5","pass1"));
|
|
@@ -24,7 +29,7 @@ public class OpenIdTest { |
|
@@ -24,7 +29,7 @@ public class OpenIdTest { |
24
|
params.put("type","1");
|
29
|
params.put("type","1");
|
25
|
params.put("sign",HttpTools.getSign(params));
|
30
|
params.put("sign",HttpTools.getSign(params));
|
26
|
String response = HttpTools.requestByMap(URL_OPEN_ID,"POST",params);
|
31
|
String response = HttpTools.requestByMap(URL_OPEN_ID,"POST",params);
|
27
|
- System.out.println(response);
|
32
|
+ return response;
|
28
|
}
|
33
|
}
|
29
|
|
34
|
|
30
|
@Test
|
35
|
@Test
|
|
@@ -44,14 +49,36 @@ public class OpenIdTest { |
|
@@ -44,14 +49,36 @@ public class OpenIdTest { |
44
|
|
49
|
|
45
|
@Test
|
50
|
@Test
|
46
|
public void testLogin(){
|
51
|
public void testLogin(){
|
|
|
52
|
+ System.out.println(bindWithOpenIdAndLoginAndGetToken("abcdefghijklmnopqrstuvwxyz123456","0"));
|
|
|
53
|
+ }
|
|
|
54
|
+
|
|
|
55
|
+ public static String bindWithOpenIdAndLoginAndGetToken(String openId, String openIdType){
|
|
|
56
|
+ bindWithOpenIdAndUser();
|
47
|
Map<String,String> params = new HashMap<String, String>();
|
57
|
Map<String,String> params = new HashMap<String, String>();
|
48
|
- params.put("openId","abcdefghijklmnopqrstuvwxyz123456");
|
|
|
49
|
- params.put("openIdType","0");
|
58
|
+ params.put("openId",openId);
|
|
|
59
|
+ params.put("openIdType",openIdType);
|
50
|
|
60
|
|
51
|
params.put("t",HttpTools.getNow());
|
61
|
params.put("t",HttpTools.getNow());
|
52
|
params.put("type","1");
|
62
|
params.put("type","1");
|
53
|
params.put("sign",HttpTools.getSign(params));
|
63
|
params.put("sign",HttpTools.getSign(params));
|
54
|
String response = HttpTools.requestByMap(URL_LOGIN,"POST",params);
|
64
|
String response = HttpTools.requestByMap(URL_LOGIN,"POST",params);
|
|
|
65
|
+
|
|
|
66
|
+ System.out.println("response:"+ response);
|
|
|
67
|
+ JSONObject jsonObject = new JSONObject(response);
|
|
|
68
|
+ JSONObject content = jsonObject.getJSONObject("content");
|
|
|
69
|
+ return content.getString("userId") + "_" + content.getString("token");
|
|
|
70
|
+ }
|
|
|
71
|
+
|
|
|
72
|
+ @Test
|
|
|
73
|
+ public void testCompare(){
|
|
|
74
|
+ String token = bindWithOpenIdAndLoginAndGetToken("abcdefghijklmnopqrstuvwxyz123456","0");
|
|
|
75
|
+ Map<String,String> params = new HashMap<String, String>();
|
|
|
76
|
+ params.put("report_id","1");
|
|
|
77
|
+
|
|
|
78
|
+ params.put("t",HttpTools.getNow());
|
|
|
79
|
+ params.put("type","1");
|
|
|
80
|
+ params.put("sign",HttpTools.getSign(params));
|
|
|
81
|
+ String response = HttpTools.requestByMapWithToken(URL_COMPARE,"POST",params,token);
|
55
|
System.out.println(response);
|
82
|
System.out.println(response);
|
56
|
}
|
83
|
}
|
57
|
} |
84
|
} |