php - 使用 Dwolla 的 API 汇款并使用 PHP 进行汇款?

标签 php api rest oauth-2.0 dwolla

大家好,我又回来了,在上一篇文章中,我尝试使用 SOAP API ( Integrating Dwolla with PHP with their API ),但我发现 SOAP API 已被弃用,显然 Dwolla 有更有效的方法,例如 REST/oAuth2 .0 这就是为什么我今天在这里询问如何使用 rest API 的原因,因为它已经将近 2 周了,我真的很想学习这个。

首先我会说我已经成功地获得了 access_token 我没有问题这样做。问题是,当我尝试使用发送端点(https://www.dwolla.com/developers/endpoints/accountapi/send)时,基本上是在尝试向账户汇款。我的确切问题是我永远无法得到成功的回应;仅错误或错误消息响应。

因此在索引页上我有“向您的帐户添加资金”链接。用户将单击该链接并将他们带到 Dwolla 页面,该页面将允许他们登录到他们的 Dwolla 帐户,然后接受该网站要求的权限。用户按下“接受”后,它将重定向到我选择的选定 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" } Warning: file_get_contents(https://www.dwolla.com/oauth/rest/accountapi/send): failed to open stream: HTTP request failed! HTTP/1.1 503 Service Unavailable in /home/swiftbitcoins/purchase_order.php on line 47 NULL

最佳答案

您尝试发出的是获取请求,而 Dwolla 文档将此称为发布请求。

您可以做的更好的事情是使用内置方法调用他们的 php 库。这是一个用于进行 Restful 调用的标准库,比您在上面的代码片段中编写的方式要好得多。

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

关于php - 使用 Dwolla 的 API 汇款并使用 PHP 进行汇款?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7774803/

相关文章:

php - 如何从特定 MongoDB 文档中的对象数组中获取特定对象?

java - 谷歌服务器验证码导致登录失败

java - Restful Webservice Java,服务器端

javascript - 如何在Angular JS模板中获取相关对象?

php - 序列化 Ajax 参数未显示在 PHP 中

php - 将不同的类别应用于不同的日期结果

php - 如何将 twitter api 与 "http basic auth"一起使用?

面向 Clojure 用户的 Java

rest - 聚合和事务的 DDD 问题

php - 需要帮助使 sql 查询按列比较数据