Beispiel #1
0
 public function get_wxinfo()
 {
     import("@.ORG.Wxhelper");
     $helper = new Wxhelper($this->pubwechat);
     $db = M('wechat_user');
     $uid = I('get.id');
     //查询用户信息
     $info = $db->find($uid);
     //获取用户微信资料
     $return = $helper->get_user_info($info['wechatid']);
     if ($return['errcode']) {
         echo "获取失败,错误信息:{errcode:{$return['errcode']},errmsg:{$return['errmsg']}}";
         die;
     } elseif (!empty($return['headimgurl'])) {
         //下载微信头像
         import("@.ORG.Http");
         import('@.ORG.Image.ThinkImage');
         $headimg = "./Data/upload/headimg/" . $uid . '.jpg';
         if (!is_file($headimg) || filesize($headimg) == 0) {
             //下载图片
             Http::curlDownload($return['headimgurl'], $headimg);
             $return['headimgurl'] = $headimg;
         }
         //保存用户最新微信资料
         $wxdata = array('subscribe' => $return['subscribe'], 'nickname' => $return['nickname'], 'sex' => $return['sex'], 'city' => $return['city'], 'province' => $return['province'], 'headimgurl' => $headimg, 'subscribe_time' => $return['subscribe_time']);
         $db->where(array('id' => $uid))->save($wxdata);
         $href = U('index', array('p' => I('get.p', 1), 'group_id' => I('get.group_id')));
         echo "获取微信资料成功,请<a href='{$href}'>刷新</a>页面查看!";
     } else {
         echo "获取微信资料成功!";
     }
 }