支付寶支付-提現到我的支付寶

此項目已開源歡迎Start、PR、發起Issues一塊兒討論交流共同進步
https://github.com/Javen205/IJPay
http://git.oschina.net/javen205/IJPayjavascript

提現到我的支付寶官方的名稱是單筆轉帳到支付寶帳戶java

一、建立應用並獲取APPID

若是沒有在開發平臺建立應用就得建立一個《開放平臺應用建立指南》
若是以前有建立過應用那麼就能夠直接添加功能git

添加單筆轉帳到支付寶帳戶

若是隻是測試不上線能夠跳過上面的步驟,直接使用沙盒環境測試github

二、配置密鑰

能夠參考《配置應用環境》json

生成RSA密鑰api

配置密鑰

三、下載服務端SDK

下載開放平臺服務端SDK微信

四、使用服務端SDK

4.1 初始化SDK
AlipayClient alipayClient = new DefaultAlipayClient(URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE); 

參數說明能夠參考關鍵參數說明app

4.2 接口調用

調用流程測試

說明:spa

一、若是商戶重複請求轉帳,支付寶會冪等返回成功結果,商戶必須對重複轉帳的業務作好冪等處理;若是不判斷,存在潛在的風險,商戶自行承擔所以而產生的全部損失。

二、若是調用alipay.fund.trans.toaccount.transfer掉單時,或返回結果code=20000時,或返回結果code=40004,sub_code= SYSTEM_ERROR時,請調用alipay.fund.trans.order.query發起查詢,若是未查詢到結果,請保持原請求不變再次請求alipay.fund.trans.toaccount.transfer接口。

三、商戶處理轉帳結果時,對於錯誤碼的處理,只能使用sub_code做爲後續處理的判斷依據,不可以使用sub_msg做爲後續處理的判斷依據。

4.3 SDK的調用

主要涉及到兩個接口

4.4 單筆轉帳到支付寶帳戶接口alipay.fund.trans.toaccount.transfer 封裝

直接調用轉帳接口若是返回不是Success 就調用轉帳查詢接口

/** * 單筆轉帳到支付寶帳戶 * https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.54Ty29&treeId=193&articleId=106236&docType=1 * @param content * @return * @throws AlipayApiException */ public static boolean transfer(AlipayFundTransToaccountTransferModel model) throws AlipayApiException{ AlipayFundTransToaccountTransferResponse response = transferToResponse(model); String result = response.getBody(); log.info("transfer result>"+result); System.out.println("transfer result>"+result); if (response.isSuccess()) { return true; } else { //調用查詢接口查詢數據 JSONObject jsonObject = JSONObject.parseObject(result); String out_biz_no = jsonObject.getJSONObject("alipay_fund_trans_toaccount_transfer_response").getString("out_biz_no"); AlipayFundTransOrderQueryModel queryModel = new AlipayFundTransOrderQueryModel(); model.setOutBizNo(out_biz_no); boolean isSuccess = transferQuery(queryModel); if (isSuccess) { return true; } } return false; } public static AlipayFundTransToaccountTransferResponse transferToResponse(AlipayFundTransToaccountTransferModel model) throws AlipayApiException{ AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); request.setBizModel(model); return alipayClient.execute(request); }
4.5 查詢轉帳訂單接口alipay.fund.trans.order.query 封裝
/** * 轉帳查詢接口 * @param content * @return * @throws AlipayApiException */ public static boolean transferQuery(AlipayFundTransOrderQueryModel model) throws AlipayApiException{ AlipayFundTransOrderQueryResponse response = transferQueryToResponse(model); log.info("transferQuery result>"+response.getBody()); System.out.println("transferQuery result>"+response.getBody()); if(response.isSuccess()){ return true; } return false; } public static AlipayFundTransOrderQueryResponse transferQueryToResponse(AlipayFundTransOrderQueryModel model) throws AlipayApiException{ AlipayFundTransOrderQueryRequest request = new AlipayFundTransOrderQueryRequest(); request.setBizModel(model); return alipayClient.execute(request); }

五、 接口測試

/** * 單筆轉帳到支付寶帳戶 * https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.54Ty29&treeId=193&articleId=106236&docType=1 */ public void transfer() { boolean isSuccess = false; String total_amount = "100"; AlipayFundTransToaccountTransferModel model = new AlipayFundTransToaccountTransferModel(); model.setOutBizNo(StringUtils.getOutTradeNo());//生成訂單號 model.setPayeeType("ALIPAY_LOGONID");//固定值 model.setPayeeAccount("abpkvd0206@sandbox.com");//轉帳收款帳戶 model.setAmount(total_amount); model.setPayerShowName("測試退款"); model.setPayerRealName("沙箱環境");//帳戶真實名稱 model.setRemark("javen測試單筆轉帳到支付寶"); try { isSuccess = AliPayApi.transfer(model); } catch (Exception e) { e.printStackTrace(); } renderJson(isSuccess); }

故意把帳戶真實名稱寫錯

{
  "alipay_fund_trans_toaccount_transfer_response": { "code": "40004", "msg": "Business Failed", "sub_code": "PAYER_USER_INFO_ERROR", "sub_msg": "付款用戶姓名或其它信息不一致", "out_biz_no": "051023044814944" }, "sign": "Zbm9lI9GbTlLbYsPQoJhd5y7+oevOInPFoKlRWp2064VUPZYUGBJRiM/8Ip8Vfz4MDhu+0Uc3gEzvoXk1O6eVj7bAPjGLc5cZI3gQNmbogTxeK/4eGgIjxJBKK46r6rzKgK2/e7YEBmExi6hACbo3inBqX0OnaIxIbedZnYY2qrkNdhIjiD1G/EWJNH846IEwhwLkihV7vVKXhIgfmfKmGu5jE7aNddwxKhAK8fAzTR7JOs8p/ZOcLD9/RHfUP1ro4HoNlUOrFUZfhxRuUEFwLxvcJon0HkcO6dnjNnXQx3jh/Ne3632SpWca1pZczervU3/z9/C0LVflQWna42t9g==" }

正確返回結果

{
  "alipay_fund_trans_toaccount_transfer_response": { "code": "10000", "msg": "Success", "order_id": "20170510110070001500460000004431", "out_biz_no": "051023003214944", "pay_date": "2017-05-10 23:00:30" }, "sign": "hedaOEcrS8CwzcLNFAQhLWJnmevaA4a+SsNuzuuyBHABUjJ+ZvagMoS1/eUpRIHfwXVOLxGVjCCtJzi4Irclqu2Roz9aHo8ROkNKFKbw66lcT2dOo9AWCYw8UVhQDUjjSZ/d+lu9nnpHPf3ZPPdFHvziBo6ghZF0DRiIX/9ZVx7uH7grFJb8SRbCbcF5C7eouJU8Aw9sMdu/XjREdlW7pLvjeinzouOLbIpICRP33JtGC/KhgdQltDzlXHtVgi9xWRJVXJVp7+jtDRbRP+V+ImY9NqYKtpfxtTBZZ1bW6nOxJaMV7ePgC/6GpDIyWjg+LdHQ09eeBtTy4XCOxtGe1g==" }

推薦閱讀:

微信、支付寶App支付-JPay0.0.2發佈
支付寶支付-刷卡支付(條碼支付)
支付寶支付-掃碼支付
一張二維碼集成微信、支付寶支付
支付寶Wap支付你瞭解多少?
Android版-支付寶APP支付

相關文章
相關標籤/搜索