搜索商品
接口调用请求说明
http请求方式:POST
https://api.weixin.qq.com/product/spu/search?access_token=xxxxxxxxx
请求参数示例
{
"keyword": "测试",(此处有个坑坑坑,待官方优化)
"source": 1,
"page": 1,
"page_size": 10
}
获取token:
获取数据:
$request_data=$_REQUEST;
$url = "https://api.weixin.qq.com/product/spu/search?access_token={$access_token}";
$keyword=$request_data['keyword'];
$url_data['keyword'] = '"'.$keyword.'"';
$url_data['page'] = $request_data['page'];
$url_data['page_size'] = $request_data['page_size'];
$url_data['source'] = $request_data['source'];
$json_data = json_encode($url_data);
$data = send_post_json($url, $json_data);
function send_post_json($url, $jsonStr)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($jsonStr)
)
);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return json_decode($response);
}