gogoWebsite

Alipay-generate QR code to realize url, realize payment

Updated to 6 hours ago
In some of the current development of some hardware does not support the transfer of images, so in some payment applications, you can pass a payment QR code, and then through the hardware parse, and then complete the payment function. Through the tutorial on the official website of Alipay, modified a little, made a small case.

Run results:

在这里插入图片描述

Generated QR code url: /bax06971pq7dmuisupj460fc Receive the url in hardware and convert it to a QR code.

在这里插入图片描述

在这里插入图片描述

coding

package ;

import ;
import . * ; import ; import .
import ;
import ;
import ;*; import ;*; import ;*; import ;*; import
import ;

import ;import ;import ;import ;import
import ;import ;import ;import ;import
import ;

/**
 * Created by liuyangkly on 15/10/23.
 Execution scheduling, the main task is completed by two threads, the transaction thread (call the face-to-face payment 2.0 interface) and transaction guarantee thread (polling), the specific things to do
 1. face to face payment program after the execution of each transaction will be saved in the temporary queue transaction results
 2. The polling thread reads the temporary queue, gets the basic collection information and up to 30 trade_info information, and calls the Alipay interface.
 The sample code only encapsulates how to call the interface api to collect data, such as the collection of network information, transaction time consumed, exception information, etc., which needs to be completed by the system vendor developer.
 */
public class DemoHbRunner extends AbsHbRunner {

    public DemoHbRunner(AlipayMonitorService monitorService) {
        super(monitorService);
    }

    public String getAppAuthToken() { super(monitorService); }
    public String getAppAuthToken() {
        // For system vendors, this value needs to be passed if they are developing the monitoring and protection interface for the merchant, otherwise it may not be passed if they are developing the transaction protection interface for the system vendor itself.
        return null.
    }

    @Override
    public AlipayHeartbeatSynRequestBuilder getBuilder() {
        // The format of the trade info used by the system vendor, json string type, retrieved from the trade queue.
        List<SysTradeInfo> sysTradeInfoList = ();

        // Exception information is captured by the system vendor.
        List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo> (); // (ExceptionInfo.
        // (ExceptionInfo.HE_SCANER); // (ExceptionInfo.
        // (ExceptionInfo.HE_PRINTER); // (ExceptionInfo.HE_PRINTER); // (ExceptionInfo.HE_PRINTER)
        // (ExceptionInfo.HE_OTHER);; // (ExceptionInfo.

        AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
            .setProduct().setType().setEquipmentId("cr1000001")
            .setEquipmentStatus().setTime((new Date()))
            .setStoreId("store10001") .setMac("0a:00:27:00:00:00") .setNetworkType("LAN")
            .setProviderId("2088911212323549") // set the system vendor pid
            .setSysTradeInfoList(sysTradeInfoList) // Synchronize trade_info information with system vendor
            .setExceptionInfoList(exceptionInfoList) // Fill in the exception information, if any
        ;
        return builder.
    }
}

package ;

import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import .*;
import .*;
import .AlipayF2FPayResult;
import .AlipayF2FPrecreateResult;
import .AlipayF2FQueryResult;
import .AlipayF2FRefundResult;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;
import ;

import .*;

/**
 * Created by liuyangkly on 15/8/9.
 * simplermainfunction (math.),For testing face-to-face paymentsapi
 * sdkcap (a poem)demo的意见cap (a poem)问题反馈请联系:@
 */

public class Main {
    private static Log                  log = ();

    // Alipay pay in person2.0service
    private static AlipayTradeService   tradeService;

    // Alipay pay in person2.0service(Integrated transaction security interface logic)
    private static AlipayTradeService   tradeWithHBService;

    // disbursement宝dealings保障接口service,test interfaceapiutilization,Please read first
    private static AlipayMonitorService monitorService;
    String ordernumber ;

    static {
        /** Be sure to create theAlipayTradeServicebefore calling()Setting the Default Parameters
         *  Configswill readclasspathConfiguration information for files under,If the file is not found then confirm that it is in theclasspathcatalogs
         */
        ("");

        /** utilizationConfigsDefault parameters provided
         *  AlipayTradeService可以utilization单例或者为静态成员对象,No need to repeatnew
         */
        tradeService = new ().build();

        // Alipay pay in person2.0service(Integrated transaction security interface logic)
        tradeWithHBService = new ().build();

        /** If you need to override the programConfigsDefault parameters provided, 可以utilizationClientBuilderclasssetXXXmethod to modify the default parameters 否则utilization代码中的默认设置 */
        monitorService = new ()
            .setGatewayUrl("/").setCharset("GBK")
            .setFormat("json").build();
    }

    // simpler打印应答
    private void dumpResponse(AlipayResponse response) {
        if (response != null) {
           // (("code:%s, msg:%s", (), ()));
            if ((())) {
               // (("subCode:%s, subMsg:%s", (),
                  //  ()));
            }
         //  ("body:" + ());    
           
			
        }
    }
  
    public static void main(String[] args) {
        Main main = new Main();

        // System vendors test transaction protection interfacesapi
        //        main.test_monitor_sys();

        // POSVendor Testing Transaction Assurance Interfaceapi
        //        main.test_monitor_pos();

        // Test Transaction Assurance Interface Scheduling
        //        main.test_monitor_schedule_logic();

        // Tests paid in person2.0disbursement(utilization未集成dealings保障接口的当面付2.0service)
             //  main.test_trade_pay(tradeService);

        // Test inquiries paid in person2.0dealings
        //        main.test_trade_query();

        // Tests paid in person2.0return merchandise
        //        main.test_trade_refund();

        // Tests paid in person2.0generatingdisbursement二维码     
    //  main.test_trade_precreate();
        main.test_trade_precreate("201918","0.01");
 
     //Tests paid in person查询disbursement结果
    // main.test_trade_query();
    }

    // 测试系统商dealings保障调度
    public void test_monitor_schedule_logic() {
        // 启动dealings保障线程
        DemoHbRunner demoRunner = new DemoHbRunner(monitorService);
        (5); // Setting the post-startup delay5Start scheduling in seconds.,Default if not set3unit of angle or arc equivalent one sixtieth of a degree
        (10); // Setting Interval10unit of angle or arc equivalent one sixtieth of a degree进行调度,Default if not set15 * 60unit of angle or arc equivalent one sixtieth of a degree
        ();

        // Initiate face-to-face payment,here at intervals of5unit of angle or arc equivalent one sixtieth of a degreecall (programming)一次disbursement接口,and when the random number is0时dealings保障线程退出
        while (() != 0) {
            test_trade_pay(tradeWithHBService);
            (5 * 1000);
        }

        // The exit condition can be satisfied by calling theshutdownElegant and safe exit
        ();
    }

    // Sample System Provider Calls,Filled in all the fields required by the system vendor
    public void test_monitor_sys() {
        // 系统商utilization的dealingstext格式,jsonstring type
        List<SysTradeInfo> sysTradeInfoList = new ArrayList<SysTradeInfo>();
        (("00000001", 5.2, ));
        (("00000002", 4.4, ));
        (("00000003", 11.3, ));
        (("00000004", 3.2, ));
        (("00000005", 4.1, ));

        // Fill in the exception information,If there is one.
        List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo>();
        (ExceptionInfo.HE_SCANER);
        //        (ExceptionInfo.HE_PRINTER);
        //        (ExceptionInfo.HE_OTHER);

        // Fill in the extended parameters,If there is one.
        Map<String, Object> extendInfo = new HashMap<String, Object>();
        //        ("SHOP_ID", "BJ_ZZ_001");
        //        ("TERMINAL_ID", "1234");

        String appAuthToken = "application authorization token";//Fill in according to the real value

        AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
            .setAppAuthToken(appAuthToken).setProduct().setType()
            .setEquipmentId("cr1000001").setEquipmentStatus()
            .setTime((new Date())).setStoreId("store10001").setMac("0a:00:27:00:00:00")
            .setNetworkType("LAN").setProviderId("2088911212323549") // Setting up the system vendorpid
            .setSysTradeInfoList(sysTradeInfoList) // system integrator synchronizationtrade_infotext
            //                .setExceptionInfoList(exceptionInfoList)  // Fill in the exception information,If there is one.
            .setExtendInfo(extendInfo) // 填写扩展text,If there is one.
        ;

        MonitorHeartbeatSynResponse response = (builder);
        dumpResponse(response);
    }

