Java Code Examples for com.alipay.demo.trade.utils.Utils

The following examples show how to use com.alipay.demo.trade.utils.Utils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: mmall20180107   Source File: Main.java    License: Apache License 2.0 6 votes vote down vote up
public void test_monitor_schedule_logic() {
    // 启动交易保障线程
    DemoHbRunner demoRunner = new DemoHbRunner(monitorService);
    demoRunner.setDelay(5); // 设置启动后延迟5秒开始调度,不设置则默认3秒
    demoRunner.setDuration(10); // 设置间隔10秒进行调度,不设置则默认15 * 60秒
    demoRunner.schedule();

    // 启动当面付,此处每隔5秒调用一次支付接口,并且当随机数为0时交易保障线程退出
    while (Math.random() != 0) {
        test_trade_pay(tradeWithHBService);
        Utils.sleep(5 * 1000);
    }

    // 满足退出条件后可以调用shutdown优雅安全退出
    demoRunner.shutdown();
}
 
Example 2
Source Project: mmall20180107   Source File: DemoHbRunner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AlipayHeartbeatSynRequestBuilder getBuilder() {
    // 系统商使用的交易信息格式,json字符串类型,从交易队列中获取
    List<SysTradeInfo> sysTradeInfoList = HbQueue.poll();

    // 异常信息的采集,系统商自行完成
    List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo>();
    //        exceptionInfoList.add(ExceptionInfo.HE_SCANER);
    //        exceptionInfoList.add(ExceptionInfo.HE_PRINTER);
    //        exceptionInfoList.add(ExceptionInfo.HE_OTHER);

    AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
            .setProduct(Product.FP).setType(Type.CR).setEquipmentId("cr1000001")
            .setEquipmentStatus(EquipStatus.NORMAL).setTime(Utils.toDate(new Date()))
            .setStoreId("store10001").setMac("0a:00:27:00:00:00").setNetworkType("LAN")
            .setProviderId("2088911212323549") // 设置系统商pid
            .setSysTradeInfoList(sysTradeInfoList) // 系统商同步trade_info信息
            .setExceptionInfoList(exceptionInfoList) // 填写异常信息,如果有的话
            ;
    return builder;
}
 
Example 3
Source Project: mmall-kay-Java   Source File: Main.java    License: Apache License 2.0 6 votes vote down vote up
public void test_monitor_schedule_logic() {
    // 启动交易保障线程
    DemoHbRunner demoRunner = new DemoHbRunner(monitorService);
    demoRunner.setDelay(5); // 设置启动后延迟5秒开始调度,不设置则默认3秒
    demoRunner.setDuration(10); // 设置间隔10秒进行调度,不设置则默认15 * 60秒
    demoRunner.schedule();

    // 启动当面付,此处每隔5秒调用一次支付接口,并且当随机数为0时交易保障线程退出
    while (Math.random() != 0) {
        test_trade_pay(tradeWithHBService);
        Utils.sleep(5 * 1000);
    }

    // 满足退出条件后可以调用shutdown优雅安全退出
    demoRunner.shutdown();
}
 
Example 4
Source Project: mmall-kay-Java   Source File: DemoHbRunner.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public AlipayHeartbeatSynRequestBuilder getBuilder() {
    // 系统商使用的交易信息格式,json字符串类型,从交易队列中获取
    List<SysTradeInfo> sysTradeInfoList = HbQueue.poll();

    // 异常信息的采集,系统商自行完成
    List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo>();
    //        exceptionInfoList.add(ExceptionInfo.HE_SCANER);
    //        exceptionInfoList.add(ExceptionInfo.HE_PRINTER);
    //        exceptionInfoList.add(ExceptionInfo.HE_OTHER);

    AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
        .setProduct(Product.FP).setType(Type.CR).setEquipmentId("cr1000001")
        .setEquipmentStatus(EquipStatus.NORMAL).setTime(Utils.toDate(new Date()))
        .setStoreId("store10001").setMac("0a:00:27:00:00:00").setNetworkType("LAN")
        .setProviderId("2088911212323549") // 设置系统商pid
        .setSysTradeInfoList(sysTradeInfoList) // 系统商同步trade_info信息
        .setExceptionInfoList(exceptionInfoList) // 填写异常信息,如果有的话
    ;
    return builder;
}
 
