微信上传素材返回 '{"errcode":41005,"errmsg":"media data missing"}',php5.6返回
问题描述:
php5.5已经把通过@加文件路径上传文件的方式给放入到Deprecated中了。php5.6默认是不支持这种方式了
解决办法curl处理
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | function curl_post( $url , $data , $header = array ()){ if (function_exists( 'curl_init' )) { $ch = curl_init(); curl_setopt( $ch , CURLOPT_URL, $url ); if ( is_array ( $header ) && ! empty ( $header )){ $set_head = array (); foreach ( $header as $k => $v ){ $set_head [] = "$k:$v" ; } curl_setopt( $ch , CURLOPT_HTTPHEADER, $set_head ); } curl_setopt( $ch , CURLOPT_HEADER, 0); curl_setopt( $ch , CURLOPT_POST, 1); curl_setopt( $ch , CURLOPT_POSTFIELDS, $data ); curl_setopt( $ch , CURLOPT_RETURNTRANSFER, 1); curl_setopt( $ch , CURLOPT_TIMEOUT, 0); // 1s to timeout. $response = curl_exec( $ch ); if (curl_errno( $ch )){ //error return curl_error( $ch ); } $reslut = curl_getinfo( $ch ); print_r( $reslut ); curl_close( $ch ); $info = array (); if ( $response ){ $info = json_decode( $response , true); } return $info ; } else { throw new Exception( 'Do not support CURL function.' ); } } |
1 2 3 4 5 | $file = "a.jpg" ; $data = array ( 'media' => new CURLFile( $file ) ); $result = $this ->curl_post(self::WEIXIN_API . 'media/upload?access_token=' . $this ->get_access_token( $app_id , $app_secret ) . '&type=' . $type , $data ); |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步