条码支付集成开发者指南

来自    当面付 | 
作者:王兰玉  |  更新于:2019-01-28 10:49:32     

本帖仅供参考,非官方demo

一、官方文档

文档地址:点击【查看

sdk下载:点击【查看

官方demo下载地址:点击【查看

二、开发前准备工作

1、签约:https://openclub.alipay.com/read.php?tid=276&fid=72

2、创建应用:https://openclub.alipay.com/read.php?tid=1606&fid=72

3、生成密钥:https://openclub.alipay.com/read.php?tid=1833&fid=69

4、下载服务端sdk:https://docs.open.alipay.com/54/106370/

如何签约以及签约无法成功等相关签约问题https://openclub.alipay.com/read.php?tid=276&fid=72

注意事项:1、支持沙箱测试;2、需签约并添加功能;3、支持第三方调用。

检查调用appid的应用功能列表中是否添加“当面付”并显示已签约。

三、接口集成示例代码

支付宝网关:

沙箱环境支付宝网:https://openapi.alipaydev.com/gateway.do   

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

1、参数说明

(1)out_trade_no:商户订单号,由商户自定义设置;

(2)scene:支付场景

条码支付,取值:bar_code 

声波支付,取值:wave_code

(3)subject:商品标题

(4)auth_code:支付授权码,由用户支付宝app的“付钱”选项中获取

    

2、JAVA请求示例

沙箱账号

//沙箱APPID
	public static final  String app_id = "填写您的appid";
	//沙箱私钥pkcs8格式
	public static final  String merchant_private_key = "填写您的私钥";
	//支付宝公钥
	public static final  String alipay_public_key = "填写您的支付宝公钥";
	//沙箱网关地址
	public static final  String gatewayUrl = "https://openapi.alipaydev.com/gateway.do";
//正式环境网关地址
	//public static final  String gatewayUrl = "https://openapi.alipay.com/gateway.do";

(适用于jdk1.5以上)

   //获得初始化的AlipayClient
		AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, AlipayConfig.format, AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
		//创建API对应的request类		
		AlipayTradePayRequest request = new AlipayTradePayRequest(); //创建API对应的request类 
		request.setNotifyUrl("https://openclub.alipay.com/");
		AlipayTradePayModel model = new AlipayTradePayModel();
		model.setOutTradeNo("2019012020321558348254");
		//支付场景 条码支付,取值:bar_code ;声波支付,取值:wave_code
		model.setScene("bar_code");
		//支付宝钱包中的付款码
    	model.setAuthCode("285532156582655772");
		model.setSubject("我是subject");
		model.setTotalAmount("0.01");
		request.setBizModel(model);
		//通过alipayClient调用API,获得对应的response类			
		AlipayTradePayResponse response = alipayClient.execute(request);

		/**
		//下面两代码是使用第三方应用授权传值方式 授权传app_auth_token写法
	    // 第三方应用授权获取app_auth_token可参照该贴:https://openclub.alipay.com/read.php?tid=1649&fid=43 获取app_auth_token
	    //用于代商户发起请求,传值app_auth_token是谁授权的,钱就收到谁的账户中
	      String app_auth_token="";  
	      AlipayTradePayResponse response = alipayClient.execute(request,"",app_auth_token);
	     **/
		//判断是否请求成功
		if(response.isSuccess()){
			System.out.println("调用成功");
		} else {
			System.out.println("调用失败");
		}
		//返回信息
		System.out.println( response.getBody());

返回结果

{"alipay_trade_pay_response":{"code":"10000","msg":"Success","buyer_logon_id":"uqq***@sandbox.com","buyer_pay_amount":"0.01","buyer_user_id":"2088102175794899","buyer_user_type":"PRIVATE","fund_bill_list":[{"amount":"0.01","fund_channel":"ALIPAYACCOUNT"}],"gmt_payment":"2019-01-28 10:31:09","invoice_amount":"0.01","out_trade_no":"2019012020321558348254","point_amount":"0.00","receipt_amount":"0.01","total_amount":"0.01","trade_no":"2019012822001494890500811033"},"sign":"Kesok3smU3DMBbG3ErBb2547mGedldcGa3XE16A/eo987ENHFjZOymjMA5qr+riIeVn3te7vljhvAoRpKaJ0IIH8lLMiCo8L+RNkpHQmoxMl6i0pZA/rbv1N4Hpd68xdKJbPp43AJ1CoEVzjKwPN3fw5XOCLTGAXk8Z3xGRmBRIOJuZa7/+hy/kD2geIOraZgt9fI22Ho9QGr1mz5UWgK/WgHVGpxef/QgUfQynqZcNVBYrXDkfL7RXPuSQdemXAienLPZwYf3d+7cYY+LNmqv89pu1heAVup/SqMYyTOhAZZXTA3kuOcWYJ2zCJTVE7RvpSweHp6lituAu6ZtgGMg=="}

 

