Commit 3fe2f2e2 by Li Yongyu

Merge branch 'master' of

git@gitlab.eoffcn.com:ys65701/nwn_Api_auto_test.git

Conflicts:
	nwn_Api_auto_test/src/DefectTest.xml
parents d070efd9 c2745fc8
......@@ -6,7 +6,7 @@
<classes>
<class name="com.puhui.test.RenMai_APITest">
<methods>
<include name="f" invocation-numbers="0 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 "/>
<include name="f" invocation-numbers="0 1 2 3 4 5 6 "/>
</methods>
</class>
</classes>
......
package com.offcn.TestUnti;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;
import java.util.Map;
public class HttpRequest {
/**
* 向指定URL发送GET方法的请求
*
* @param url
* 发送请求的URL
* @param param
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return URL 所代表远程资源的响应结果
*/
public static void main(String[] args) {
String s=HttpRequest.sendGet("http://beta.alitest.eoffcn.com/template/addStuden/sign/5d114486999208096dace001ae4bc45a",
"user_info=[{\"package_id\":391634,\"username\":\"aaa\",\"phone\":15656333337,\"sso_id\":1}]&timestamp=1548828632&appid=jiaowu");
try {
String s1=new String(s.getBytes(),"utf-8");
System.out.println(s1);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
public static String sendGet(String url, String param) {
String result = "";
BufferedReader in = null;
try {
// String urlNameString = url ;
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打开和URL之间的连接
URLConnection connection = realUrl.openConnection();
// 设置通用的请求属性
connection.setRequestProperty("Authorization", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NSwicGhvbmUiOiIxODUxMTg1MjA0OSIsImlhdCI6MTQ4NzEzMjU0OX0.2aZ8FcfE52CYpXc4VUYjdfzzLzXwVOE-J8CnMlhUPic");
connection.setRequestProperty("Content-Type", "application/json");
// 建立实际的连接
connection.connect();
// 获取所有响应头字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍历所有的响应头字段
for (String key : map.keySet()) {
System.out.println(key + "--->" + map.get(key));
}
// 定义 BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
// o.write(line+"\r\n");
result += line;
result += "\r\n";
}
// o.close();
} catch (Exception e) {
System.out.println("发送GET请求出现异常!" + e);
e.printStackTrace();
}
// 使用finally块来关闭输入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
/**
* 向指定 URL 发送POST方法的请求
*
* @param url
* 发送请求的 URL
* @param param
* 请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
* @return 所代表远程资源的响应结果
*/
public static String sendPost(String url, String param) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打开和URL之间的连接
URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性
conn.setRequestProperty("Authorization", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NSwicGhvbmUiOiIxODUxMTg1MjA0OSIsImlhdCI6MTQ4NzEzMjU0OX0.2aZ8FcfE52CYpXc4VUYjdfzzLzXwVOE-J8CnMlhUPic");
conn.setRequestProperty("Content-Type", "application/json");
// 发送POST请求必须设置如下两行
conn.setDoOutput(true);
conn.setDoInput(true);
// 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream());
// 发送请求参数
out.print(param);
// flush输出流的缓冲
out.flush();
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
result += "\r\n";
}
} catch (Exception e) {
System.out.println("发送 POST 请求出现异常!"+e);
e.printStackTrace();
}
//使用finally块来关闭输出流、输入流
finally{
try{
if(out!=null){
out.close();
}
if(in!=null){
in.close();
}
}
catch(IOException ex){
ex.printStackTrace();
}
}
return result;
}
}
\ No newline at end of file
......@@ -667,7 +667,6 @@ public class RequestDataUtils {
return re;
}
@SuppressWarnings("static-access")
public static Response Get_one_cookie_pre(HashMap<String, Object> data,
String serviceURL,
......@@ -837,4 +836,5 @@ public class RequestDataUtils {
}
return re;
}
}
......@@ -33,7 +33,7 @@ public class nwngetsign {
str = str + "bf2h3%^j?ljkj3706kji88697"; //教务的加密,规则固定需要加
System.out.println("str===" + str);
NWN.suprise_str = str;
//String str1 = "appid=tiku&avatar=http://thirdqq.qlogo.cn/qqapp/1106773681/5B50BBF83A00DC46B16B708F720A5D46/100&device_id=861837034477409&login_type=qq&nickname=hobo&open_id=1&platform=Android&version=1"+"&123456";
String res = new LMFMD5().MD5(str);
System.out.println("res===" +res);
......
......@@ -4,6 +4,7 @@ package com.offcn.api.nwn.service;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import java.io.UnsupportedEncodingException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
......@@ -15,16 +16,17 @@ import java.util.Random;
import org.json.simple.JSONArray;
import com.offcn.TestUnti.HttpRequest;
import com.offcn.TestUnti.Log;
import com.offcn.TestUnti.MapUtil;
import com.offcn.TestUnti.RequestDataUtils;
import com.offcn.TestUnti.StringUtils;
import com.offcn.api.nwn.md5.nwngetsign;
import com.offcn.interfaces.API;
import com.offcn.process.NWN;
import com.offcn.process.TK;
import com.offcn.TestUnti.ListUtil;
import net.sf.json.JSONObject;
......@@ -40,6 +42,7 @@ public class addStuden extends NWN implements API {
public String template_id_1;//母板ID
public String response;//返回结果
// public String phone;//层级包id
@Override
public void initialize(HashMap<String, Object> data) {
......@@ -76,20 +79,30 @@ public class addStuden extends NWN implements API {
// Map<String,String> m=new HashMap<String,String>();
// m.put("user_info", parameter);
//Response re = RequestDataUtils.Post_cooike_form_data(data, Url,"PHPSESSID",PHPSESSID,m);
Response re = RequestDataUtils.Get_one_cookie_pre(data, Url, "PHPSESSID",PHPSESSID);
//Response re = RequestDataUtils.Get_one_cookie(data, serviceURL, cookie1Name, cookie1value) //只能无参
// Response re = RequestDataUtils.Get_token(data, Url, "");
return re;
// Response re = RequestDataUtils.Get_one_cookie_pre(data, Url, "PHPSESSID",PHPSESSID);
//response=HttpRequest.sendGet("http://beta.alitest.eoffcn.com/template/addStuden/sign/5d114486999208096dace001ae4bc45a",
// "user_info=[{\"package_id\":391634,\"username\":\"aaa\",\"phone\":15656333337,\"sso_id\":1}]&timestamp=1548828632&appid=jiaowu");
System.out.println("parameter====" + parameter);
System.out.println("url===" + Url);
response=HttpRequest.sendGet("http://beta.alitest.eoffcn.com"+Url,parameter);
try {
String s1=new String(response.getBytes(),"utf-8");
System.out.println(s1);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}
@Override
public String handleOutput(Response re, HashMap<String, Object> data) {
JsonPath jp = re.body().jsonPath();
JsonPath jp = new JsonPath(response);
System.out.println( "jp===="+ jp);
boolean result = true;
String failReason = "";
String json = re.asString();
String json = response;
System.out.println("response=========="+StringUtils.decodeUnicode(json));
if ((data.get("statusCode") != null)
......
......@@ -47,6 +47,7 @@ public class NWN extends BasicsGM{
public static List<String> user_id_List = new ArrayList<String>();//user_id
public static String template_id = "";
public static String timestamp;//时间戳
public static String suprise_str;//特殊字符
// public static String phone_code = "";//手机号验证码
//
//
......
......@@ -99,13 +99,18 @@ public class APITest_nwn extends NWN{
if(data.get("Description").toString().contains("流程")){
result = obj.handleOutput(re, data);
}
}else{
result = obj.handleOutput(re, data);
}
codeORerrcode=getCode(re);
msgORerrmsy=getMsg(re);
// else{
// result = obj.handleOutput(re, data);
// }
// codeORerrcode=getCode(re);
// msgORerrmsy=getMsg(re);
}
result = obj.handleOutput(re, data);
codeORerrcode=getCode(re);
msgORerrmsy=getMsg(re);
Log.logInfo("返回结果="+StringUtils.decodeUnicode(body));
System.out.println();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment