提現微信和提現到支付寶

    首先微信和支付寶的流程都是前臺先拿到code,然後微信是通過code拿到用戶appid執行轉賬,支付寶是通過code拿到userid執行轉賬。

微信需要開通企業提現到零錢的業務,支付寶需要開通單筆資金轉賬到支付寶所對應的業務,如果要獲取用戶信息的話,還要開通會員信息功能。

微信對應的開發文檔:https://pay.weixin.qq.com/wiki/doc/api/tools/mch_pay.php?chapter=14_1

支付寶對應的開發文檔:https://docs.open.alipay.com/api_28/alipay.fund.trans.toaccount.transfer/

下面是支付寶提現到用戶支付寶功能代碼

    public Welipayorder authtoken(String code){
        ReturnResult result = new ReturnResult();
//         公鑰簽名
        try {
        AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", AlipayConfig.APP_ID,AlipayConfig.APP_PRIVATE_KEY, AlipayConfig.FORMAT, AlipayConfig.CHARSET, AlipayConfig.ALIPAY_PUBLIC_KEY, "RSA2");             
            AlipaySystemOauthTokenRequest request = new AlipaySystemOauthTokenRequest();
            System.out.println(code);
            request.setCode(code);
            request.setGrantType("authorization_code");
            try {
                System.out.println(request);
                AlipaySystemOauthTokenResponse oauthTokenResponse = alipayClient.execute(request);
                System.out.println(oauthTokenResponse.getBody());
                String out_bi_zno = trandno();
                weli.setOutbizno(out_bi_zno);
                AlipayFundTransToaccountTransferRequest request1 = new AlipayFundTransToaccountTransferRequest();
                System.out.println("payee_account========"+oauthTokenResponse.getAlipayUserId());
                request1.setBizContent("{" +
                "\"out_biz_no\""+":\""+ weli.getOutbizno() +"\"," +
                "\"payee_type\":\"ALIPAY_USERID\"," +
                "\"payee_account\""+":\""+ oauthTokenResponse.getUserId()+"\"," +
                "\"amount\":\"0.1\"," +
                "\"payer_show_name\":\"毛毛的\"," +
//                "\"payee_real_name\":\"毛俊剛\"," +
                "\"remark\":\"app提現到用戶支付寶\"" +
                "  }");
                
                System.out.println(request1.toString());
                AlipayFundTransToaccountTransferResponse response = alipayClient.execute(request1);
                if(response.isSuccess()){
                System.out.println("調用成功");
                } else {
                System.out.println("調用失敗");
                }
            } catch (AlipayApiException e) {
                //處理異常
                e.printStackTrace();
            }
            
        } catch (Exception e) {
            // TODO: handle exception
        }
            return weli;
    }
    public String trandno(){
        /**---------------開始生成訂單號 ------------------------**/
        //當前時間 yyyyMMddHHmmss
        String currTime = TenpayUtil.getCurrTime();
        //8位日期
        String strTime = currTime.substring(8, currTime.length());
        //四位隨機數
        String strRandom = TenpayUtil.buildRandom(4) + "";
        //10位序列號,可以自行調整
        String strReq = strTime + strRandom;
        //訂單號,此處用時間加隨機數生成,只要保持全局唯一就行
        String out_trade_no = strReq;
        out_trade_no = String.valueOf(UUID.next());
        return out_trade_no;
    }

由於微信封裝的比較多,所以關於 微信的提現方法更多內容,可百度雲盤下載關於微信提現項目源碼:https://pan.baidu.com/s/1lV8DYen7I6HW-tQVYfihJw

注意:微信提現讀取證書路徑windows絕對路徑爲:D:\\demo\\apiclient_cert.p12,如果在linux上面則路徑爲:/usr/demo/

apiclient_cert.p12。window用"\\"標識目錄分隔,二linux則用"/"標識目錄分隔。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章