开发者可以使用多种开发方式接入支付能力,开放平台提供了支持主流开发语言的SDK接入的方式, 建议开发者采用SDK接入模式。也支持使用自己熟悉的编程语言构造HTTP请求接入支付宝支付能力
以java语言为例,调用交易支付接口alipay.trade.pay:
AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", APP_ID, APP_PRIVATE_KEY, "json", CHARSET, ALIPAY_PUBLIC_KEY, "RSA2"); //获得初始化的AlipayClient
//创建API对应的request类
AlipayTradePayRequest request = new AlipayTradePayRequest();
request.setBizContent("{" +
" \"out_trade_no\":\"20150320010101001\"," +
" \"scene\":\"bar_code\"," +
" \"auth_code\":\"28763443825664394\"," +
" \"subject\":\"Iphone6 16G\"," +
" \"store_id\":\"NJ_001\"," +
" \"timeout_express\":\"2m\"," +
" \"total_amount\":88.88" +
" }"); //设置业务参数
//通过alipayClient调用API,获得对应的response类
AlipayTradePayResponse response = alipayClient.execute(request);
System.out.print(response.getBody());
//根据response中的结果继续业务逻辑处理
收起 | 了解更多SDK开发接入细节 | 查看相关的API
以调用交易支付接口alipay.trade.pay为例,构造http请求发起支付:
请注意需要对请求做urlencode处理,以下请求是为了方便查看,而没有做urlencode的原始报文
https://openapi.alipay.com/gateway.do?timestamp=2013-01-01 08:08:08&method=alipay.trade.pay&app_id=2284&sign_type=RSA2&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&version=1.0&biz_content=
{
"out_trade_no":"20150320010101001",
"scene":"bar_code,wave_code",
"auth_code":"28763443825664394",
"subject":"Iphone6 16G",
"seller_id":"2088102146225135",
"total_amount":"88.88",
"store_id":"NJ_001"
}
收起 | 查看相关的API