首页 > 解决方案 > 卷曲试图获取非对象的属性

问题描述

用 Coinbase 付款 a 写道:`

$amount = isset($_POST['AMOUNT']) ? filter_input(INPUT_POST, 'AMOUNT', FILTER_SANITIZE_NUMBER_FLOAT) : 0.0;
$memo = isset($_POST['MEMO']) ? filter_input(INPUT_POST, 'MEMO', FILTER_SANITIZE_STRING) : '';
$cust_name = isset($_POST['sName']) ? filter_input(INPUT_POST, 'sName', FILTER_SANITIZE_STRING) : '';
$cust_id = isset($_POST['sID']) ? filter_input(INPUT_POST, 'sID', FILTER_SANITIZE_NUMBER_INT) : 0;


$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.commerce.coinbase.com/charges/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$post = array(
    "name" => "Payement to CSI",
    "description" => $memo,
    "local_price" => array(
        'amount' => $amount,
        'currency' => 'USD'
    ),
    "pricing_type" => "fixed_price",
    "metadata" => array(
        'customer_id' => $cust_id,
        'customer_name' => $cust_name
    )
);

$post = json_encode($post);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_POST, 1);

$headers = array();
$headers[] = "Content-Type: application/json";
$headers[] = "X-Cc-Api-Key: 81xxxxxxxx-41a4-xxxxx-f4axxxxxxxx";
$headers[] = "X-Cc-Version: 2018-03-22";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
curl_close ($ch);
$response = json_decode($result);
return $response->data->hosted_url;`

但我得到一个错误:

试图在第 64 行的 C:\Users\kjkj\Documents\ProjetCrypt\coinBasePayment.php 中获取非对象的属性

我做了一个var_dump($response),它返回NULL,但为什么呢?我确定代码没问题。请有任何建议

标签: phpcurlcoinbase-php

解决方案


推荐阅读