3、PHP版请求参数

(适用于php 5.5以上环境)

<?php
/**
 * 
 * 条码支付:https://docs.open.alipay.com/api_1/alipay.trade.pay
 */
require_once 'AopSdk.php';
$aop = new AopClient ();
$aop->appId = '填写您的appid';
$aop->rsaPrivateKey = '填写您的私钥';
$aop->alipayrsaPublicKey='填写您的支付宝公钥';
$aop->gatewayUrl = 'https://openapi.alipay.com/gateway.do';
$aop->apiVersion = '1.0';
$aop->postCharset='utf-8';
$aop->format='json';
$aop->signType = 'RSA2';

//生成随机订单号
$date=date("YmdHis");
$arr=range(1000,9999);
shuffle($arr);
$request = new AlipayTradePayRequest();
$request->setBizContent("{" .
    "\"out_trade_no\":\"".$date.$arr[0]."\"," .
    "\"total_amount\":\"0.1\"," .
	"\"scene\":\"bar_code\"," .
	"\"auth_code\":\"282535540301553598\"," .
	"\"subject\":\"tets\"," .
    "\"product_code\":\"FACE_TO_FACE_PAYMENT\"" .
    "}");
$result = $aop->execute($request);

//post请求
//$result = $aop->pageExecute($request);
var_dump($result);
?>

返回信息

public 'alipay_trade_pay_response' => 
    object(stdClass)[10]
      public 'code' => string '10000' (length=5)
      public 'msg' => string 'Success' (length=7)
      public 'buyer_logon_id' => string 'uqq***@sandbox.com' (length=18)
      public 'buyer_pay_amount' => string '0.10' (length=4)
      public 'buyer_user_id' => string '2088102175794899' (length=16)
      public 'buyer_user_type' => string 'PRIVATE' (length=7)
      public 'fund_bill_list' => 
        array (size=1)
          0 => 
            object(stdClass)[11]
              ...
      public 'gmt_payment' => string '2019-01-28 10:27:24' (length=19)
      public 'invoice_amount' => string '0.10' (length=4)
      public 'out_trade_no' => string '201901280227221355' (length=18)
      public 'point_amount' => string '0.00' (length=4)
      public 'receipt_amount' => string '0.10' (length=4)
      public 'total_amount' => string '0.10' (length=4)
      public 'trade_no' => string '2019012822001494890500811327' (length=28)
  public 'sign' => string 'ctTkcTpVtF3WGioFaw5lVtI4R4hdss/t/nqUlDQGyDY3zQaW+L3j8t889sxtRd9KZB7wGIDikFr7kySxTAdT3vqcp6OdyFqTQbpO+XznZK8SkV3HX/rkooD/wjzA4niTa6pdkbo/DENYZlK2NLfxaQZ6lnJXLfXiRPwOH0fVz9Qf5/Nw5aKKSe+GWs5e8rcCqr9sbsWt7DhVdXHnb9BSCZTeOCU3vimZzHa7+0o9RuxcJ6H4FRzPm9MIgePSPyUS7eONWb2WEBmIYo40eKnmIjnr9wnnvlmo4x/L9UG1pAcc9gtMSAQN+DyPwQQtXE7bZgvFidDhlAZ+bSyrXa1dMQ==' (length=344)

 

4、.NET版请求参数

