package test; import idNoUtils.IdNo; import java.io.IOException; import java.util.HashMap; import org.json.JSONObject; import org.testng.annotations.Test; import com.al.api.net.Http; import com.al.api.test.base.APIBase; import com.al.core.annotation.DataFactory; import com.al.core.nassert.NAssert; import com.al.core.report.NReporter; import common.BankCard; import test.HashMapObject; @DataFactory(dataPathKey= "DataPath") public class OpenData extends APIBase{ // 寧波銀行 ("621279", "16") 7600 中國銀行("623040", "16") 5300 String mobile = "13536703795"; String bankCode = "5300"; String cardbin = "623040"; String cardlength = "16"; String vcode = "123456"; String id = ""; String publicKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDEq8eU4xQtq7f9hyWulOtzKClrbiCQuTQ8cq+jlqV6UqLllxWUe7O2qFsxGznmOrW5tyIXUuLbNUj+Gcq0+jgSl7rOqw1sEXkjvq3oujr7c5RUvaLgsSUhqmTyQlqIudPL7tHKfGr6TIMdV9s7CZ+e1YF6XpPbv7MwmCoM4rkVSQIDAQAB"; //發�1�7�短信驗證碼 @Test public void sendSms(){ Http hf = Http.newInstance("10.17.171.11",8080); //請求入參賦�1�7�1�7 HashMap<String,String> input = new HashMap<String,String>(); input.put("serviceKey", "sendSms"); input.put("mobile", mobile); input.put("imgCode", ""); input.put("codeType", "0"); //發起post請求 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); } //驗證短信驗證碼成劄1�7 @Test(dependsOnMethods="sendSms") public void vSmsCode( ){ Http hf = Http.newInstance("10.17.171.11",8080); //發�1�7�短信驗證碼請求入參賦�1�7�1�7 HashMap<String, String> params = new HashMap<String, String>(); params.put("mobile", mobile); //請求入參對象封裝 HashMap<String, String> input = new HashMap<String, String>(); params = HashMapObject.parameter(params); //驗證短信驗證碼請求入參賦倄1�7 input.put("serviceKey","vSmsCode"); input.put("mobile",params.get("mobile")); input.put("vcode",vcode); input.put("codeType",params.get("codeType")); input.put("sVersion",params.get("sVersion")); input.put("loginFlag",params.get("loginFlag")); input.put("h5RecommenderNoId",params.get("h5RecommenderNoId")); input.put("pinion_recommender_code",params.get("pinion_recommender_code")); input.put("pinion_recommender_name",params.get("pinion_recommender_name")); input.put("version_recommender_name",params.get("version_recommender_name")); input.put("appPlatform",params.get("appPlatform")); //驗證短信驗證碼的請求 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); NAssert.assertNotNull(jo.getJSONObject("data").get("user_id")); id = (String) jo.getJSONObject("data").get("user_id"); } //上傳身份證正靄1�7 @Test(dependsOnMethods="vSmsCode") public void uploadIdpicurl(){ Http hf = Http.newInstance("10.17.171.11",8080); //入參賦�1�7�1�7 flist[0].base64Data HashMap<String, String> input = new HashMap<String, String>(); input.put("serviceKey","saveUserMaterial"); input.put("userId",id); input.put("channel","jykh"); input.put("flist[0].fileType","3"); //生成圖片base64砄1�7 String imageName ="photo.jpg"; try { String imgbese = ImageTranscoding.imageToBase64(imageName); input.put("flist[0].base64Data",imgbese); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //發起post請求 hf.post(conf.get("oasDomain") + "oas/restapi/material",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); //---------------------------------------------- input.replace("flist[0].fileType", "4"); //生成圖片base64砄1�7 imageName ="idpicurl.jpg"; try { String imgbese = ImageTranscoding.imageToBase64(imageName); input.replace("flist[0].base64Data",imgbese); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //發起post請求 hf.post(conf.get("oasDomain") + "oas/restapi/material",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject joa = new JSONObject(hf.getResponse()); NAssert.assertEquals(joa.getString("responseCode"),"0"); //---------------------------------------------- input.replace("flist[0].fileType", "5"); //生成圖片base64砄1�7 imageName ="idpicurlBack.jpg"; try { String imgbese = ImageTranscoding.imageToBase64(imageName); input.replace("flist[0].base64Data",imgbese); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } //發起post請求 hf.post(conf.get("oasDomain") + "oas/restapi/material",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject job = new JSONObject(hf.getResponse()); NAssert.assertEquals(job.getString("responseCode"),"0"); } //提交併確認我的信恄1�7 @Test(dependsOnMethods="uploadIdpicurl") public void submitUserInfo(){ Http hf = Http.newInstance("10.17.171.11",8080); // HashMap<String, String> input = new HashMap<String, String>(); input.put("id", id ); input.put("idno", IdNo.idNo() ); input.put("serviceKey" ,"saveUserInfo"); input.put("infocolect_channel" ,"3"); input.put("idtype" ,"00"); input.put("custname" ,"自動"); input.put("borthday" ,"1978-05-28"); input.put("idbegindate" ,"2006-07-28"); input.put("idenddate" ,"2025-07-28"); input.put("nativeAddr" ,"自動化測試盧灣區淡春樹裏頂頂替磚石"); input.put("policeorg" ,"上肅市公安局盧壽分局"); input.put("usersex" ,"1"); input.put("nationality" ,"156"); input.put("addr" ,"自動化測試盧灣區淡春樹裏頂頂替磚石"); input.put("postid" ,"520000"); input.put("edu" ,"博士"); input.put("branchno" ,"8888"); input.put("provinceno" ,"03"); input.put("cityno" ,""); input.put("ipaddr" ,""); input.put("macaddr" ,""); input.put("recommender_name" ,"恭喜發財"); input.put("recommender_idno" ,"8888888"); input.put("profession" ,"99"); input.put("profession_code" ,"03"); input.put("accountBeneficiary" ,"1"); input.put("actualController" ,"1"); input.put("creditRecord" ,"00"); input.put("taxPayer" ,"1"); input.put("appropriate_flag" ,"1"); //發起post請求 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); } //提交股東戶開通申評1�7 @Test(dependsOnMethods="submitUserInfo") public void saveStepStatus( ){ Http hf = Http.newInstance("10.17.171.11",8080); //手機短信驗證請求入參賦�1�7�1�7 HashMap<String, String> input = new HashMap<String, String>(); input.put("serviceKey","saveStepStatus"); input.put("userId",id); input.put("szaStr","1"); input.put("shaStr","1"); //提交股東戶開通申請請汄1�7 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); } //設置密碼 @Test(dependsOnMethods="saveStepStatus") public void findLoadAccount( ){ Http hf = Http.newInstance("10.17.171.11",8080); //手機短信驗證請求入參賦�1�7�1�7 HashMap<String, String> input = new HashMap<String, String>(); input.put("serviceKey", "setTCPassword"); input.put("userId", id); input.put("fundPwd", rsaUtils.EncryptPwd.testEncryptPwd("123123", publicKey)); input.put("tradePwd", rsaUtils.EncryptPwd.testEncryptPwd("123123", publicKey) ); //post請求 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); } //銀行卡綁宄1�7 @Test(dependsOnMethods="findLoadAccount") public void bindBank( ){ Http hf = Http.newInstance("10.17.171.11",8080); //生成民生銀行卄1�7 String bankAcct = BankCard.generateBankCard(cardbin,cardlength); NReporter.info("銀行卡號$1�7 "+ bankAcct); //請求入參封裝 HashMap<String,String> input = new HashMap<String,String>(); input.put("serviceKey", "bindTpBank" ); input.put("userId", id ); input.put("bankAcct", bankAcct ); input.put("fndacct", "" ); input.put("bankCode", bankCode); input.put("bankPwd", "123456"); input.put("opType", "0"); //post請求 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); } //提交風險測評答案 @Test(dependsOnMethods="bindBank") public void saveRiskResult( ){ Http hf = Http.newInstance("10.17.171.11",8080); //手機短信驗證請求入參賦�1�7�1�7 HashMap<String, String> input = new HashMap<String, String>(); input.put("serviceKey", "saveRiskResult"); input.put("ratingValue", "3;3;3;3;3;3;3;3,;3;3;3;"); input.put("userId", id); //post請求 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); } //提交問卷回訪答案 @Test(dependsOnMethods="saveRiskResult") public void visitsurveyFlag( ){ Http hf = Http.newInstance("10.17.171.11",8080); //手機短信驗證請求入參賦�1�7�1�7 HashMap<String, String> input = new HashMap<String, String>(); input.put("serviceKey", "visitsurveyFlag"); input.put("userId", id); //post請求 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0"); } //同步我的信息 @Test(dependsOnMethods="visitsurveyFlag") public void endPageDo(){ Http hf = Http.newInstance("10.17.171.11",8080); //請求入參封裝 HashMap<String, String> input = new HashMap<String, String>(); input.put("serviceKey", "endPageDo" ); input.put("userId", id ); //post請求 hf.post(conf.get("oasDomain") + "oas/restapi/service",input); //校驗請求響應砄1�7 NReporter.saveJSON(hf.getRequest(), hf.getResponse()); NAssert.assertEquals(hf.getStatus(), 200); //校驗接口響應 JSONObject jo = new JSONObject(hf.getResponse()); NAssert.assertEquals(jo.getString("responseCode"),"0","同步信息成功"); } }