$url = 'https://api.weixin.qq.com/product/spu/search?access_token='.$access_token;
$params = [
'source' => 1,
'page' => 1,
'page_size' => 10,
'keyword' => '方圆图',
];
appid:wx8c57701ead77cd40
文档链接:https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/business-capabilities/ministore/minishopopencomponent/API/spu/search_spu.html
def call_search(): print(f"self.access_token----{self.access_token}") import urllib.parse post_data = { "keyword": "乌合之众", 'source': 1, 'page': 1, 'page_size': 10 } headers = {'Content-Type': 'application/json; charset=UTF-8'} data = json.dumps(post_data, ensure_ascii=False) response_data = requests.post(f'https://api.weixin.qq.com/product/spu/search?access_token={self.access_token}', data=data.encode('utf-8'), headers=headers) res_data = response_data.json() print(f"res_data------{res_data}") return res_data
贴一段python的代码 希望兄弟们别踩坑
php post 提交需要中文不转码:json_encode($data, JSON_UNESCAPED_UNICODE)
function curl_post($url, $data) { $data = json_encode($data, JSON_UNESCAPED_UNICODE); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Content-Type: application/json;charset=UTF-8;' ) ); $handles = curl_exec($ch); curl_close($ch); return json_decode($handles, true); }