Xen*_*and 8 php api rest oauth-2.0 dwolla
大家好我回来了,我在去年的文章中,我试图使用SOAP API(使用PHP与他们的API集成Dwolla),但我发现了SOAP API已被废弃,显然Dwolla有更有效的方法,如REST/oAuth2.0这就是为什么我今天在这里问如何使用其余的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));
}
?>
Run Code Online (Sandbox Code Playgroud)
我收到这样的消息,例如
阵列(1){[ "ACCESS_TOKEN"] =>串(50) "绝密"}警告:的file_get_contents(https://www.dwolla.com/oauth/rest/accountapi/send):未能打开流:HTTP请求失败!第47行/home/swiftbitcoins/purchase_order.php中的HTTP/1.1 503服务不可用NULL
您试图发出的是 get 请求,而 Dwolla 文档将此称为 post 请求。
您可以做的更好的事情是使用他们的 php 库,使用内置方法进行调用。这是一个用于进行静态调用的标准库,比上面代码片段中编写的方式要好得多。
https://github.com/Dwolla/dwolla-php
归档时间: |
|
查看次数: |
1854 次 |
最近记录: |