美文网首页程序员Java 杂谈技术干货
支付宝支付-刷卡支付(条码支付)

支付宝支付-刷卡支付(条码支付)

作者: Javen205 | 来源:发表于2017-05-07 21:20 被阅读2499次

    在官方的产品是叫做当面付

    1、什么是当面付呢?

    简单的讲就是条码支付(刷卡支付)、扫码支付、声波支付。

    官方是这样解释的
    商户可通过以下任一方式在线下完成交易收款都是当面付
    1、商家通过扫描线下买家支付宝钱包中的条码、二维码等方式将买家的交易资金直接打入卖家支付宝账户,资金实时到账;
    2、线下买家通过使用支付宝钱包扫描商家的二维码等方式完成支付,提升商家收银效率,资金实时到账;
    3、线下买家使用支付宝钱包中的当面付功能,通过声波支付的方式向商家完成付款,资金实时到账。

    2、申请条件

    1. 申请前必须拥有企业或个人支付宝账号,且通过支付宝实名认证审核;
    1. 营业执照主体需与签约主体一致,如不一致者需提供有效授权函;授权函要求:公司类型必须盖公章、个体工商户需两选一:
      a. 法人身份证原件+法人签字
      b. 法人身份证原件+个体工商户盖章;
    2. 部分行业暂未开放签约,如保险、黄金期货、借贷(P2P)、POS等支付业务等;

    3、产品费率

    单笔费率 0.6%

    4、签约认证流程

    如果你只是想了解支付流程可以不进行签约,我们可以使用沙箱环境进行测试。

    签约认证流程 开发平台-研发服务-沙箱环境

    5、聊聊条码支付(刷卡支付)

    官方文档 当面付详细的产品介绍在这里

    条码支付是支付宝给到线下传统行业的一种收款方式。商家使用扫码枪等条码识别设备扫描用户支付宝钱包上的条码/二维码,完成收款。用户仅需出示付款码,所有收款操作由商家端完成。

    业务流程

    使用步骤:

    1、用户登录支付宝钱包,点击首页“付款”,进入付款码界面;
    2、收银员在商家收银系统操作生成订单,用户确认支付金额;
    3、用户出示钱包的“付款码”,收银员用扫码设备来扫描用户手机上的条码/二维码后,商家收银系统提交支付;
    4、付款成功后商家收银系统会拿到支付成功或者失败的结果。

    使用步骤

    6、如何接入条码支付(刷卡支付)呢?

    官方接入介绍资料 当面付快速接入

    前三步任何支付方式对接必不可少,这些按照文档操作应该没有问题。如遇到问题欢迎留言

    前三步任何支付方式对接必不可少

    今天的主角要登场了>>>>>>条码支付

    调用时序图

    这里主要涉及到三个接口

    这里我们使用官方提供的服务端SDK(开放平台服务端SDK)来快速接入

    7、选择正确的接入环境

    👆上面提到过如果是测试或者不上线应用可以不用签约直接使用沙箱环境

    正式环境支付网关:https://openapi.alipay.com/gateway.do
    沙盒环境支付网关:https://openapi.alipaydev.com/gateway.do

    8、使用SDK封装接口

    添加支付宝相关的配置文件 alipay.properties

    ############################
    # 支付宝相关的配置
    ############################
    
    appId=xxx //测试号的APPID
    privateKey=xxx //测试号的私钥 建议使用RSA2
    alipayPulicKey=xxx //支付宝公钥
    serverUrl=https://openapi.alipaydev.com/gateway.do //支付网关
    notify_domain = xxx //通知域名
    
    8.1 在SDK调用前需要进行初始化
        private static final Prop prop = PropKit.use("alipay.properties");
    
        public static AlipayClient alipayClient;
        public static String charset = "UTF-8";
        public static String privateKey = prop.get("privateKey");
        public static String alipayPulicKey = prop.get("alipayPulicKey");
        public static String serverUrl = prop.get("serverUrl");
        public static String appId = prop.get("appId");
        public static String format = "json";
        public static String signType = "RSA2";
        public static String notify_domain = prop.get("notify_domain");
    
        static {
            alipayClient = new DefaultAlipayClient(serverUrl, appId, privateKey, format, charset, alipayPulicKey, signType);
        }
    
    8.2 封装交易支付接口alipay.trade.pay
    /**
         * 条形码支付
         * https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.Yhpibd&treeId=194&articleId=105170&docType=1#s4
         * @throws AlipayApiException
         */
        public static String tradePay(AlipayTradePayModel model) throws AlipayApiException {
            AlipayTradePayResponse response = tradePayToResponse(model);
            return response.getBody();
        }
        
        public static AlipayTradePayResponse tradePayToResponse(AlipayTradePayModel model) throws AlipayApiException{
            AlipayTradePayRequest request = new AlipayTradePayRequest();
            request.setBizModel(model);// 填充业务参数
            return alipayClient.execute(request); // 通过alipayClient调用API,获得对应的response类
        }
    
    8.3 交易查询接口alipay.trade.query
    /**
         * 交易查询接口
         * https://doc.open.alipay.com/docs/api.htm?spm=a219a.7395905.0.0.8H2JzG&docType=4&apiId=757
         * @param bizContent
         * @return
         * @throws AlipayApiException
         */
        public static boolean isTradeQuery(AlipayTradeQueryModel model) throws AlipayApiException{
            AlipayTradeQueryResponse response = tradeQuery(model);
            if(response.isSuccess()){
                return true;
            }
            return false;
        }
        
        public static AlipayTradeQueryResponse  tradeQuery(AlipayTradeQueryModel model) throws AlipayApiException{
            AlipayTradeQueryRequest request = new AlipayTradeQueryRequest();
            request.setBizModel(model);
            return alipayClient.execute(request);
        }
    
    8.4 交易撤销接口alipay.trade.cancel
    /**
         * 交易撤销接口
         * https://doc.open.alipay.com/docs/api.htm?spm=a219a.7395905.0.0.XInh6e&docType=4&apiId=866
         * @param bizContent
         * @return
         * @throws AlipayApiException
         */
        public static boolean isTradeCancel(AlipayTradeCancelModel model) throws AlipayApiException{
            AlipayTradeCancelResponse response = tradeCancel(model);
            if(response.isSuccess()){
                return true;
            }
            return false;
        }
        
        public static AlipayTradeCancelResponse tradeCancel(AlipayTradeCancelModel model) throws AlipayApiException{
            AlipayTradeCancelRequest request = new AlipayTradeCancelRequest();
            request.setBizModel(model);
            AlipayTradeCancelResponse response = alipayClient.execute(request);
            return response;
        }
    

    9、使用沙盒环境测试

    下载沙箱模式下的app【沙箱钱包

    9.1 交易支付接口alipay.trade.pay测试
    
    /**
         * 条码支付
         * https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.Yhpibd&treeId=194&articleId=105170&docType=1#s4
         */
        public void tradePay() {
            String authCode = getPara("auth_code");
            String subject = "Javen 支付宝条形码支付测试";
            String totalAmount = "100";
            
            AlipayTradePayModel model = new AlipayTradePayModel();
            model.setAuthCode(authCode);
            model.setSubject(subject);
            model.setTotalAmount(totalAmount);
            model.setOutTradeNo(StringUtils.getOutTradeNo());
            model.setScene("bar_code");
            
            try {
                String resultStr = AliPayApi.tradePay(model);
                renderText(resultStr);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    

    打开沙箱钱包>付款>输入条形码测试

    返回的结果

    {
      "alipay_trade_pay_response": {
        "code": "10000",
        "msg": "Success",
        "buyer_logon_id": "abp***@sandbox.com",
        "buyer_pay_amount": "100.00",
        "buyer_user_id": "2088102169474200",
        "fund_bill_list": [
          {
            "amount": "100.00",
            "fund_channel": "ALIPAYACCOUNT"
          }
        ],
        "gmt_payment": "2017-05-07 20:28:35",
        "invoice_amount": "100.00",
        "open_id": "20881035070193409461376162014620",
        "out_trade_no": "050720283214941",
        "point_amount": "0.00",
        "receipt_amount": "100.00",
        "total_amount": "100.00",
        "trade_no": "2017050721001004200200238428"
      },
      "sign": "FZVBkb4tuqjM/3OZnAJJ8YFkGSmpcMIum+WdhCNURy+jSs5mZT2RZLlDuzVNHYoZQpItpVscDR86n87wFni/lhaNK0UvCkjQmSeBrmzuntFDrD8rh/KX3U3kpsQEmSzbI/E1VNYM3zL/lVPCnjkc9etVky8w690yHVqsRTBpjXDYUw91zdlm7iXjrRAv1vNWEhfaAgBh3toz8Asra03vFPMXaaGp4ARTI3AkjatH4zPO0JmDu3fMd+jk759FYW1qGf89LpLD/6ng+VNhu4rr3FC4RpLtYed9lKSrehlujGHSkhnWJcr0JZ6doYYF4aJuH7Eflyt+FCg/1JFzd0Mygw=="
    }
    
    9.2 交易查询接口alipay.trade.query测试
    public void tradeQuery(){
            try {
                AlipayTradeQueryModel model = new AlipayTradeQueryModel();
                model.setOutTradeNo("050720283214941");
                model.setTradeNo("2017050721001004200200238428");
                
                boolean isSuccess = AliPayApi.isTradeQuery(model);
                renderJson(isSuccess);
            } catch (AlipayApiException e) {
                e.printStackTrace();
            }
        }
    

    或者

    public void tradeQueryByStr(){
            String out_trade_no = getPara("out_trade_no");
            
            AlipayTradeQueryModel model = new AlipayTradeQueryModel();
            model.setOutTradeNo(out_trade_no);
    
            try {
                String resultStr = AliPayApi.tradeQuery(model).getBody();
                renderText(resultStr);;
            } catch (AlipayApiException e) {
                e.printStackTrace();
            }
        }
    

    返回的结果

    {
      "alipay_trade_query_response": {
        "code": "10000",
        "msg": "Success",
        "buyer_logon_id": "abp***@sandbox.com",
        "buyer_pay_amount": "100.00",
        "buyer_user_id": "2088102169474200",
        "fund_bill_list": [
          {
            "amount": "100.00",
            "fund_channel": "ALIPAYACCOUNT"
          }
        ],
        "invoice_amount": "100.00",
        "open_id": "20881035070193409461376162014620",
        "out_trade_no": "050720283214941",
        "point_amount": "0.00",
        "receipt_amount": "100.00",
        "send_pay_date": "2017-05-07 20:28:34",
        "total_amount": "100.00",
        "trade_no": "2017050721001004200200238428",
        "trade_status": "TRADE_SUCCESS"
      },
      "sign": "DE6qYfU0Nziv3Dxpaj0gUROcqMNmREwYUw/t9qlnLiuM1JkKEdNJtbyJZ8OCoOIkgXEOSs7+mOrGgyxmOQqccwwhkDDsYXhPnc0cy4M7L4sNl5S3nUaveBaZjk3SMMGif43UaYtVI6SF4kq74uyoH15tCWDJ0N3nYct2epgc7r6kprAFqQxszgYp4tfKLw0qPCKnUyo7+WRbrc6UWQVuK+xDlVcvivW5cXjAf/HFyb8o+ddj6g+QQ4jUN2WTc2QGpbtfum6G7oPHT99cjAURVRw2NmU5WfUXNazzSvisa2oYsl8EH7+XHvsAMyIUZw0Ix8ymuAXdMkrUPFY4PfzjIg=="
    }
    
    9.3 交易撤销接口alipay.trade.cancel测试
    public void tradeCancelByStr(){
            try {
                AlipayTradeCancelModel model = new AlipayTradeCancelModel();
                model.setOutTradeNo("050720283214941");
                model.setTradeNo("2017050721001004200200238428");
                
                AlipayTradeCancelResponse response = AliPayApi.tradeCancel(model);
                renderJson(response.getBody());
            } catch (AlipayApiException e) {
                e.printStackTrace();
            }
        }
    
    {
      "alipay_trade_cancel_response": {
        "code": "10000",
        "msg": "Success",
        "out_trade_no": "050720283214941",
        "retry_flag": "N"
      },
      "sign": "QFwTwACi/x/qZu7YCapToWKpYDatg7Y06KAxij01PHSQrq0+l9eeFGdNIRpD2rSmkCVN75RQManw4PvIEurN5uW6YSZlZQ0Rj2EeH0eVyNWqNRWmVGeSaLQ+hpAt3vG/cy5vXJ1Zl7yr/VbtRiuSYrbzPhgkG1UNYf9JIb4Nj2iSpo8Ct6Bbhiq848w7ZEN6itBmd04N3O4HkBoueuXtgUmKoaTegDfrtNtQ7dRAkCRnoa43QbHYysqwOO751JjI6HOeviZUrTspegUFbqhSXInaZ4LMqeiPWXeXc7dRmtOlPOSRY5wYzYYNCmEe89HdyLFSzd447QS2b5Ky3wAY3w=="
    }
    
    测试结果图

    相关文章

      网友评论

        本文标题:支付宝支付-刷卡支付(条码支付)

        本文链接:https://www.haomeiwen.com/subject/qunutxtx.html