package app; import http.HttpClient4; import http.HttpParameter; import http.HttpResp; import http.JsonUtil; import java.io.IOException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Map; import java.util.Random; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.PostMethod; import org.apache.jmeter.config.Arguments; import org.apache.jmeter.protocol.java.sampler.AbstractJavaSamplerClient; import org.apache.jmeter.protocol.java.sampler.JavaSamplerContext; import org.apache.jmeter.samplers.SampleResult; import com.yeepay.g3.utils.common.encrypt.AES; import com.yibao.utils.des3.RSA_Encrypt; public class TheardTest extends AbstractJavaSamplerClient{ private SampleResult results; public void setupTest(JavaSamplerContext arg0) { results = new SampleResult(); } public Arguments getDefaultParameters() { Arguments params = new Arguments(); return params; } public static String ramdonNum(int num){ Random rd = new Random(); StringBuilder sb = new StringBuilder(""); if (num <1){ return null; } else{ for(int i=1;i<=num;i++){ int sr=rd.nextInt(9); sb.append(String.valueOf(sr)); } return sb.toString(); }} public static void testCreditPay() throws ParseException{ String PUBLIC_KEY=TheardTest.testConsult(); HttpClient client = new HttpClient(); PostMethod method = new PostMethod("http://xxxxxxxx/xxxxxx/api/bankcard/credit/pay"); String key=TheardTest.ramdonNum(6); String encryptkey = "0123456789"+key; String merchantAccount = "YB01000000078"; //民生 String cardNo ="XXXXXXXXX"; String validthru="xxx7"; String cvv2 = "6xx"; String phone = "13xxxxxx5431"; String orderId = "33hhkssseef3utyt2"+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); // 自动退款 Map<String, Object> mapjson=JsonUtil.parse(result); Object obj = mapjson.get("yborderid"); String yborderid=obj.toString(); System.out.println("流水号:"+yborderid); TheardTest.refundTeseCase(yborderid,merchantAccount,amount); method.releaseConnection(); } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } |