7

こんにちは、また戻ってきました。前回の投稿で、SOAP API ( Dwolla と PHP の APIの統合) を使用しようとしていましたが、SOAP API は非推奨であり、Dwolla には REST/ などのより効率的な方法があることがわかりました。 oAuth2.0 について、私が今日ここに来て残りの API の使用方法を尋ねた理由は、ほぼ 2 週間が経過したためです。これについて学びたいと思っています。

まず、access_token の取得に成功しました。問題はありません。問題は、送信エンドポイント ( https://www.dwolla.com/developers/endpoints/accountapi/send ) を使用しようとすると、基本的にアカウントに送金しようとすることです。私の正確な問題は、成功した応答が得られないことです。false またはエラー メッセージ応答のみ。

そのため、インデックスページに「アカウントに資金を追加する」リンクがあります。ユーザーがそのリンクをクリックすると、Dwolla ページに移動し、Dwolla アカウントにサインインして、Web サイトが求めている許可を受け入れることができます。ユーザーが [Accept] を押すと、選択した URL にリダイレクトされ、承認目的で使用する access_token が返されます。これが私のコードです(これはDwollaもリダイレクトし、access_tokenも送信するページです)

<?php
//Define variables
    $key            = 'redacted';
    $secret         = 'redacted';
    $dwolla_client_id   = urlencode($key);
    $dwolla_secret_key  = urlencode($secret);
$code = urlencode($_GET["code"]);
//get token
    $retireve_token = file_get_contents("https://www.dwolla.com/oauth/v2/token?client_id=".$dwolla_client_id."&client_secret=".$dwolla_secret_key."&grant_type=authorization_code&redirect_uri=http://localhost/purchase_order.php&code=".$code);


    $decoded_json = json_decode($retireve_token, true);


        var_dump($decoded_json);
        if($decoded_json["access_token"]){
                    $arr = '{
                            "oauth_token": "'.$decoded_json["access_token"].'",
                            "fundsSource": "balance",
                            "pin": "1111",
                            "notes": "Payment for services rendered",
                            "amount": 1.01,
                            "destinationId": "812-111-1111",
                            "assumeCosts": false,
                            "facilitatorAmount": 0,
                            "destinationType": "dwolla"
                    }';
                    $opts = array('http'=>array('method'=>"POST",'content'=> $arr, 'header' => 'Content-Type: application/json'));

                    $ctx = stream_context_create($opts);
            $send_request = file_get_contents('https://www.dwolla.com/oauth/rest/accountapi/send', false, $ctx);

            var_dump(json_decode($send_request));
        }

?>

たとえば、このようなメッセージを受け取ります

array(1) { ["access_token"]=> string(50) "redacted" } 警告: file_get_contents( https://www.dwolla.com/oauth/rest/accountapi/send ): ストリームを開けませんでした: HTTP リクエスト失敗した!HTTP/1.1 503 Service Unavailable in /home/swiftbitcoins/purchase_order.php 行 47 NULL

4

1 に答える 1

0

あなたが作ろうとしているのは get リクエストですが、Dwolla のドキュメントではこれを post リクエストと呼んでいます。

あなたができることは、呼び出しを行うためのメソッドが組み込まれたphpライブラリを使用することです。これは安らかな呼び出しを行うための標準ライブラリであり、上記のコード スニペットで記述した方法よりもはるかに優れています。

https://github.com/Dwolla/dwolla-php

于 2015-08-03T08:56:55.247 に答える