支付宝支付-提现到个人支付宝
此項目已開源歡迎Start、PR、發起Issues一起討論交流共同進步
https://github.com/Javen205/IJPay
http://git.oschina.net/javen205/IJPay
提現到個人支付寶官方的名稱是單筆轉賬到支付寶賬戶
1、創建應用并獲取APPID
如果沒有在開發平臺創建應用就得創建一個《開放平臺應用創建指南》
如果之前有創建過應用那么就可以直接添加功能
如果只是測試不上線可以跳過上面的步驟,直接使用沙盒環境測試
2、配置密鑰
可以參考《配置應用環境》
生成RSA密鑰
3、下載服務端SDK
下載開放平臺服務端SDK
4、使用服務端SDK
4.1 初始化SDK
AlipayClient alipayClient = new DefaultAlipayClient(URL, APP_ID, APP_PRIVATE_KEY, FORMAT, CHARSET, ALIPAY_PUBLIC_KEY, SIGN_TYPE);參數說明可以參考關鍵參數說明
4.2 接口調用
調用流程
說明:
1、如果商戶重復請求轉賬,支付寶會冪等返回成功結果,商戶必須對重復轉賬的業務做好冪等處理;如果不判斷,存在潛在的風險,商戶自行承擔因此而產生的所有損失。
2、如果調用alipay.fund.trans.toaccount.transfer掉單時,或返回結果code=20000時,或返回結果code=40004,sub_code= SYSTEM_ERROR時,請調用alipay.fund.trans.order.query發起查詢,如果未查詢到結果,請保持原請求不變再次請求alipay.fund.trans.toaccount.transfer接口。
3、商戶處理轉賬結果時,對于錯誤碼的處理,只能使用sub_code作為后續處理的判斷依據,不可使用sub_msg作為后續處理的判斷依據。
4.3 SDK的調用
主要涉及到兩個接口
單筆轉賬到支付寶賬戶接口alipay.fund.trans.toaccount.transfer
查詢轉賬訂單接口alipay.fund.trans.order.query
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);}5、 接口測試
/*** 單筆轉賬到支付寶賬戶* 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支付
總結
以上是生活随笔為你收集整理的支付宝支付-提现到个人支付宝的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 白酒能不能兑水溶c100?
- 下一篇: maven 整合支付宝,导入alipay