【发布时间】:2016-10-09 08:50:30
【问题描述】:
我想使用 WePay 报告 API 进行报告,以在我的自定义应用程序中显示 WePay 交易和提款信息。当我调用 Wepayreports api 时,我在使用 PHP CURL 传递 JSON 数据时遇到了一些问题。
我的代码如下:
<?php
$data = array(
"type" => "merchant_transactions",
"resource" => array(
"object_type" => "account",
"object_id" => 634303761
)
);
$ch = curl_init('https://stage.wepayapi.com/v2/report/create'); // URL of the call
CURL_SETOPT($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1a2pre) Gecko/2008073000 Shredder/3.0a2pre ThunderBrowse/3.2.1.8');
// execute the api call
$result = curl_exec($ch);
// display the json response
echo '<pre>';
print_r(json_decode($result, true));
echo '</pre>';
?>
当我尝试在 API 调用中调用它时,接收如下数据
{"{\"type\":\"merchant_transactions\",\"resource\":{\"object_type\":\"account\",\"object_id\":\"1776251645\"}}":""}
但我需要发送如下数据:
{"type":"merchant_transactions","resource":{"object_type":"account","object_id":"1776251645"}}
WePay API Documantation 的链接供您参考。WePay Reports API
如果您有任何其他替代解决方案来解决此问题,请告诉我。
任何人都可以在这方面帮助我吗?任何形式的帮助表示赞赏。 提前致谢。
【问题讨论】:
-
只需使用他们的 PHP SDK,即围绕他们的 PHP API 的包装器。 github.com/wepay/php-sdk
-
使用
CURLOPT_HTTPHEADER并将其值设置为application/json。并发送实际的 json 字符串。