Latitude Checkout API 使用 curl 返回 string(0) ""
Posted
技术标签:
【中文标题】Latitude Checkout API 使用 curl 返回 string(0) ""【英文标题】:Latitude Checkout API returns string(0) "" using curl 【发布时间】:2021-09-15 14:49:46 【问题描述】:我正在尝试将 Latitude 结帐集成到我的 prestashop 网站中。我已经使用 curl 实现了 API。 它总是返回字符串(0)“”。并且还在标题中显示 400 Bad Request。我期待重定向 url 作为输出。 这是我试过的代码
$url = "https://api.test.latitudefinancial.com/v1/applybuy-checkout-service/purchase";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
"Content-Type: application/json",
"Authorization: Basic MTIzNDU6bGZzbXNfXzI2NWM4N2QyNjAxYTQzNWQ5YzdmZDlkZDM5MzEyNDI4",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = '"merchantId":"directnetuser","isTest":true,"merchantReference":"102","amount":550.00,"currency":"AUD","promotionReference":"2012","customer":"firstName":"John","lastName":"Doe","phone":"0400000000","email":"john.doe@email.com","shippingAddress":"name":"John Doe","line1":"100 Spencer Street","line2":"tttt","city":"Melbourne","postcode":"3000","state":"VIC","countryCode":"AU","phone":"0400000000","billingAddress":"name":"John Doe","line1":"100 Spencer Street","line2":"tttt","city":"Melbourne","postcode":"3000","state":"VIC","countryCode":"AU","phone":"0400000000","orderLines":["name":"Echo Fit Compression Short","productUrl":"","sku":"WSH07-28-Black","quantity":5,"unitPrice":100.00,"amount":500.00,"requiresShipping":true,"isGiftCard":false,"name":"Short","productUrl":"","sku":"ACW-24-Black","quantity":2,"unitPrice":150.00,"amount":300.00,"requiresShipping":true,"isGiftCard":false],"merchantUrls":"cancel":"https://directnet.latitudecheckout.com/purchase/checkout","complete":"https://directnet.latitudecheckout.com/purchase/verify","totalShippingAmount":50.00,"platformType":"direct","platformVersion":"0.0.1"';
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_VERBOSE, true);
$resp = curl_exec($curl);
curl_close($curl);
var_dump($resp);
【问题讨论】:
您的主要问题是如何更正 HTTP 状态码 400 - Bad Request? 是的,我想通过纠正这个问题得到一个数组作为输出。 我试过没有 Content-Type: application/json 。现在它返回代码 303 查看其他。谁能帮我看看这个状态码是什么意思? 【参考方案1】:在 curl 执行前添加这两行
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
然后
$resp = curl_exec($curl);
【讨论】:
以上是关于Latitude Checkout API 使用 curl 返回 string(0) ""的主要内容,如果未能解决你的问题,请参考以下文章
通过 JSON 在 Google latitude API 中获取经过身份验证的用户的过去签到
尝试使用 google-api-ruby-client 更新 CurrentLocation 的 Google Latitude 返回“400 Invalid Value”
如何使用Facebook API从Latitude / Longitude获取城市的地方ID