    // POSSample calls from vendors,Filled out allposFields to be filled in by the vendor
    public void test_monitor_pos() {
        // POS厂商utilization的dealingstext格式,string type
        List<PosTradeInfo> posTradeInfoList = new ArrayList<PosTradeInfo>();
        ((, "1324", 7));
        ((, "1326", 15));
        ((, "1401", 8));
        ((, "1405", 3));

        // Fill in the exception information,If there is one.
        List<ExceptionInfo> exceptionInfoList = new ArrayList<ExceptionInfo>();
        (ExceptionInfo.HE_PRINTER);

        // Fill in the extended parameters,If there is one.
        Map<String, Object> extendInfo = new HashMap<String, Object>();
        //        ("SHOP_ID", "BJ_ZZ_001");
        //        ("TERMINAL_ID", "1234");

        AlipayHeartbeatSynRequestBuilder builder = new AlipayHeartbeatSynRequestBuilder()
            .setProduct()
            .setType(Type.SOFT_POS)
            .setEquipmentId("soft100001")
            .setEquipmentStatus()
            .setTime("2015-09-28 11:14:49")
            .setManufacturerPid("2088000000000009")
            // 填写机具商的disbursement宝pid
            .setStoreId("store200001").setEquipmentPosition("31.2433190000,121.5090750000")
            .setBbsPosition("2869719733-065|2896507033-091").setNetworkStatus("gggbbbgggnnn")
            .setNetworkType("3G").setBattery("98").setWifiMac("0a:00:27:00:00:00")
            .setWifiName("test_wifi_name").setIp("192.168.1.188")
            .setPosTradeInfoList(posTradeInfoList) // POSvendor synchronizationtrade_infotext
            //                .setExceptionInfoList(exceptionInfoList) // Fill in the exception information,If there is one.
            .setExtendInfo(extendInfo) // 填写扩展text,If there is one.
        ;

        MonitorHeartbeatSynResponse response = (builder);
        dumpResponse(response);
    }

