正方形のサーバーから空の応答を受け取るのはなぜですか?正方形のAPIが空のJSONで応答します
試験場所の1つに場所を変更すると、何らかの応答が得られないようです。正しいサンドボックストークンを使用しています。私は意図せずに必要な情報を省略したり、何らかのバグやセキュリティメカニズムを引き起こしたりしましたか?どのような状況でも空の応答が適切であるとは想像できません。敏感な文字列は明白な理由で難読化されています。 cURLのリクエスト私が受け取るprint_r(curl_getinfo($curl_handle))
を使用し
{
"idempotency_key": "1",
"billing_address": {
"address_line_1": "123 Main Street",
"address_line_2": "",
"locality": "New York City",
"administrative_district_level_1": "NY",
"postal_code": "12345",
"country": "US"
},
"amount_money": {
"amount": 10,
"currency": "USD"
},
"delay_capture": false,
"buyer_email_address": "[email protected]",
"card_nonce": "122333444455555666666777777"
}
で使用
PHP
$url = 'https://connect.squareup.com/v2/locations/'.$location_id.'/transactions';
$curl_handle = curl_init($url);
$request_headers = array();
$request_headers[] = 'Content-Type: application/json';
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Authorization: Bearer '.$token;
$encodedData = json_encode($jsonData);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, $encodedData);
$request_headers[] = 'Content-Length: '.strlen($encodedData);
curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($curl_handle, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($curl_handle);
JSON:
Array
(
[certinfo] => Array()
[connect_time] => 0.101375
[content_type] => application/json
[download_content_length] => 2
[filetime] => -1
[header_size] => 372
[http_code] => 200
[local_ip] => 66.198.240.51
[local_port] => 44428
[namelookup_time] => 0.009074
[pretransfer_time] => 0.392582
[primary_ip] => 74.122.190.85
[primary_port] => 443
[redirect_count] => 0
[redirect_time] => 0
[redirect_url] =>
[request_size] => 734
[size_download] => 2
[size_upload] => 492
[speed_download] => 3
[speed_upload] => 979
[ssl_verify_result] => 0
[starttransfer_time] => 0.502108
[total_time] => 0.502167
[upload_content_length] => 492
[url] => https://connect.squareup.com/v2/locations/__example__/transactions
)
私は今、 *問題を解決しました。私は本当に*第三者のコードを嫌い、通常は肥大し巻き込まれています。私はここで最後の質問になることを願っています:https://stackoverflow.com/questions/46477085/square-value-was-not-expected-to-be-a-string私は絶対に興奮します。 – John
また、SDKを見て(私が必要とするJSONをうまく蒸留するために)、 'require 'vendor/autoload.php';を使用すると言いますが、SDKにベンダーディレクトリはありません。だから何? – John
PHP用のパッケージマネージャであるコンポーザーを使用する必要があります。このページのインストール手順をお読みください。https://github.com/square/connect-php-sdk – tristansokol