在使用小鹅通云服务API开发过程中,当传递二维数组时,后台总是提示The user id list must be an array.
即传递的参数必须是数组。
文档请求标准格式
{ "access_token": "xxxxxxxx", "user_id_list": [ "u_xxxx", "u_xxxx", "u_xxxx" ], "page": 1, "page_size": 3 }
其中"user_id_list"为二维数组。
PHP传参页面
require_once __DIR__ . '/libs/Client.php'; $client = new Client(); $url = "https://api.xiaoe-tech.com/xe.user.batch_by_user_id.get/1.0.0"; $method = "post"; //获取单个用户信息; $page_size = $_GET['page_size']; if ($page_size == "") { $page_size = 10; } $user_id_list = ['u_62b29be26704d_0cjjzuCSNk', '"u_62b2c2c2a121f_uFYhvzwnUP']; $params = ['user_id_list' => $user_id_list, 'page' => 1, 'page_size' => $page_size]; $result = $client->request($method, $url, $params); die(json_encode($result));
返回内容
{ "req_msg":"The user id list must be an array.", "req_code":8 }
错误提示页
运维管理–请求日志:
解决方案
将
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
修改为
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postdata));
http_build_query()就是将一个数组转换成url 问号?后面的参数字符串,并且会自动进行urlencode处理。
@lockdata.cn