    // Tests paid in person2.0disbursement
    public void test_trade_pay(AlipayTradeService service) {
        // (mandatory field) Unique order number in the merchant website order system,64within one character,Can only contain letters、digital (electronics etc)、underscores,
        // Need to ensure that the merchant system side can not be duplicated,Proposed adoption of a databasesequencegenerating,
        String outTradeNo = "tradepay" + ()
                            + (long) (() * 10000000L);

        // (mandatory field) Order Title,粗略描述用户的disbursement目的。as if“xxxbrandingxxxConsumption in store”
        String subject = "xxxbrandingxxxPay in person at the store";

        // (mandatory field) Total Order Amount,Units are in dollars.,cannot exceed1billions
        // as if果同时传入了【Discounted amount】,【不可Discounted amount】,【Total Order Amount】three,则必须满足as if下条件:【Total Order Amount】=【Discounted amount】+【不可Discounted amount】
        String totalAmount = "0.01";

        // (mandatory field) payment barcode,用户disbursement宝钱包手机appstrike (on the keyboard)“disbursements”产生的payment barcode
        String authCode ="280984021082891331";
 // Barcode Example,286648048691290423
        // (selectable,根据需要决定是否utilization) 订单可Discounted amount,Discounts can be configured in conjunction with the merchant platform,as if果订单部分商品参与打折,Part of the total price of the product can be entered into this field.,All items can be discounted by default
        // as if果该值未传入,But the incoming【Total Order Amount】,【不可Discounted amount】 then the value defaults to【Total Order Amount】- 【不可Discounted amount】
        //        String discountableAmount = "1.00"; //

        // (selectable) 订单不可Discounted amount,Discounts can be configured in conjunction with the merchant platform,as if果酒水不参与打折,Then fill in the corresponding amount into this field
        // as if果该值未传入,But the incoming【Total Order Amount】,【Discounted amount】,then the value defaults to【Total Order Amount】-【Discounted amount】
        String undiscountableAmount = "0.0";

        // 卖家disbursement宝账号ID,Used to support one contracted account to support the payment to different collection accounts,(payable tosellerIdcorrespondingdisbursement宝账号)
        // as if果该字段为空,则默认为与disbursement宝签约的商户的PID,i.e.appidcorrespondingPID
        String sellerId = "";

        // Order Description,可以对dealings或商品进行一个详细地描述,比as if填写"Purchase of goods3Total20.00unit of money (in PRC: Chinese yuan, in USA: dollar, etc)"
        String body = "Purchase of goods3Total20.00unit of money (in PRC: Chinese yuan, in USA: dollar, etc)";

        // Merchant Operator Number,Add this parameter to make sales statistics for merchant operators.
        String operatorId = "test_operator_id";

        // (mandatory field) Merchant Store Number,pass (a bill or inspection etc)门店号cap (a poem)商家后台可以配置精准到门店的折扣text,详询disbursement宝技术支持
        String storeId = "test_store_id";

        // Business Extension Parameters,目前可添加由disbursement宝分配的系统商编号(pass (a bill or inspection etc)setSysServiceProviderIdmethodologies),详情请咨询disbursement宝技术支持
        String providerId = "2088100200300400500";
        ExtendParams extendParams = new ExtendParams();
        (providerId);

        // disbursement超时,线下扫码dealingsdefine as5minutes
        String timeoutExpress = "5m";

        // Product Detail List,需填写Purchase of goods详细text,
        List<GoodsDetail> goodsDetailList = new ArrayList<GoodsDetail>();
        // 创建一个商品text,The meaning of the parameters are commoditiesid(utilization国标)、name (of a thing)、price of item(Units are minutes)、quantities,as if果需要添加商品类别,for further details, refer toGoodsDetail
        GoodsDetail goods1 = ("goods_id001", "xxxbakery", 1000, 1);
        // 创建好一个商品后添加至Product Detail List
        (goods1);

        // 继续创建并添加第一条商品text,The user purchased the product as“Negro toothbrushes”,price of item为5.00unit of money (in PRC: Chinese yuan, in USA: dollar, etc),Purchased two
        GoodsDetail goods2 = ("goods_id002", "xxxrazors", 500, 2);
        (goods2);

        String appAuthToken = "application authorization token";//Fill in according to the real value

        // 创建条码disbursement请求builder,Setting request parameters
        AlipayTradePayRequestBuilder builder = new AlipayTradePayRequestBuilder()
            //            .setAppAuthToken(appAuthToken)
            .setOutTradeNo(outTradeNo).setSubject(subject).setAuthCode(authCode)
            .setTotalAmount(totalAmount).setStoreId(storeId)
            .setUndiscountableAmount(undiscountableAmount).setBody(body).setOperatorId(operatorId)
            .setExtendParams(extendParams).setSellerId(sellerId)
            .setGoodsDetailList(goodsDetailList).setTimeoutExpress(timeoutExpress);

        // call (programming)tradePaymethodologies获取当面付应答
        AlipayF2FPayResult result = (builder);
        switch (()) {
            case SUCCESS:
                ("disbursement宝disbursement成功: )");
                break;

            case FAILED:
                ("disbursement宝disbursement失败!!!");
                break;

            case UNKNOWN:
                ("system anomaly,Order Status Unknown!!!");
                break;

            default:
                ("不支持的dealings状态,dealings返回异常!!!");
                break;
        }
    }