Example 5
Source Project: MMall_JAVA   Source File: Main.java    License: GNU General Public License v3.0 6 votes vote down vote up
public void test_monitor_schedule_logic() {
    // 启动交易保障线程
    DemoHbRunner demoRunner = new DemoHbRunner(monitorService);
    demoRunner.setDelay(5); // 设置启动后延迟5秒开始调度,不设置则默认3秒
    demoRunner.setDuration(10); // 设置间隔10秒进行调度,不设置则默认15 * 60秒
    demoRunner.schedule();

    // 启动当面付,此处每隔5秒调用一次支付接口,并且当随机数为0时交易保障线程退出
    while (Math.random() != 0) {
        test_trade_pay(tradeWithHBService);
        Utils.sleep(5 * 1000);
    }

    // 满足退出条件后可以调用shutdown优雅安全退出
    demoRunner.shutdown();
}
 
Example 6
Source Project: MMall_JAVA   Source File: DemoHbRunner.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public AlipayHeartbeatSynRequestBuilder getBuilder() {
    // 系统商使用的交易信息格式,json字符串类型,从交易队列中获取
    List<SysTradeInfo> sysTradeInfoList = HbQueue.poll();

    // 异常信息的采集,系统商自行完成
    List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo>();
    //        exceptionInfoList.add(ExceptionInfo.HE_SCANER);
    //        exceptionInfoList.add(ExceptionInfo.HE_PRINTER);
    //        exceptionInfoList.add(ExceptionInfo.HE_OTHER);

    AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
        .setProduct(Product.FP).setType(Type.CR).setEquipmentId("cr1000001")
        .setEquipmentStatus(EquipStatus.NORMAL).setTime(Utils.toDate(new Date()))
        .setStoreId("store10001").setMac("0a:00:27:00:00:00").setNetworkType("LAN")
        .setProviderId("2088911212323549") // 设置系统商pid
        .setSysTradeInfoList(sysTradeInfoList) // 系统商同步trade_info信息
        .setExceptionInfoList(exceptionInfoList) // 填写异常信息,如果有的话
    ;
    return builder;
}
 
Example 7
Source Project: mmall20180107   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
public void test_monitor_sys() {
    // 系统商使用的交易信息格式,json字符串类型
    List<SysTradeInfo> sysTradeInfoList = new ArrayList<SysTradeInfo>();
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000001", 5.2, HbStatus.S));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000002", 4.4, HbStatus.F));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000003", 11.3, HbStatus.P));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000004", 3.2, HbStatus.X));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000005", 4.1, HbStatus.X));

    // 填写异常信息,如果有的话
    List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo>();
    exceptionInfoList.add(ExceptionInfo.HE_SCANER);
    //        exceptionInfoList.add(ExceptionInfo.HE_PRINTER);
    //        exceptionInfoList.add(ExceptionInfo.HE_OTHER);

    // 填写扩展参数,如果有的话
    Map<String, Object> extendInfo = new HashMap<String, Object>();
    //        extendInfo.put("SHOP_ID", "BJ_ZZ_001");
    //        extendInfo.put("TERMINAL_ID", "1234");

    String appAuthToken = "应用授权令牌";//根据真实值填写

    AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
            .setAppAuthToken(appAuthToken).setProduct(Product.FP).setType(Type.CR)
            .setEquipmentId("cr1000001").setEquipmentStatus(EquipStatus.NORMAL)
            .setTime(Utils.toDate(new Date())).setStoreId("store10001").setMac("0a:00:27:00:00:00")
            .setNetworkType("LAN").setProviderId("2088911212323549") // 设置系统商pid
            .setSysTradeInfoList(sysTradeInfoList) // 系统商同步trade_info信息
            //                .setExceptionInfoList(exceptionInfoList)  // 填写异常信息,如果有的话
            .setExtendInfo(extendInfo) // 填写扩展信息,如果有的话
            ;

    MonitorHeartbeatSynResponse response = monitorService.heartbeatSyn(builder);
    dumpResponse(response);
}
 
