简体   繁体   English

自定义Snipcart订单仪表板

[英]Custom Snipcart orders dashboard

I'm trying to create a custom Snipcart orders dashboard using their orders API but starting with this: 我正在尝试使用他们的订单API创建自定义Snipcart订单仪表板,但从这开始:

$query = curl_init();
$key = 'My-API-key';
$options = array(
  CURLOPT_URL            => 'https://app.snipcart.com/api/orders/',
  CURLOPT_USERPWD        => $key,
  CURLOPT_RETURNTRANSFER => 1,
  CURLOPT_SSL_VERIFYHOST => 0,
  CURLOPT_SSL_VERIFYPEER => 0,
  CURLOPT_HTTPHEADER     => 'Accept: application/json'
);

curl_setopt_array($query, $options);
$resp = curl_exec($query);
curl_close($query);
$body = json_decode($resp);

I'm not getting any output from $resp . 我没有从$resp获得任何输出。 Not sure where I'm going wrong. 不知道我哪里出错了。

We recently integrated Snipcart's data into a Wordpress site admin panel. 我们最近将Snipcart的数据集成到Wordpress网站管理面板中。

We use this code to make the request: 我们使用此代码发出请求:

function call_snipcart_api($url, $method = "GET", $post_data = null) {
    $url = 'https://app.snipcart.com/api' . $url;

    $query = curl_init();

    $headers = array();
    $headers[] = 'Content-type: application/json';
    if ($post_data)
        $headers[] = 'Content-Length: ' . strlen($post_data);
    $headers[] = 'Accept: application/json';

    $secret = 'Secret API Key';
    $headers[] = 'Authorization: Basic '.base64_encode($secret . ":");
    $options = array(
        CURLOPT_RETURNTRANSFER => 1,
        CURLOPT_URL => $url,
        CURLOPT_HTTPHEADER => $headers,
        CURLOPT_SSL_VERIFYHOST => 0,
        CURLOPT_SSL_VERIFYPEER => 0
    );

    if ($post_data) {
        $options[CURLOPT_CUSTOMREQUEST] = $method;
        $options[CURLOPT_POSTFIELDS] = $post_data;
    }

    curl_setopt_array($query, $options);
    $resp = curl_exec($query);
    curl_close($query);

    return json_decode($resp);
}

We then use like like this: 然后我们像这样使用:

// Get list of orders
$orders = call_snipcart_api('/orders');

// Get an order by its token
$order = call_snipcart_api('/orders/' . $orderToken);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM