PHP7 Curl简单的 <?php $url = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=$token&type=image'; $file_data = array("media" => new \CURLFile('22.jpg')); //22.jpg为服务器的绝对路径 $ch = curl_init(); curl_setopt($ch , CURLOPT_URL , $url); curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch , CURLOPT_POST, 1); curl_setopt($ch , CURLOPT_POSTFIELDS, $file_data); $output = curl_exec($ch); curl_close($ch);//关闭会话 print_r($output);//返回结果
php7.4 上传临时素材成功时候返回为空https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/Adding_Permanent_Assets.html php7.4上传素材时,错误时正常返回,正常提交,返回为空。
2023-04-28php7 我来个简单的 <?php $url = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=$token&type=image'; $file_data = array("media" => new \CURLFile('22.jpg')); //22.jpg为服务器的绝对路径 $ch = curl_init(); curl_setopt($ch , CURLOPT_URL , $url); curl_setopt($ch , CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch , CURLOPT_POST, 1); curl_setopt($ch , CURLOPT_POSTFIELDS, $file_data); $output = curl_exec($ch); curl_close($ch);//关闭会话 print_r($output);//返回结果
php7.4 上传临时素材无法成功php7.4使用curl上传临时素材,API返回空白(The requested URL returned error: 412 Precondition Failed),http状态码412 https://developers.weixin.qq.com/doc/offiaccount/Asset_Management/New_temporary_materials.html 同样的反馈帖子: https://developers.weixin.qq.com/community/develop/doc/000a6ca7ae4988a4d9f949d4456800 https://developers.weixin.qq.com/community/develop/doc/0004089f8d078823aef9b63655b400 <?php # 下面是我的测试代码: $url = 'https://api.weixin.qq.com/cgi-bin/media/upload?access_token=...&type=image'; $data = [ 'media' => new CURLFile('F:\web\30101441194a79ab.jpg') ]; $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_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $res= curl_exec($ch); $info = curl_getinfo($ch); curl_close($ch); echo '<pre>'; var_dump($res); var_dump($info); echo '</pre>'; ?>
2023-04-28