Example 8
Source Project: mmall20180107   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
public void test_trade_query() {
    // (必填) 商户订单号,通过此商户订单号查询当面付的交易状态
    String outTradeNo = "tradepay14817938139942440181";

    // 创建查询请求builder,设置请求参数
    AlipayTradeQueryRequestBuilder builder = new AlipayTradeQueryRequestBuilder()
            .setOutTradeNo(outTradeNo);

    AlipayF2FQueryResult result = tradeService.queryTradeResult(builder);
    switch (result.getTradeStatus()) {
        case SUCCESS:
            log.info("查询返回该订单支付成功: )");

            AlipayTradeQueryResponse response = result.getResponse();
            dumpResponse(response);

            log.info(response.getTradeStatus());
            if (Utils.isListNotEmpty(response.getFundBillList())) {
                for (TradeFundBill bill : response.getFundBillList()) {
                    log.info(bill.getFundChannel() + ":" + bill.getAmount());
                }
            }
            break;

        case FAILED:
            log.error("查询返回该订单支付失败或被关闭!!!");
            break;

        case UNKNOWN:
            log.error("系统异常,订单支付状态未知!!!");
            break;

        default:
            log.error("不支持的交易状态,交易返回异常!!!");
            break;
    }
}
 
Example 9
Source Project: mmall-kay-Java   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
public void test_monitor_sys() {
    // 系统商使用的交易信息格式,json字符串类型
    List<SysTradeInfo> sysTradeInfoList = new ArrayList<SysTradeInfo>();
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000001", 5.2, HbStatus.S));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000002", 4.4, HbStatus.F));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000003", 11.3, HbStatus.P));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000004", 3.2, HbStatus.X));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000005", 4.1, HbStatus.X));

    // 填写异常信息,如果有的话
    List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo>();
    exceptionInfoList.add(ExceptionInfo.HE_SCANER);
    //        exceptionInfoList.add(ExceptionInfo.HE_PRINTER);
    //        exceptionInfoList.add(ExceptionInfo.HE_OTHER);

    // 填写扩展参数,如果有的话
    Map<String, Object> extendInfo = new HashMap<String, Object>();
    //        extendInfo.put("SHOP_ID", "BJ_ZZ_001");
    //        extendInfo.put("TERMINAL_ID", "1234");

    String appAuthToken = "应用授权令牌";//根据真实值填写

    AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
        .setAppAuthToken(appAuthToken).setProduct(Product.FP).setType(Type.CR)
        .setEquipmentId("cr1000001").setEquipmentStatus(EquipStatus.NORMAL)
        .setTime(Utils.toDate(new Date())).setStoreId("store10001").setMac("0a:00:27:00:00:00")
        .setNetworkType("LAN").setProviderId("2088911212323549") // 设置系统商pid
        .setSysTradeInfoList(sysTradeInfoList) // 系统商同步trade_info信息
        //                .setExceptionInfoList(exceptionInfoList)  // 填写异常信息,如果有的话
        .setExtendInfo(extendInfo) // 填写扩展信息,如果有的话
    ;

    MonitorHeartbeatSynResponse response = monitorService.heartbeatSyn(builder);
    dumpResponse(response);
}
 
