/* * LoadRunner Java script. (Build: _build_number_) * * Script Description: * */ import lrapi.lr; import http.HttpClient4; import http.HttpParameter; import http.HttpResp; import http.JsonUtil; import http.Testcredit; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.PostMethod; import java.util.Random; import java.util.Date; import java.text.SimpleDateFormat; import java.util.Calendar; import com.yeepay.g3.utils.common.encrypt.AES; import com.yibao.utils.des3.RSA_Encrypt; public class Actions { public String aes; Date d = new Date(); Testcredit tc = new Testcredit(); SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); HttpParameter parameter = new HttpParameter(); public int init() throws Throwable { String url = "http://xxxxx/xxxxx/consult"; HttpClient4 client =HttpClient4.createDefault(); String data = ""; Calendar now = Calendar.getInstance(); now.setTime(d); String dateline=format.format(now.getTime()); System.out.println(dateline); Date date = format.parse(dateline); String dates=date.getTime()/1000+""; System.out.println(dates); try { data = AES.encryptToBase64(dates, "<aes>"); } catch (Exception e) { e.printStackTrace(); } parameter.add("data", data); parameter.add("merchantaccount", "<merchant>"); HttpResp resp = new HttpResp(); try{ resp=client.doPost(url, parameter, "utf-8"); String respStr= resp.getText("utf-8"); System.out.println(respStr); aes=AES.decryptFromBase64(respStr, "<aes>"); System.out.println("aes="+aes); } catch (Exception e) { e.printStackTrace(); } client.shutdown(); return 0; }//end of init public int action() throws Throwable { StringBuilder sb = new StringBuilder(""); Random rd = new Random(); for(int i=1;i<=6;i++){ int sr=rd.nextInt(9); sb.append(String.valueOf(sr)); } String key=sb.toString(); int rds=rd.nextInt(999999); lr.start_transaction("pay"); lr.rendezvous("pay"); HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://xxxxxxxx/xxxxxxx/api/bankcard/credit/pay"); System.out.println(aes); String PUBLIC_KEY=aes; System.out.println("PUBLIC_KEY"+PUBLIC_KEY); String encryptkey = "0123456789"+key; String merchantAccount = "<merchant>"; //民生 String cardNo = "6XXXXXXXXXXXXXX"; String validthru = "XXXX"; String cvv2 = "XXX"; String phone = "13466745431"; String orderId = rds+"334234223"+key; System.out.println(orderId); Integer transtime = (int)(System.currentTimeMillis()/1000); Integer currency = 156; String amount = "50"; String productcatalog = "1"; String productName = "123"; String productDesc = "小丸子"; String userIp = "123.45.45.45"; String identityId = "a"; Integer identityType = 6; String other = "eeee"; String data = "{\"merchantaccount\":\"" + merchantAccount +"\",\"cardno\":\"" + cardNo + "\",\"validthru\":\"" + validthru + "\",\"cvv2\":\"" + cvv2 + "\",\"phone\":\"" + phone + "\",\"orderid\":\"" + orderId + "\",\"transtime\":" + transtime + ",\"currency\":" + currency + ",\"amount\":" + amount + ",\"productcatalog\":\"" + productcatalog + "\",\"productname\":\"" + productName + "\",\"productdesc\":\"" + productDesc + "\",\"userip\":\"" + userIp + "\",\"identityid\":\"" + identityId + "\",\"identitytype\":" + identityType + ",\"other\":\"" + other + "\"}"; data = AES.encryptToBase64(data, encryptkey); try { method.setParameter("merchantaccount", merchantAccount); method.setParameter("data", data); method.setParameter("encryptkey", RSA_Encrypt.encrypt(encryptkey, PUBLIC_KEY)); client.executeMethod(method); System.out.println(method.getStatusLine()); String respStr = method.getResponseBodyAsString(); System.out.println(respStr); String result = AES.decryptFromBase64(respStr, encryptkey); System.out.println(result); method.releaseConnection(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace();} lr.end_transaction("pay", lr.AUTO); return 0; }//end of action public int end() throws Throwable { return 0; }//end of end } |