2011-10-15 19 views
8

大家好,我又回来了,在我上一篇文章中,我试图使用SOAP api(Integrating Dwolla with PHP with their API),但我发现SOAP API已被弃用,显然Dwolla有更有效的方法,如REST/oAuth2.0就是为什么我今天在这里问如何使用其余的API,因为它已经差不多2周了,我真的很想学习这个。使用Dwolla的API发送Money并使用PHP来完成它?

首先我会说我已经成功地获得了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)); 
     } 

?> 

我收到这样的消息例如

阵列(1){[ “的access_token”] = >字符串(50) “redacted”}警告: file_get_contents(https://www.dwolla.com/oauth/rest/accountapi/send): 无法打开流:HTTP请求失败! HTTP/1.1 503服务不可用 在/home/swiftbitcoins/purchase_order.php在线47 NULL

+0

谢谢,我忘了这一点:d – Xenland

+1

其所有的好,我再次我的凭据和旧的不再有效 – Xenland

+1

根据你的日志,我想你应该问dwolla。它说503服务不可用。这表明服务器存在问题。 – ariefbayu

回答

0

你正在尝试做一个GET请求,而Dwolla的文件称此为POST请求。

更好的你可以做的是用户他们的PHP库内置方法来打电话。这是一个标准库,用于进行稳定的调用,比写上述代码片段的方式要好得多。

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