php如何发送此数据

php如何发送此数据,php,arrays,object,curl,Php,Arrays,Object,Curl,我必须将此数据发送到以下位置: -d '{"payer": { "default_payment_instrument":"BANK_ACCOUNT", "allowed_payment_instruments":["BANK_ACCOUNT"], "default_swift":"FIOBCZPP", "contact":{"first_name":"First", "last_name":"

我必须将此数据发送到以下位置:

-d '{"payer": {
        "default_payment_instrument":"BANK_ACCOUNT",
        "allowed_payment_instruments":["BANK_ACCOUNT"],
        "default_swift":"FIOBCZPP",
        "contact":{"first_name":"First",
                   "last_name":"Last",
                   "email":"first.last@example.com"
        }
    },
}'
如何将这些数据保存到
字段中
变量

$fields = {
  "payer": {
        "default_payment_instrument":"BANK_ACCOUNT",
        "allowed_payment_instruments":["BANK_ACCOUNT"],
        "default_swift":"FIOBCZPP",
        "contact":{"first_name":"First",
                   "last_name":"Last",
                   "email":"first.last@example.com"
        }
    },
};
$field_string = http_build_query($fields);
curl_setopt($process, CURLOPT_POSTFIELDS, $field_string);

好的,用卷发贴东西。给你

<?php

$target_url = "http://domain.dev/post-acceptor.php";

$data_to_post = array(
   "payer" => array(
        "default_payment_instrument" => "BANK_ACCOUNT",
        "allowed_payment_instruments" => "BANK_ACCOUNT",
        "default_swift" => "FIOBCZPP",
        "contact" => array(
           "first_name" => "First",
           "last_name" => "Last",
           "email" => "first.last@example.com"
        )
    )
);

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, $target_url);
curl_setopt($curl, CURLOPT_POST, count($data_to_post));
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data_to_post));

$result = curl_exec($curl);

curl_close($curl);
这是GoPay,对吗

这样做:

$fields = [
    "payer" => [
        "default_payment_instrument" => "BANK_ACCOUNT",
        "allowed_payment_instruments" => ["BANK_ACCOUNT"],
        "default_swift" => "FIOBCZPP",
        "contact" => [
            "first_name" => "First",
            "last_name" => "Last",
            "email" => "first.last@example.com"
        ]
    ]
];

$json = json_encode($fields);

curl_setopt($ch, CURLOPT_POSTFIELDS, $json);

你试过json_解码吗?这会转到哪里,端点需要什么形式?CURLOPT_POSTFIELDS应该是一个字符串而不是数组,所以这个函数是必需的。hanks@gopalmer的解决方案也在工作,它按照你的建议使用json_解码