passback_params:公用回传参数,如果请求时传递了该参数,则返回给商户时会回传该参数。支付宝只会在异步通知时将该参数原样返回。
本参数必须进行UrlEncode之后才可以发送给支付宝
1.代码示例:
//获得初始化的AlipayClient
AlipayClient alipayClient = new DefaultAlipayClient(AlipayConfig.gatewayUrl, AlipayConfig.app_id, AlipayConfig.merchant_private_key, "json", AlipayConfig.charset, AlipayConfig.alipay_public_key, AlipayConfig.sign_type);
//设置请求参数
AlipayTradePagePayRequest alipayRequest = new AlipayTradePagePayRequest();
alipayRequest.setReturnUrl(AlipayConfig.return_url);
alipayRequest.setNotifyUrl(AlipayConfig.notify_url);
//商户订单号,商户网站订单系统中唯一订单号,必填
String out_trade_no = new String(request.getParameter("WIDout_trade_no").getBytes("ISO-8859-1"),"UTF-8");
//付款金额,必填
String total_amount = new String(request.getParameter("WIDtotal_amount").getBytes("ISO-8859-1"),"UTF-8");
//订单名称,必填
String subject = new String(request.getParameter("WIDsubject").getBytes("ISO-8859-1"),"UTF-8");
//商品描述,可空
String body = new String(request.getParameter("WIDbody").getBytes("ISO-8859-1"),"UTF-8");
//设置自定义参数
String passback_params = "ab=测试一下;tdst=公共参数;ccsd=gds;dfa=23·12";
//将参数encode
String passback_params2 =java.net.URLEncoder.encode(passback_params,"UTF-8");
alipayRequest.setBizContent("{\"out_trade_no\":\""+ out_trade_no +"\","
+ "\"total_amount\":\""+ total_amount +"\","
+ "\"subject\":\""+ subject +"\","
+ "\"body\":\""+ body +"\","
+ "\"passback_params\":\""+ passback_params2 +"\","
+ "\"product_code\":\"FAST_INSTANT_TRADE_PAY\"}");
//请求
String result = alipayClient.pageExecute(alipayRequest).getBody();
注意事项
a).passback_params 必须encode,否则运行会报“订单信息无法识别,建议联系卖家”
b).自定义参数encode传入后,会将encode后的数据在异步通知中原样返回,异步通知数据返回如下:
app_id=2014100900013222&auth_app_id=2014100900013222&buyer_id=2088802862373955&buyer_pay_amount=0.01&charset=utf-8&fund_bill_list=[{"amount":"0.01","fundChannel":"ALIPAYACCOUNT"}]&gmt_create=2018-01-05 16:07:20&gmt_payment=2018-01-05 16:07:31&invoice_amount=0.01¬ify_id=02483fa093d2793a87f8bd5790818aanc1¬ify_time=2018-01-05 16:07:32¬ify_type=trade_status_sync&out_trade_no=2018151671825&passback_params={ab%3D%E6%B5%8B%E8%AF%95%3Bb%3D3421%3Bc%3Dgds}&point_amount=0.00&receipt_amount=0.01&seller_id=2088501624560335&sign=XXXXXXX&sign_type=RSA2&subject=测试&total_amount=0.01&trade_no=2018010521001004950523397325&trade_status=TRADE_SUCCESS&version=1.0
注意:
自定义参数不要与支付宝定义的参数,内置对象和属性等相同,以免发生不必要的错误 !!
如果您接入这个参数报错欢迎追问
正确的提问方式: 测试环境+开发语言+请求参数+appid+请求时间 方便判断问题