Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在WePay API中使用PHP CURL传递JSON数据?_Php_Json_Api_Curl_Wepay - Fatal编程技术网

如何在WePay API中使用PHP CURL传递JSON数据?

如何在WePay API中使用PHP CURL传递JSON数据?,php,json,api,curl,wepay,Php,Json,Api,Curl,Wepay,我想使用WePay reports API进行报告,以便在自定义应用程序中显示WePay交易和取款信息。当我调用Wepayreports api时,我在使用PHP CURL传递JSON数据时遇到了一些问题 我的代码如下所示: <?php $data = array( "type" => "merchant_transactions", "resource" => array( "object_type" => "account",

我想使用WePay reports 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>';
?>
<?php
$data = array(
    "type" => "merchant_transactions",
    "resource" => array(
        "object_type" => "account",
        "object_id" => 634303761
    )
);
$data_json = json_encode($data);
$ch = curl_init('https://stage.wepayapi.com/v2/report/create'); // URL of the call
CURL_SETOPT($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
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>';
?>
但我需要发送如下数据:

<?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>';
?>
<?php
$data = array(
    "type" => "merchant_transactions",
    "resource" => array(
        "object_type" => "account",
        "object_id" => 634303761
    )
);
$data_json = json_encode($data);
$ch = curl_init('https://stage.wepayapi.com/v2/report/create'); // URL of the call
CURL_SETOPT($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_json);
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>';
?>
这里是WePay API文档的链接,供您参考

如果您有任何其他解决此问题的替代方案,请让我知道

有谁能帮我这方面的忙吗?谢谢你的帮助。 提前感谢。

引用

调用参数应在请求体中作为JSON传递 将内容类型HTTP头设置为application/json。确保 设置有效的用户代理标头(我们的SDK会为您执行此操作)。这个 用户代理可以是任何东西,但要保持其信息性。例如: “WePay v2 PHP SDK v0.0.9”

你的答案就在这里:


下载WePay报告的最终代码如下


这是在自定义应用程序中集成WePay Reports API的非常有用的解决方案。这个解决方案对我100%有效。如果你遇到任何麻烦,请告诉我。我已经准备好回答。

只需使用他们的PHP SDK,即PHP API的包装器。使用
CURLOPT_HTTPHEADER
并将其值设置为
application/json
。并发送实际的json字符串。可能是重复的,非常感谢。这些信息对我很有帮助。你必须接受我的答案,而不是写你自己的答案(完全相同)。因为正是它帮助你解决了你的问题。
<?php
$data = array(
    "type" => "merchant_transactions",
    "resource" => array(
        "object_type" => "account",
        "object_id" => 634303761
    ),
    "callback_uri"=>"https://example.com/report/ipn"
);
$data = json_encode($data);

$access_token = 'STAGE_5d93d1cfb8a47da7f726fd0cacfeda5ghfhgfhfgh0f74adbc089e1d36d1dc1ccc5a57aafd92b'; // access_token received from /oauth2/token call
$ch = curl_init('https://stage.wepayapi.com/v2/report/create'); // URL of the call
CURL_SETOPT($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json',"Authorization: Bearer $access_token"));
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>';

?>
Array
(
    [report_id] => 23684078
    [user_id] => 22866774
    [resource] => Array
        (
            [object_type] => account
            [object_id] => 634303761
        )

    [type] => merchant_transactions
    [advanced_options] => Array
        (
            [disable_email] => 1
        )

    [state] => processing
    [request_time] => 1476023145
    [expires_time] => 
    [callback_uri] => https://example.com/report/ipn
    [report_uri] => 
)