curl_exec()参数删除整数的最后2位数

时间:2016-11-28 12:01:59

标签: php web-services

我正在使用带有WordPress的softtouch API,并通过curl将数据发布到API。

但作为回应我无法在函数中发送大整数值。我没有得到数据类型范围问题或卷曲。

以下是我的代码:

//create reservation
$prod_items = array();
$single_item = array('product_uid'=>11449701010101);
$prod_items[] = $single_item;

$res_params = array(
    'customer_id' => 1111,
    'payment_type' => '',
    'invoice_address_id' => 123,
    'delivery_address_id' => 142,
    'giftlist_id' => '',
    'store_id' => '',
    'items' => $prod_items
);
$res_url = $base_url . 'reservations';    
$res_content = json_encode($res_params);

$res_curl = curl_init();
curl_setopt($res_curl, CURLOPT_HTTPHEADER, array('Authorization: ' . $authToken, 'Content-Type: application/json'));
curl_setopt($res_curl, CURLOPT_POST, true);
curl_setopt($res_curl, CURLOPT_POSTFIELDS, $res_content);
curl_setopt($res_curl, CURLOPT_URL, $res_url);
curl_setopt($res_curl, CURLOPT_RETURNTRANSFER, true);

$res_response = curl_exec($res_curl);

if ($res_response === FALSE)
die(curl_error($res_curl));
curl_close($res_curl);
$res_array = json_decode($res_response);

在向curl_exec()函数发送数据时,它会移除product_uid的最后两位数字,因为我将其11449701010101传递给114497010101

是否存在任何整数范围问题或卷曲函数问题?

1 个答案:

答案 0 :(得分:0)

tl:dr 似乎有其他(在处理CURL请求的脚本中)正在截断product_uid。 (?)

array('product_uid'=>11449701010101)

如果您使用的是32位系统(PHP编译为32位),那么11449701010101确实会超过32位整数范围。但是,在这种情况下,PHP 静默将数字转换为 float ,并且在此实例中没有任何“丢失”。

json_encode($res_params);

PHP函数json_encode()将传递的数组转换为字符串表示形式(JSON字符串)。什么都没有丢失。保留11449701010101值。

  

在向curl_exec()函数发送数据时,它会删除最后两位数

传输的(POST)数据是普通字符串,因此在此阶段不会丢失任何内容。

如果接收脚本然后解码传输的JSON字符串,再次对其进行编码并将其发回,则数据将完整无损地返回。 product_uid是浮点数,而不是整数(与原始数据中的一样)。

如果您专门强制11449701010101为整数(例如(int)11449701010101),那么您得到-681801035 - 最后2位数不会被简单地截断。对于要截断的最后2位数字,似乎会进行某种字符串操作?

因此,在处理此数据期间似乎还有其他内容(此处未显示)可能会截断该值。 (?)

相关问题