    // Tests paid in person2.0generatingdisbursement二维码
    public String test_trade_precreate(String outTradeNo1,String price) {
        // (mandatory field) Unique order number in the merchant website order system,64within one character,Can only contain letters、digital (electronics etc)、underscores,
        // Need to ensure that the merchant system side can not be duplicated,Proposed adoption of a databasesequencegenerating,
//        String outTradeNo = "tradeprecreate" + ()
//                            + (long) (() * 10000000L);
    	String outTradeNo  = outTradeNo1;
        ordernumber = outTradeNo;
        ("test_trade_precreate order number:"+ordernumber+price);
       // String outTradeNo = "tradepay14817118170004421162";
        // (mandatory field) Order Title,粗略描述用户的disbursement目的。as if“xxxbrandingxxxPay in person at stores with code-sweeping”
        String subject = "xxxbrandingxxxPay in person at stores with code-sweeping";

        // (mandatory field) Total Order Amount,Units are in dollars.,cannot exceed1billions
        // as if果同时传入了【Discounted amount】,【不可Discounted amount】,【Total Order Amount】three,则必须满足as if下条件:【Total Order Amount】=【Discounted amount】+【不可Discounted amount】
        String totalAmount = price;

        // (selectable) 订单不可Discounted amount,Discounts can be configured in conjunction with the merchant platform,as if果酒水不参与打折,Then fill in the corresponding amount into this field
        // as if果该值未传入,But the incoming【Total Order Amount】,【Discounted amount】,then the value defaults to【Total Order Amount】-【Discounted amount】
        String undiscountableAmount = "0";

        // 卖家disbursement宝账号ID,Used to support one contracted account to support the payment to different collection accounts,(payable tosellerIdcorrespondingdisbursement宝账号)
        // as if果该字段为空,则默认为与disbursement宝签约的商户的PID,i.e.appidcorrespondingPID
        String sellerId = "";

        // Order Description,可以对dealings或商品进行一个详细地描述,比as if填写"Purchase of goods2Total15.00unit of money (in PRC: Chinese yuan, in USA: dollar, etc)"
        String body = "Purchase of goods3Total20.00unit of money (in PRC: Chinese yuan, in USA: dollar, etc)";

        // Merchant Operator Number,Add this parameter to make sales statistics for merchant operators.
        String operatorId = "test_operator_id";

        // (mandatory field) Merchant Store Number,pass (a bill or inspection etc)门店号cap (a poem)商家后台可以配置精准到门店的折扣text,详询disbursement宝技术支持
        String storeId = "test_store_id";

        // Business Extension Parameters,目前可添加由disbursement宝分配的系统商编号(pass (a bill or inspection etc)setSysServiceProviderIdmethodologies),详情请咨询disbursement宝技术支持
        ExtendParams extendParams = new ExtendParams();
        ("2088100200300400500");

        // disbursement超时,define as120minutes
        String timeoutExpress = "120m";

        // Product Detail List,需填写Purchase of goods详细text,
        List<GoodsDetail> goodsDetailList = new ArrayList<GoodsDetail>();
        // 创建一个商品text,The meaning of the parameters are commoditiesid(utilization国标)、name (of a thing)、price of item(Units are minutes)、quantities,as if果需要添加商品类别,for further details, refer toGoodsDetail
        GoodsDetail goods1 = ("goods_id001", "xxx小bakery", 1000, 1);
        // 创建好一个商品后添加至Product Detail List
        (goods1);

        // 继续创建并添加第一条商品text,The user purchased the product as“Negro toothbrushes”,price of item为5.00unit of money (in PRC: Chinese yuan, in USA: dollar, etc),Purchased two
        GoodsDetail goods2 = ("goods_id002", "xxxrazors", 500, 2);
        (goods2);

        // 创建扫码disbursement请求builder,Setting request parameters
        AlipayTradePrecreateRequestBuilder builder = new AlipayTradePrecreateRequestBuilder()
            .setSubject(subject).setTotalAmount(totalAmount).setOutTradeNo(outTradeNo)
            .setUndiscountableAmount(undiscountableAmount).setSellerId(sellerId).setBody(body)
            .setOperatorId(operatorId).setStoreId(storeId).setExtendParams(extendParams)
            .setTimeoutExpress(timeoutExpress)
            .setNotifyUrl("/zouminghao")//disbursement宝service器主动通知商户service器里指定的页面httptrails,Set up as needed
            .setGoodsDetailList(goodsDetailList);

        AlipayF2FPrecreateResult result = (builder);
        String url = "";
        //AlipayF2FPrecreateResult result = (builder);
        switch (()) {
            case SUCCESS:
                ("disbursement宝预下单成功: )");

                AlipayTradePrecreateResponse response = ();
                dumpResponse(response);
                url=();
                (());
                // 需要修改为运行机器上的trails
                String filePath = ("/Users/sudo/Desktop/qr-%",
                    ());
                ("filePath:" + filePath);
                //                ((), 256, filePath);
                break;

            case FAILED:
                ("disbursement宝预下单失败!!!");
                break;

            case UNKNOWN:
                ("system anomaly,Pre-order status unknown!!!");
                break;

            default:
                ("不支持的dealings状态,dealings返回异常!!!");
                break;
        }
        return url;
    }
    // Tests paid in person2.0refund
    public void test_trade_refund() {
        // (mandatory field) 外部order number,需要refunddealings的商户外部order number
        String outTradeNo = "tradepay14817938139942440181";

        // (mandatory field) refund金额,该金额必须小于等于订单的disbursement金额,Units are in dollars.
        String refundAmount = "0.01";

        // (selectable,需要支持重复return merchandise时mandatory field) 商户refund请求号,相同disbursement宝dealings号下的不同refund请求号对应同一笔dealings的不同refund申请,
        // 对于相同disbursement宝dealings号下多笔相同商户refund请求号的refunddealings,disbursement宝只会进行一次refund
        String outRequestNo = "";

        // (mandatory field) refund原因,可以说明用户refund原因,Conveniently provide statistics for the merchant's back office
        String refundReason = "正常refund,users buy more than they should";

        // (mandatory field) Merchant Store Number,refund情况下可以为商家后台提供refund权限判定cap (a poem)统计等作用,详询disbursement宝技术支持
        String storeId = "test_store_id";

        // 创建refund请求builder,Setting request parameters
        AlipayTradeRefundRequestBuilder builder = new AlipayTradeRefundRequestBuilder()
            .setOutTradeNo(outTradeNo).setRefundAmount(refundAmount).setRefundReason(refundReason)
            .setOutRequestNo(outRequestNo).setStoreId(storeId);

        AlipayF2FRefundResult result = (builder);
        switch (()) {
            case SUCCESS:
                ("disbursement宝refund成功: )");
                break;

            case FAILED:
                ("disbursement宝refund失败!!!");
                break;

            case UNKNOWN:
                ("system anomaly,订单refund状态未知!!!");
                break;

            default:
                ("不支持的dealings状态,dealings返回异常!!!");
                break;
        }
    }
 // Tests paid in person2.0Check Orders
    public String test_trade_query( ) {
        // (mandatory field) 商户order number,pass (a bill or inspection etc)此商户order number查询当面付的dealings状态
        String outTradeNo = ordernumber;
        ("test_trade_query order number:"+outTradeNo);
        // Creating a Query Requestbuilder,Setting request parameters
        AlipayTradeQueryRequestBuilder builder = new AlipayTradeQueryRequestBuilder()
            .setOutTradeNo(outTradeNo);

        AlipayF2FQueryResult result = (builder);
        AlipayTradeQueryResponse response = ();
        (());
        (());
        return ();
       /* switch (()) {
            case SUCCESS:
                ("查询返回该订单disbursement成功: )");

                AlipayTradeQueryResponse response = ();
                dumpResponse(response);

                (());
                if ((())) {
                    for (TradeFundBill bill : ()) {
                        (() + ":" + ());
                    }
                }
                break;

            case FAILED:
                ("查询返回该订单disbursement失败或被关闭!!!");
                break;

            case UNKNOWN:
                ("system anomaly,订单disbursement状态未知!!!");
                break;

            default:
                ("不支持的dealings状态,dealings返回异常!!!");
                break;
        }*/
    }
  
}

Configuration information:


# paypal gateway name, partnerId and appId
open_api_domain =/
mcloud_api_domain =/
pid =
appid =

# RSA private key, public key and paypal public key
private_key =
public_key =

# SHA256withRsa corresponding to Alipay public key
alipay_public_key =
sign_type = RSA2
# Maximum number of queries and query intervals (in milliseconds) for PayPal in person
max_query_retry = 5
query_duration = 5000

# Maximum number of in-person revocations and revocation interval (milliseconds)
max_cancel_retry = 3
cancel_duration = 2000

# First scheduling delay and scheduling interval for transaction safeguard threads (in seconds)
heartbeat_delay = 5
heartbeat_duration = 900

Ways to view Pid: /?tid=1689&fid=69&ant_source=zsearch
You can't forget to set up the callback interface.

更多学习资讯,学习源码,请在耶宇星球领取

More learning information, learning source code, please pick up at Yayu Planet!