//应用appId沙箱
            string appId = "appid";

            //支付宝网关
            string serverUrl = "https://openapi.alipaydev.com/gateway.do";

            //沙箱支付宝公钥
            string alipay_public_key = @"支付宝公钥";

            //开发者原始私钥,千万不要用pkcs8格式的 沙箱
            string merchant_private_key = @"商户应用私钥";

            IAopClient client = new DefaultAopClient(serverUrl, appId, merchant_private_key, "json", "1.0", "RSA2", alipay_public_key, "GBK", false);

            //IAopClient client = new DefaultAopClient("https://openapi.alipaydev.com/gateway.do", Com.Alipay.Config.appId, Com.Alipay.Config.merchant_private_key, "json", "1.0", "RSA2", Com.Alipay.Config.alipay_public_key, "GBK", false);
            AlipayTradePayRequest alipayRequest = new AlipayTradePayRequest();//创建API对应的request
            AlipayTradePayModel model = new AlipayTradePayModel();
            model.OutTradeNo = "20190128262815182234123";
            model.Subject = "沙箱条码支付测试";
            model.TotalAmount = "0.11";
            model.Scene = "bar_code";
            model.AuthCode = "289044087810204442";  //支付宝钱包中的付款码
            model.ProductCode = "FACE_TO_FACE_PAYMENT";
            alipayRequest.SetBizModel(model);
            //第三方调用方式
            // AlipayTradePayResponse response = client.Execute(alipayRequest, "", "app_auth_token");
            //自调用方式
            AlipayTradePayResponse response = client.Execute(alipayRequest);
            Console.WriteLine("条码支付返回信息:" + response.Body);

返回结果

条码支付返回信息:{"alipay_trade_pay_response":{"code":"10000","msg":"Success","buyer_logon_id":"uqq***@sandbox.com","buyer_pay_amount":"0.11","buyer_user_id":"2088102175794899","buyer_user_type":"PRIVATE","fund_bill_list":[{"amount":"0.11","fund_channel":"ALIPAYACCOUNT"}],"gmt_payment":"2019-01-28 10:11:46","invoice_amount":"0.11","out_trade_no":"20190128262815182234123","point_amount":"0.00","receipt_amount":"0.11","total_amount":"0.11","trade_no":"2019012822001494890500811217"},"sign":"VzXHbX1hbviodKtHuL5McBEnQxcyF/jrIG95/ReTiJkVRwQPyAYPOH/piwvpLzRYtLDzg1AyTCo9EV1NVRIXm22YRILXsl4TCmtbZ3dngEbiXLRBXJIA7XSSDOAYPhRSdmm8h1EK8n4DyfSOWoSaZn1Aq6aPSg7ulDsapEgruWai9RW7oKbklpMvE+fodeSp5dLjQf284Zf4kojacnsSyhZEnMh9n+p7l+u+LWSQ68VvLM6lLwqFAZyzn+u5T5BnEhcRigETt312W4vTpPNbupBudIdVin7FB6fB1hpdAgPA+RdmiG0Yox9eS2O8BzMjpN5quN4qS5em0KHIz3iW7A=="}

四、注意事项

1、调用接口返回10003状态

1).金额过大,需要用户手动输入密码,正式环境金额大于1000,沙箱环境因账户而异,以实测为准;

2).账户余额不足,导致扣款失败;

3).系统异常,网络问题,导致付款失败;

2、交易是否成功

接口返回1000只代表接口调用成功,不代表交易成功,交易成功建议使用查询接口查询。

3、条码限额

1千块钱以内是无需输入密码,直接扣款的,返回支付成功;

大于一千则会扫码后会跳出密码输入框,要求输入密码,不输入密码会返回1003(等待支付)状态;

4、“码已失效,请刷新二维码后重试”

1.检查auth_code 是否传值错误;

2.检查支付请求网关是沙箱还是正式环境,是否跟获取code码的钱包相符,可能沙箱环境用的正式钱包的码,正式环境用的沙箱钱包的条码;

5、沙箱钱包下载

沙箱账号查看地址:https://openhome.alipay.com/platform/appDaily.htm?tab=info

注意:沙箱钱包只适用于安卓手机,不支持ios;

6、辅助接口

alipay.trade.cancel(统一收单交易撤销接口)集成流程:https://openclub.alipay.com/read.php?tid=13966&fid=56

alipay.trade.query(统一收单线下交易查询)集成流程:https://openclub.alipay.com/read.php?tid=13842&fid=56

alipay.trade.refund(统一收单交易退款接口) 集成流程:https://openclub.alipay.com/read.php?tid=13853&fid=56

alipay.trade.fastpay.refund.query(统一收单交易退款查询) :https://openclub.alipay.com/read.php?tid=13962&fid=56

alipay.trade.close(统收单交易关闭接口)集成流程:https://openclub.alipay.com/read.php?tid=13963&fid=56

alipay.data.dataservice.bill.downloadurl.query(查询对账单下载地址):https://openclub.alipay.com/read.php?tid=14016&fid=56

 

 

如果还是报错,请按如下方式进行提问:

正确提问方式:使用环境(沙箱还是正式环境)+接口名称(中文+英文)+ 请求参数 + 报错信息详情

我的回复

返回顶部