INAPP登陆调用的FB接口
1 public function login_get (){ 2 $this->load->helper ( 'auth' ); 3 4 $redirectUrl = $this->input->cookie ( 'inapp_redirect', TRUE ); 5 $redirectUrl = empty ( $redirectUrl ) ? '/index' : $redirectUrl; 6 7 // 判斷是否已登入 8 if ( $this->input->cookie ( 'inapp_auth', TRUE ) ) { 9 delete_cookie ( 'inapp_redirect' ); 10 header ( 'Location: ' . $redirectUrl ); 11 exit; 12 } 13 14 $user = $this->facebook->getUser (); 15 if ( $user ) { // FB 己登入 16 // 删除 redirect cookie 17 delete_cookie ( 'inapp_redirect' ); 18 19 // 取得相對應的平台 uid 20 $params = array(); 21 $params[ 'fbid' ] = $user; 22 $sp = 'CALL Member_SP_GetMemberRegInfoByFbid(?,@rtn)'; 23 $member = $this->inapp->_query_sp ( $sp, $params, $error_no, 'row' ); 24 25 //增加禁權的攔截 26 $status = $member[ 'status' ]; 27 $checkStatus = $this->checkAccessBarred ( $status ); 28 if ( ! $checkStatus ) 29 exit (); 30 31 // 存在則寫 cookie 32 if ( $error_no == _SUCCESS_ ) { 33 // 登入 Log 34 $params = array(); 35 $params[ 'uid' ] = $member[ 'uid' ]; 36 $params[ 'appid' ] = 1000000; 37 $sp = 'CALL App_SP_SetAppDailyLoginLog_v2(?,?,@rtn)'; 38 $this->inapp->_query_sp ( $sp, $params, $error_no, 'row' ); 39 40 //会员积分登录时间 41 $this->memberBat ( $member[ 'uid' ] ); 42 43 //记录登陆信息 44 $this->member_model->addAdminLoginLog ( $member[ 'uid' ], 1, $params[ 'appid' ] ); 45 46 // 取得授權 47 $params = array(); 48 $params[ 'uid' ] = $member[ 'uid' ]; 49 $params[ 'appid' ] = 1000000; 50 $sp = 'CALL App_SP_SetUserApp(?,?,@rtn)'; 51 $this->inapp->_query_sp ( $sp, $params, $error_no, 'row' ); 52 53 // 產生 auth 54 $auth = $this->_genAuth ( authHelper_genUUID ( $member, $this->config->item ( 'inappKey' ) ) ); 55 $this->_setAuth ( $auth ); 56 header ( 'Location: ' . $redirectUrl ); 57 exit; 58 } 59 60 // 不存在則取得 FB 相關個人資料 61 $fbuser_profile = $this->facebook->api ( '/me' ); 62 63 // 寫入 Member DB 64 $params = array(); 65 $params[ 'fbid' ] = $fbuser_profile[ 'id' ]; 66 $params[ 'name' ] = empty ( $fbuser_profile[ 'name' ] ) ? '' : $fbuser_profile[ 'name' ]; 67 $params[ 'link' ] = empty ( $fbuser_profile[ 'link' ] ) ? '' : $fbuser_profile[ 'link' ]; 68 $params[ 'birthday' ] = empty ( $fbuser_profile[ 'birthday' ] ) ? '' : $fbuser_profile[ 'birthday' ]; 69 $params[ 'gender' ] = empty ( $fbuser_profile[ 'gender' ] ) ? '' : $fbuser_profile[ 'gender' ]; 70 $params[ 'email' ] = empty ( $fbuser_profile[ 'email' ] ) ? '' : $fbuser_profile[ 'email' ]; 71 $params[ 'ip' ] = $_SERVER[ "REMOTE_ADDR" ]; 72 73 $sp = 'CALL Member_SP_Register(?,?,?,?,?,?,?,@rtn)'; 74 $member = $this->inapp->_query_sp ( $sp, $params, $error_no, 'row' ); 75 76 // 註冊成功 77 if ( $error_no == _SUCCESS_ ) { 78 // 登入 Log 79 $params = array(); 80 $params[ 'uid' ] = $member[ 'uid' ]; 81 $params[ 'appid' ] = 1000000; 82 $sp = 'CALL App_SP_SetAppDailyLoginLog_v2(?,?,@rtn)'; 83 $this->inapp->_query_sp ( $sp, $params, $error_no, 'row' ); 84 85 //会员积分登录时间 86 $this->memberBat ( $member[ 'uid' ] ); 87 88 //记录登陆信息 89 $this->load->model ( 'member_model' ); 90 $this->member_model->addAdminLoginLog ( $member[ 'uid' ], 1, $params[ 'appid' ] ); 91 92 // 取得授權 93 $params = array(); 94 $params[ 'uid' ] = $member[ 'uid' ]; 95 $params[ 'appid' ] = 1000000; 96 $sp = 'CALL App_SP_SetUserApp(?,?,@rtn)'; 97 $this->inapp->_query_sp ( $sp, $params, $error_no, 'row' ); 98 99 // 產生 auth 100 $auth = $this->_genAuth ( authHelper_genUUID ( $member, $this->config->item ( 'inappKey' ) ) ); 101 } 102 103 header ( 'Location: ' . $redirectUrl ); 104 } else { // FB 未登入 105 $url = $this->facebook->getLoginUrl ( array('scope' => 'publish_stream, user_photos, email, user_birthday, user_online_presence', 'req_perms' => 5, 'fbconnect' => 0) ); 106 header ( 'Location: ' . $url ); 107 } 108 }