Example 10
Source Project: mmall-kay-Java   Source File: Main.java    License: Apache License 2.0 5 votes vote down vote up
public void test_trade_query() {
    // (必填) 商户订单号,通过此商户订单号查询当面付的交易状态
    String outTradeNo = "tradepay14817938139942440181";

    // 创建查询请求builder,设置请求参数
    AlipayTradeQueryRequestBuilder builder = new AlipayTradeQueryRequestBuilder()
        .setOutTradeNo(outTradeNo);

    AlipayF2FQueryResult result = tradeService.queryTradeResult(builder);
    switch (result.getTradeStatus()) {
        case SUCCESS:
            log.info("查询返回该订单支付成功: )");

            AlipayTradeQueryResponse response = result.getResponse();
            dumpResponse(response);

            log.info(response.getTradeStatus());
            if (Utils.isListNotEmpty(response.getFundBillList())) {
                for (TradeFundBill bill : response.getFundBillList()) {
                    log.info(bill.getFundChannel() + ":" + bill.getAmount());
                }
            }
            break;

        case FAILED:
            log.error("查询返回该订单支付失败或被关闭!!!");
            break;

        case UNKNOWN:
            log.error("系统异常,订单支付状态未知!!!");
            break;

        default:
            log.error("不支持的交易状态,交易返回异常!!!");
            break;
    }
}
 
Example 11
Source Project: MMall_JAVA   Source File: Main.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void test_monitor_sys() {
    // 系统商使用的交易信息格式,json字符串类型
    List<SysTradeInfo> sysTradeInfoList = new ArrayList<SysTradeInfo>();
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000001", 5.2, HbStatus.S));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000002", 4.4, HbStatus.F));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000003", 11.3, HbStatus.P));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000004", 3.2, HbStatus.X));
    sysTradeInfoList.add(SysTradeInfo.newInstance("00000005", 4.1, HbStatus.X));

    // 填写异常信息,如果有的话
    List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo>();
    exceptionInfoList.add(ExceptionInfo.HE_SCANER);
    //        exceptionInfoList.add(ExceptionInfo.HE_PRINTER);
    //        exceptionInfoList.add(ExceptionInfo.HE_OTHER);

    // 填写扩展参数,如果有的话
    Map<String, Object> extendInfo = new HashMap<String, Object>();
    //        extendInfo.put("SHOP_ID", "BJ_ZZ_001");
    //        extendInfo.put("TERMINAL_ID", "1234");

    String appAuthToken = "应用授权令牌";//根据真实值填写

    AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
        .setAppAuthToken(appAuthToken).setProduct(Product.FP).setType(Type.CR)
        .setEquipmentId("cr1000001").setEquipmentStatus(EquipStatus.NORMAL)
        .setTime(Utils.toDate(new Date())).setStoreId("store10001").setMac("0a:00:27:00:00:00")
        .setNetworkType("LAN").setProviderId("2088911212323549") // 设置系统商pid
        .setSysTradeInfoList(sysTradeInfoList) // 系统商同步trade_info信息
        //                .setExceptionInfoList(exceptionInfoList)  // 填写异常信息,如果有的话
        .setExtendInfo(extendInfo) // 填写扩展信息,如果有的话
    ;

    MonitorHeartbeatSynResponse response = monitorService.heartbeatSyn(builder);
    dumpResponse(response);
}
 
Example 12
Source Project: MMall_JAVA   Source File: Main.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void test_trade_query() {
    // (必填) 商户订单号,通过此商户订单号查询当面付的交易状态
    String outTradeNo = "tradepay14817938139942440181";

    // 创建查询请求builder,设置请求参数
    AlipayTradeQueryRequestBuilder builder = new AlipayTradeQueryRequestBuilder()
        .setOutTradeNo(outTradeNo);

    AlipayF2FQueryResult result = tradeService.queryTradeResult(builder);
    switch (result.getTradeStatus()) {
        case SUCCESS:
            log.info("查询返回该订单支付成功: )");

            AlipayTradeQueryResponse response = result.getResponse();
            dumpResponse(response);

            log.info(response.getTradeStatus());
            if (Utils.isListNotEmpty(response.getFundBillList())) {
                for (TradeFundBill bill : response.getFundBillList()) {
                    log.info(bill.getFundChannel() + ":" + bill.getAmount());
                }
            }
            break;

        case FAILED:
            log.error("查询返回该订单支付失败或被关闭!!!");
            break;

        case UNKNOWN:
            log.error("系统异常,订单支付状态未知!!!");
            break;

        default:
            log.error("不支持的交易状态,交易返回异常!!!");
            break;
    }
}