示例#1
0
function get_base_information($openid)
{
    $accessToken = get_access_token();
    $url = sprintf('https://api.weixin.qq.com/cgi-bin/user/info?access_token=%s&openid=%s&lang=zh_CN', $accessToken, $openid);
    $res = http_get_data($url);
    return $res;
}
示例#2
0
 /**
  * 用户通过第三方登陆方式来注册
  * @param String $openid 第三方提供的用户信息唯一标识,一般是保密的
  * @param String $name 第三方提供的昵称信息
  * @param Number $sex 第三方提供用户性别 0 男,1女
  * @param String $avatar_url 第三方提供用户头像url
  * @param String $sign 个性签名
  * @param String $type 第三方类型, 2 微信,3 QQ ,4微博
  * @return Number $uid 注册成功返回的Uid
  */
 public function userRegThroughThird($openid, $name, $sex, $avatar_url, $sign, $type)
 {
     $wechat_auth_str = $type == LOGIN_TYPE_WECHAT ? md5($openid) : '';
     $qq_auth_str = $type == LOGIN_TYPE_QQ ? md5($openid) : '';
     $weibo_auth_str = $type == LOGIN_TYPE_WEIBO ? md5($openid) : '';
     $user_data = array('phone' => 0, 'name' => $name, 'pwd' => '', 'spacebg' => 'files/spacebg/default.jpg', 'sex' => $sex, 'sign' => $sign, 'wechat_auth_str' => $wechat_auth_str, 'qq_auth_str' => $qq_auth_str, 'weibo_auth_str' => $weibo_auth_str, 'regtime' => date('Y-m-d H:i:s'));
     $uid = $this->user->insert($user_data);
     // 这个地方图片头像需要想办法处理一下
     // 生成对应的文件夹
     $path = 'files/avatar/' . date('Ymd') . '/';
     $ori_path = $path . 'ori/';
     $sm_path = $path . 'sm/';
     if (!is_dir($path)) {
         mkdir($path);
         mkdir($ori_path);
         mkdir($sm_path);
     }
     // 头像的处理
     if (!empty($avatar_url)) {
         $filename = date('YmdHis') . rand(0, 9);
         $ori_img_path = $ori_path . $filename . '.jpg';
         $sm_img_path = $sm_path . $filename . '.jpg';
         $round_img_path = $sm_path . $filename . '_round.png';
         $tmp_round_img_path = $sm_path . $filename . '_round_tmp.jpg';
         try {
             // 原图片的存储
             Log::write('begin to download avatar');
             $img = http_get_data($avatar_url);
             Log::write('download ok');
             file_put_contents(SKY_ROOT . $ori_img_path, $img);
             Log::write('save ok');
             // 缩略图的存储
             $ic = new ImgCrop(SKY_ROOT . $ori_img_path, SKY_ROOT . $sm_img_path);
             $ic->Crop(200, 200, 1);
             $ic->SaveImage();
             $ic->destory();
             // round小图的存储,好麻烦
             $ic = new ImgCrop(SKY_ROOT . $ori_img_path, SKY_ROOT . $tmp_round_img_path);
             $ic->Crop(100, 100, 4);
             $ic->SaveImage();
             $ic->destory();
             $rounder = new RoundCorner(SKY_ROOT . $tmp_round_img_path, 50);
             $rounder->round_it(SKY_ROOT . $round_img_path);
             unlink(SKY_ROOT . $tmp_round_img_path);
             $imgs = new Imgs();
             $mid = $imgs->insert(array('uid' => $uid, 'ori' => $ori_img_path, 'sm' => $sm_img_path, 'upload_time' => date('Y-m-d H:i:s')));
             if (!empty($mid)) {
                 $user = new User();
                 $user->update(array('avatar' => $mid), array('uid' => $uid));
             }
         } catch (Exception $e) {
             Log::write('get remote avatar ERR');
         }
     }
     return $uid;
     // 注册成功,返回$uid
 }
 public function indexAction()
 {
     //取出openId数据组
     $accessToken = get_access_token();
     $url = 'https://api.weixin.qq.com/cgi-bin/user/get?access_token=' . $accessToken;
     $jsonData = http_get_data($url);
     $data = json_decode($jsonData);
     $openids = $data->data->openid;
     //取出openid对应的其它信息
     $userInfo = array();
     foreach ($openids as $key => $value) {
         $userInfo[] = get_weichat_user_info($value, $accessToken);
     }
     $customer = D('Customer');
     $customer->addUserInfo($userInfo);
     $this->success('列表获取完成', U('Index/index'), 2);
 }
示例#4
0
function get_jsapi_ticket()
{
    $key = "jsapi_ticket";
    $jsapiTicket = S($key);
    if ($jsapiTicket != FALSE) {
        return $jsapiTicket;
    }
    $accessToken = get_access_token();
    $url = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token={$accessToken}";
    $res = json_decode(http_get_data($url));
    //   var_dump($res);
    $ticket = $res->ticket;
    if ($ticket) {
        S($key, $ticket, 6000);
    }
    return $ticket;
}
 public function deleteMenuAction()
 {
     $accessToken = get_access_token();
     $url = 'https://api.weixin.qq.com/cgi-bin/menu/delete?access_token=' . $accessToken;
     $res = http_get_data($url);
     $this->success("删除成功", U('CustomerMenu/index'), 2);
 }