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