public function downloadPic($openid='',$headimgurl='')
{
$header = array(
'User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:45.0) Gecko/20100101 Firefox/45.0',
'Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3',
'Accept-Encoding: gzip, deflate',);
$url=$headimgurl;
$curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
$data = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); curl_close($curl);
if ($code == 200) {//把URL格式的图片转成base64_encode格式的!
$imgBase64Code = "data:image/jpeg;base64," . base64_encode($data);
}
$img_content=$imgBase64Code;//图片内容
// echo $img_content;exit;
if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $img_content, $result))
{
$type = $result[2];//得到图片类型png?jpg?gif?
// dump($result);exit; $new_file = ROOT_PATH . 'public' . DS . 'uploads/'.$openid.'.'.$type;//存储目录
if (file_put_contents($new_file, base64_decode(str_replace($result[1], '', $img_content))))
{
$pic = $openid.'.'.$type;
return $pic;
}
} }

  

PHP下载微信头像的更多相关文章

  1. web-view中下载微信头像跨域解决方案

    let img = new Image() // 头像地址后边添加时间戳可解决跨域问题 555. img.src = 'http://wx.qlogo.cn/mmopen/vi_32/RnLIHfXi ...

  2. python批量下载微信好友头像,微信头像批量下载

    #!/usr/bin/python #coding=utf8 # 自行下载微信模块 itchat 小和QQ496631085 import itchat,os itchat.auto_login() ...

  3. Android 高仿微信头像截取 打造不一样的自定义控件

    转载请表明出处:http://blog.csdn.net/lmj623565791/article/details/39761281,本文出自:[张鸿洋的博客] 1.概述 前面已经写了关于检测手势识别 ...

  4. 使用canvas生成含有微信头像的邀请海报没有微信头像

    最近做了一个微信内访问的H5页面,长按分享图片发送朋友邀请的海报,网上搜索资料,得出解决思路,用canvas将页面绘制生成图片, 问题:canvas 图片跨域. 解决过程(填坑历程): 1.从网上存在 ...

  5. 麒麟子Cocos Creator实用技巧一:如何正确地显示微信头像

    不管是游戏App,还是H5,又或者是微信小游戏.但凡接入了微信登录的应用,都可能需要显示微信头像. 在Cocos Creator中,我们常见的显示方法像下面这样 var headimg = 'http ...

  6. 微信小程序获得微信头像和昵称

    微信小程序之登录态的探索 { wx.getSetting({ success: res => { if (res.authSetting && res.authSetting[' ...

  7. canvas跨域完美解决,微信头像解决跨域

    现在前端技术发展的越来越快,很多图片合成这种耗费服务器性能的,都可以移动到前端进行了合成了.而且合成很方便,我们利用 canvas 可以实现好多东西. 自动打算利用前端来合成图片,在网上就找到了 ht ...

  8. PHP远程下载图片,微信头像存到本地,本地图片转base64

    方法一(推荐): function download_remote_pic($url){ $header = [ 'User-Agent: Mozilla/5.0 (Windows NT 6.1; W ...

  9. file_get_contents微信头像等待时间过长的原因

    UPDATE 2016/05/13 stackoverflow上的解决方法:http://stackoverflow.com/questions/3629504/php-file-get-conten ...

随机推荐

  1. vue-cli3.0怎么修改端口?

    在根目录新建 vue.config.js 文件 module.exports = { devServer: { port: 8888, // 端口 }, lintOnSave: false // 取消 ...

  2. canvas和SVG

    Canvas的介绍 1.1.创建canvas元素 canvas的定义:它是HTML5中新增一个HTML5标签与操作canvas的javascript API,它可以实现在网页中完成动态的2D与3D图像 ...

  3. 使用 dva 如何配置异步加载路由组件

    来源:https://www.jianshu.com/p/69694013e36b----------------------------------------------------- 普通方式 ...

  4. redis最全配置讲解

    #redis.conf# Redis configuration file example.# ./redis-server /path/to/redis.conf ################# ...

  5. 让input不可编辑

    有时候,我们希望表单中的文本框是只读的,让用户不能修改其中的信息,如使<input type="text" name="input1" value=&qu ...

  6. servlet获取request数据的乱码解决

    例如请求中有: /score?type=Mana&name=${user.name} ***************************************************** ...

  7. mybatis 注解的方式批量插入,更新数据

    一,当向数据表中插入一条数据时,一般先检查该数据是否已经存在,如果存在更新,不存在则新增  使用关键字  ON DUPLICATE KEY UPDATE zk_device_id为主键 model  ...

  8. node.js学习5--------------------- 返回html内容给浏览器

    /** * http服务器的搭建,相当于php中的Apache或者java中的tomcat服务器 */ // 导包 const http=require("http"); cons ...

  9. java 秒时间格式化

    public static String durationFormat(Integer totalSeconds) { if (totalSeconds == null || totalSeconds ...

  10. LR单用户,重复操作日志

    案例:假如你想在一个脚本中,实现登录执行1次,查询执行2次,插入执行3次,怎么办?录3个脚本?每个事务分别在脚本中复制N次? 当然不用,LR早就想到了你的需求,下面让我们隆重推出Block. 位置: ...