支付寶支付demo(親測)
阿新 • • 發佈:2017-12-03
pan 名稱 package form exe 類名 int rgs order
支付寶支付demo
這個是java後臺調起支付的demo,直接將body返回給安卓端即可調起支付
1 package com.dyy.test; 2 3 import java.text.SimpleDateFormat; 4 import java.util.Date; 5 import com.alipay.api.AlipayApiException; 6 import com.alipay.api.AlipayClient; 7 import com.alipay.api.DefaultAlipayClient; 8 import com.alipay.api.domain.AlipayTradeAppPayModel;9 import com.alipay.api.request.AlipayTradeAppPayRequest; 10 import com.alipay.api.response.AlipayTradeAppPayResponse; 11 12 public class TestZhiFu { 13 /** 14 * 支付寶方面訂單號獲取 15 * @param aliPrepayReq 16 * @return 17 * @throws OperationFailedException 18 */ 19 //private static final String Logger = "";20 private static final String APP_ID= "appid"; 21 private static final String APP_PRIVATE_KEY = "秘鑰"; 22 private static final String ALIPAY_PUBLIC_KEY = "公鑰"; 23 public static void main(String[] args) throws AlipayApiException { 24 TestZhiFu.APPqm();//生成訂單 25 // AppServers.chenggong();26 } 27 28 //服務端生成訂單的接口 29 30 public static void APPqm() { 31 String out_trade_no=new SimpleDateFormat("yyyymmddmmhhss").format(new Date());//產生一組隨機的訂單號 32 //實例化客戶端 33 AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do",APP_ID,APP_PRIVATE_KEY,"json","UTF-8",ALIPAY_PUBLIC_KEY,"RSA2"); 34 //實例化具體API對應的request類,類名稱和接口名稱對應,當前調用接口名稱:alipay.trade.app.pay 35 AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); 36 //SDK已經封裝掉了公共參數,這裏只需要傳入業務參數。以下方法為sdk的model入參方式(model和biz_content同時存在的情況下取biz_content)。 37 AlipayTradeAppPayModel model = new AlipayTradeAppPayModel(); 38 model.setBody("清揚洗發水"); 39 model.setSubject("洗發水"); 40 model.setOutTradeNo("20171110191203"); 41 model.setTimeoutExpress("90m"); 42 model.setTotalAmount("1.00"); 43 model.setProductCode("QUICK_MSECURITY_PAY"); 44 request.setBizModel(model); 45 request.setNotifyUrl("回調地址");//商戶外網可以訪問的異步地址,不能重定向 46 try { 47 //這裏和普通的接口調用不同,使用的是sdkExecute 48 AlipayTradeAppPayResponse response = alipayClient.sdkExecute(request); 49 //就是orderString 可以直接給客戶端請求,無需再做處理。 50 System.out.println(response.getBody()); 51 } catch (AlipayApiException e) { 52 e.printStackTrace(); 53 } 54 } 55 56 }
支付寶支付demo(親測)