Alipay to pay two-dimensional code - Sandbox Beta (c)

Keywords:
Alipay payment bar code, java achieve, sandbox Beta

This article pay sandbox test version of the extension, use two-dimensional code barcode Alipay payment

First, Alipay sandbox version of the APP, the payee business information are also to be registered, the package is the same to be imported.
Here we must realize that the bar code payment is similar to what you go to the supermarket to buy things, and then you use the bar code payment collection and payment, merchants using scan code gun sweep your bar code to complete the payment.

The following codes on

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.api.domain.AlipayTradePayModel;
import com.alipay.api.request.AlipayTradePayRequest;
import com.alipay.api.response.AlipayTradePayResponse;

// 使用支付宝付款中的条形码付款,沙箱环境下

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        AlipayClient alipayClient = new DefaultAlipayClient (
                "https://openapi.alipaydev.com/gateway.do",// 支付宝网关
                "2016101800711866",// APPID
                // 应用私钥
                "应用私钥",
                "json","utf-8",
                // 支付宝公钥,使用应用公钥获取的支付宝公钥
                "支付宝公钥",
                "RSA2" );// 加密方式
        
        AlipayTradePayRequest request = new AlipayTradePayRequest();
        AlipayTradePayModel model = new AlipayTradePayModel();
        request.setBizModel(model);

        model.setOutTradeNo(System.currentTimeMillis()+"");// 以当前时间为订单号
        model.setSubject("Android手机");// 商品名称
        model.setTotalAmount("12");// 商品价格
        model.setAuthCode("286598280249659146");//沙箱钱包中的付款码
        model.setScene("bar_code");
        model.setBody("此商品为测试商品");// 商品描述
        // 该笔订单允许的最晚付款时间,逾期将关闭交易。取值范围:1m~15d。m-分钟,h-小时,d-天,1c-当天(1c-当天的情况下,无论交易何时创建,都在0点关闭)。 该参数数值不接受小数点, 如 1.5h,可转换为 90m。
        // model.setTimeoutExpress("");

        AlipayTradePayResponse response = null;
        try {
            response = alipayClient.execute(request);
            System.out.println(response.getBody());
            System.out.println(response.getMsg());
        } catch (AlipayApiException e) {
            e.printStackTrace();
        }
    }
}

This side basically nothing special to talk about, I think it is the only talk of "sandbox wallet payment code", this thing is you in the sandbox version APP Alipay payment, click the button, there will be a bar code and a two-dimensional code , a bar code on it, two-dimensional code below.
You click on the bar code, it will enlarge the bar code, and all the numbers appear below the bar code, that string of numbers is the content of the above to fill in.
After fill out all the information, do not move the phone, hold the bar code, and then run the program. The console will output the following, it means that the payment was successful, this time the phone will jump to the page to pay for success. If your console in the last line of the output of the other things, it is possible that the transaction failed.
Note Control click payment from the phone, to the time interval you run the program, it is best not to be here for a long time, or it may be wrong.
Here Insert Picture Description

Published 17 original articles · won praise 3 · Views 3087

Guess you like

Origin blog.csdn.net/qq_20179227/article/details/104033875