Example #1
0
 public function oauth_back()
 {
     $ac_id = intval($_GET['ac_id']);
     $auth_code = $_GET['auth_code'];
     $expires_in = $_GET['expires_in'];
     if (!empty($auth_code) && !empty($expires_in)) {
         $apiOauth = new apiOauth();
         $authorization_info = $apiOauth->get_authorization_info($auth_code);
         $authorizer_info = $apiOauth->get_authorizer_info($authorization_info['authorizer_appid']);
         $appid = $authorization_info['authorizer_appid'];
         $where = array('uid' => session('uid'));
         if (!empty($ac_id)) {
             $where['id'] = $ac_id;
         } else {
             $where['appid'] = $appid;
         }
         //file_put_contents('authorization_info.txt',json_encode($authorization_info));
         //file_put_contents('authorizer_info.txt',json_encode($authorizer_info));
         $wxinfo = M('Wxuser')->where($where)->find();
         if ($wxinfo) {
             $save = array();
             $save['type'] = 1;
             $save['encode'] = 2;
             $save['wxid'] = $authorizer_info['user_name'];
             $save['wxname'] = $authorizer_info['nick_name'];
             $save['weixin'] = $authorizer_info['alias'];
             $save['headerpic'] = empty($authorizer_info['head_img']) ? '' : $authorizer_info['head_img'];
             $service_type = $authorizer_info['service_type_info']['id'];
             $verify_type = $authorizer_info['verify_type_info']['id'];
             if (($service_type == 0 || $service_type == 1) && $verify_type == 0) {
                 $res['winxintype'] = 4;
             } else {
                 if ($service_type == 2 && $verify_type == 0) {
                     $res['winxintype'] = 3;
                 } else {
                     if ($service_type == 2 && $verify_type == -1) {
                         $save['winxintype'] = 2;
                     } else {
                         if (($service_type == 0 || $service_type == 1) && $verify_type == -1) {
                             $save['winxintype'] = 1;
                         }
                     }
                 }
             }
             $save['appid'] = $authorization_info['authorizer_appid'];
             $save['authorizer_access_token'] = $authorization_info['authorizer_access_token'];
             $save['authorizer_refresh_token'] = $authorization_info['authorizer_refresh_token'];
             $save['authorizer_expires'] = $authorization_info['expires_in'] + time();
             if (M('Wxuser')->where($where)->save($save)) {
                 $update = array('appid' => $save['appid'] . '_no', 'authorizer_access_token' => '', 'authorizer_refresh_token' => '', 'authorizer_expires' => 0);
                 M('Wxuser')->where("appid = '{$save['appid']}' AND id != {$wxinfo['id']}")->save($update);
                 $status = true;
             }
         } else {
             $status = $this->add_authorizer($authorizer_info, $authorization_info);
         }
         if ($status) {
             $this->success('公众号授权成功', U('Index/index'));
         } else {
             $this->error('公众号授权失败', U('Index/index'));
         }
     } else {
         $this->error('授权错误', U('Index/oauth'));
     }
 }
Example #2
0
 public function oauth_back()
 {
     $ac_id = intval($_GET["ac_id"]);
     $auth_code = $_GET["auth_code"];
     $expires_in = $_GET["expires_in"];
     if (!empty($auth_code) && !empty($expires_in)) {
         $apiOauth = new apiOauth();
         $authorization_info = $apiOauth->get_authorization_info($auth_code);
         $authorizer_info = $apiOauth->get_authorizer_info($authorization_info["authorizer_appid"]);
         $appid = $authorization_info["authorizer_appid"];
         $where = array("uid" => session("uid"));
         if (!empty($ac_id)) {
             $where["id"] = $ac_id;
         } else {
             $where["appid"] = $appid;
         }
         $wxinfo = M("Wxuser")->where($where)->find();
         if ($wxinfo) {
             $save = array();
             $save["type"] = 1;
             $save["encode"] = 2;
             $save["wxid"] = $authorizer_info["user_name"];
             $save["wxname"] = $authorizer_info["nick_name"];
             $save["weixin"] = $authorizer_info["alias"];
             $save["headerpic"] = empty($authorizer_info["head_img"]) ? "" : $authorizer_info["head_img"];
             $service_type = $authorizer_info["service_type_info"]["id"];
             $verify_type = $authorizer_info["verify_type_info"]["id"];
             if (($service_type == 0 || $service_type == 1) && $verify_type == 0) {
                 $res["winxintype"] = 4;
             } else {
                 if ($service_type == 2 && $verify_type == 0) {
                     $res["winxintype"] = 3;
                 } else {
                     if ($service_type == 2 && $verify_type == -1) {
                         $save["winxintype"] = 2;
                     } else {
                         if (($service_type == 0 || $service_type == 1) && $verify_type == -1) {
                             $save["winxintype"] = 1;
                         }
                     }
                 }
             }
             $save["appid"] = $authorization_info["authorizer_appid"];
             $save["authorizer_access_token"] = $authorization_info["authorizer_access_token"];
             $save["authorizer_refresh_token"] = $authorization_info["authorizer_refresh_token"];
             $save["authorizer_expires"] = $authorization_info["expires_in"] + time();
             if (M("Wxuser")->where($where)->save($save)) {
                 $update = array("appid" => $save["appid"] . "_no", "authorizer_access_token" => "", "authorizer_refresh_token" => "", "authorizer_expires" => 0);
                 M("Wxuser")->where("appid = '{$save["appid"]}' AND id != {$wxinfo["id"]}")->save($update);
                 $status = true;
             }
         } else {
             $status = $this->add_authorizer($authorizer_info, $authorization_info);
         }
         if ($status) {
             $this->success("公众号授权成功", U("Index/index"));
         } else {
             $this->error("公众号授权失败", U("Index/index"));
         }
     } else {
         $this->error("授权错误", U("Index/oauth"));
     }
 }