2. 新建lr腳本,選擇Java vuser協議;
3. Run-time Settings中Classpath設置jar包,沒用的jar包一概刪除,或不選擇,不然會出現錯誤;而後添加Java腳本所須要的jar包;
4. jar能夠放在Java vuser根目錄,直接使用;
5. 寫Java腳本,調試。
6. controller中併發時,使用Run Vuser as a process模式併發。
import com.p2p.test.*;
import lrapi.lr;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class Actions
{
public static HttpClient httpClient = new HttpClient();
public int init() throws Throwable {
return 0;
}//end of init
public int action() throws Throwable {
// HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod(
//http://172.30.1.44:8899/entruSettleNotify
//http://10.7.3.94:8899/frontAPI/entruSettleNotify
"http://172.30.1.44:8899/entruSettleNotify");//http://172.30.1.44:8899/entruSettleNotify http://10.7.3.94:8899/frontAPI/entruSettleNotify
// 設置用戶瀏覽器爲MicrosoftIE6.0
postMethod.setRequestHeader("User-Agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
// 設置編碼
postMethod.getParams().setParameter(
HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
// 設置請求參數
//String BatchNo = "20140707109257829643";
//String childBatchNo = "140387";
String reid = "2233344450"; // 還款用 要改
try{
String xmldsES0003="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<message xmlns=\"http://www.w3school.com.cn\"> "
+ "<head> "
+ "<version>01</version> "
+ "<type>0002</type> "
+ "<channelNo>HM</channelNo> "
+ "<tradDate>20140515</tradDate> "
+ "<tradTime>141558</tradTime> "
+ "<tradFlowNo>ES000320140515100591</tradFlowNo> "
+ "<tradNo>ES0003</tradNo> "
+ "</head> "
+ "<body> "
+ "<merchantNo>1092</merchantNo> "
//20140712109264712593
//20140712109289216534
+ "<batchNo>20140715109258670149</batchNo> " // 要改
+ "<submitDate>790538</submitDate> "
+ "<batchStatus>06</batchStatus> "
+ "<batchUse>01</batchUse> "
+ "<batchRemark></batchRemark> "
+ "<batchSumCount>1</batchSumCount> "
+ "<batchSumAmt>100</batchSumAmt> " // 要改
+ "<batchSumSuccCount>0</batchSumSuccCount> "
+ "<batchSumSuccAmt>0.00</batchSumSuccAmt> "
+ "<list name=\"batchList\"> "
+ "<row> "
//961754
//160759
+ "<childBatchNo>578936</childBatchNo> " // 要改
//102100009545
//305100001057
+ "<cnaps>102100009545</cnaps> "
+ "<bankAcc>1</bankAcc> "
+ "<rcvName>1</rcvName> "
+ "<acctAttribute>02</acctAttribute> "
//中國工商銀行股份有限公司北京玉林支行
//中國民生銀行股份有限公司北京中關村支行
+ "<branchName>中國工商銀行股份有限公司北京玉林支行</branchName> "
+ "<branchProvince></branchProvince> "
+ "<branchCity></branchCity> "
+ "<branchSite></branchSite> "
+ "<amount>100</amount> " // 要改
+ "<currencyType>CNY</currencyType> "
+ "<state>02</state> "
+ "<procTime>20140515131232</procTime> "
+ "<remark>轉帳成功</remark> "
+ "</row> "
+ "</list> "
+ "</body>"
+ "</message>";
String xmldsES0006="<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
+ "<message xmlns=\"http://www.w3school.com.cn\"> "
+ "<head> "
+ "<version>01</version> "
+ "<type>0002</type> "
+ "<channelNo>HM</channelNo> "
+ "<tradDate>20140613</tradDate> "
+ "<tradTime>105500</tradTime> "
+ "<tradFlowNo>ES000620140410100821</tradFlowNo> "
+ "<tradNo>ES0006</tradNo> "
+ "</head> "
+ "<body> "
+ "<rechargeId>"+reid+"</rechargeId> "
+ "<merchantNo>1054</merchantNo> "
+ "<balanceId>161</balanceId> "
+ "<rechargeAmt>1003315.07</rechargeAmt> "
+ "<tradeDate>20140621</tradeDate> "
+ "<state>1</state> "
+ "<businessType>2</businessType> "
+ "<info>161</info> "
+ "<remark>161</remark> "
+ "</body>"
+ "</message>";
String xmlds = xmldsES0003;//xmldsES0003; //要改
//
String aa = xmlds+"111111";
String mac=DigestUtils.md5Hex(aa);
// System.out.println("上送報文:"+xmlds);
// System.out.println("上送摘要:"+mac);
postMethod.addParameter("tradNo","ES0003"); // 要改 03放款 06還款
postMethod.addParameter("type","0002");//0002
postMethod.addParameter("data",xmlds);
postMethod.addParameter("mac",mac);
}catch (Exception e) {
e.printStackTrace();
}
String bankResultValue = "";
// 獲取執行結果
int status = 0;
try {
status = httpClient.executeMethod(postMethod);
} catch (HttpException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if(status != 200){
System.out.println("鏈接失敗");
}else{
//鏈接成功,獲取response中的xml數據
try {
bankResultValue = new String(postMethod.getResponseBody(), "UTF-8");
System.out.println("返回結果:"+bankResultValue);
// System.out.println("第"+args[0]+"次返回結果:"+bankResultValue);
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// return bankResultValue;
//
//
}
return 0;
}//end of action
public int end() throws Throwable {
return 0;
}//end of end
}