zoukankan      html  css  js  c++  java
  • 微信上传素材返回 '{"errcode":41005,"errmsg":"media data missing"}',php5.6返回

    问题描述:

    php5.5已经把通过@加文件路径上传文件的方式给放入到Deprecated中了。php5.6默认是不支持这种方式了

    解决办法curl处理

    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.');
                }
        }
    
    $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);
    
  • 相关阅读:
    关于Java 下 Snappy压缩存文件
    英文分词和中文分词
    vuex requires a Promise polyfill in this browser
    Vue 中 export default 和 module.exports
    Linux 进程以及多线程的支持
    mysqldump
    linux磁 盘分区 挂载
    ubuntu16.04挂载windows NTFS磁盘方法
    Linux服务管理 systemctl命令详解
    nextcloud 安装
  • 原文地址:https://www.cnblogs.com/padog/p/6150516.html
Copyright © 2011-2022 走看看