码迷,mamicode.com
首页 > 微信 > 详细

【转】PHP微信上传永久图片素材

时间:2019-04-15 16:30:36      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:response   weixin   return   amp   not   class   image   curl   图片   

     $TOKEN="XXXX";
        $file = "D:\www\weixin\game.jpg";
        $data = array(
            ‘media‘=> new CURLFile($file)
        );
        $url = ‘https://api.weixin.qq.com/cgi-bin/material/add_material?access_token=‘.$TOKEN.‘&type=image‘;
        $result = curl_posts($url,$data);
        var_dump($result);

 
    function curl_posts($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.
                curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
                $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.‘);
            }

}

 

【转】PHP微信上传永久图片素材

标签:response   weixin   return   amp   not   class   image   curl   图片   

原文地址:https://www.cnblogs.com/zhangzhijian/p/10710876.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!