loadrunner的java脚本

/*
 * LoadRunner Java script. (Build: _build_number_)
 * 
 * Script Description: 
 *                     
 */
package com.trunkbow.comm.serviceTest;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.trunkbow.comm.service.impl.XmlSignature;
import com.trunkbow.comm.util.HttpClientHelper;

import lrapi.lr;

public class Actions
{

    public int init() throws Throwable {
        return 0;
    }//end of init


    public int action() throws Throwable {
                testPay();
        return 0;
    }//end of action


    public int end() throws Throwable {
        return 0;
    }//end of end

        Log log = LogFactory.getLog(PayTest.class);
    
    public void testPay() throws Exception {
        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
        String date = formatter.format(currentTime);
        SimpleDateFormat orderId = new SimpleDateFormat("yyyyMMddHHmmss");
        String orderTime = orderId.format(currentTime);
                String order=orderTime+String.valueOf(randInt(10000,99999));
        
        String xml = "<Finance><Message id=\"0000\">" + "<CPReq id=\"CPReq\">"
                + "<version>6.0.1</version>" + "<instId>12345</instId>"
                + "<certId>13389743053847134210</certId>"
                //+ "<serialNo>"+lr.eval_string("{serialNo}")+"</serialNo>"
                + "<serialNo>"+order+"</serialNo>"
                + "<date>"+date+"</date>"
                + "<accountName></accountName>"
                + "<bankCardNo>"+lr.eval_string("{支付卡号}")+"</bankCardNo>"
                + "<bankCardType>C</bankCardType>"
                + "<bankCardAreaCode></bankCardAreaCode>"
                + "<certType></certType>" + "<certNo></certNo>"
                + "<mobilePhone></mobilePhone>"
                + "<charge></charge>" 
                + "<amount>1</amount>"
                + "<useCode>K00</useCode>" + "<currency>156</currency>"
                + "<limitType></limitType>" + "<remark></remark>"
                + "<sellerName></sellerName>"
                + "<installmentCount></installmentCount>"
                + "<originalAmount></originalAmount>"
                + "<expiryDate></expiryDate>" + "<cvv2></cvv2>"
                + "<channelSystemId>0000</channelSystemId>" + "</CPReq>"
                + "</Message></Finance>";
        XmlSignature xmlSignature = new XmlSignature();
                
        String result = xmlSignature.sign(xml, "CPReq");
        HttpClientHelper http = new HttpClientHelper();
        
        String postUrl = "http://195.203.56.22/online/alipay.action";
        
        String resultXml = null;
        
        lr.start_transaction("支付");//事务开始
        if(postUrl.indexOf("https://") != -1){
            resultXml = HttpsHelper.sendHTTPS(postUrl,result);
        }else{
            resultXml = http.send(result, postUrl);
        }
        
        log.info("请求报文:" + result);
        if (xmlSignature.signVerification(resultXml)) {
            lr.end_transaction("支付",lr.PASS);//事务成功
            log.info("验签通过");
        } else {  
            lr.end_transaction("支付",lr.FAIL);//事务成功
            log.error("验签失败");
        }
        log.info("返回报文:" + resultXml);
    }
    public int randInt(int min, int max) throws Exception{

        Random rand = new Random();
        int randomNum = rand.nextInt((max - min) + 1) + min;
        return randomNum;
    }
}

 

转载于:https://www.cnblogs.com/atwanli/articles/4900017.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值