/** * 会员注册 * member_id 会员id member_name 会员名 password 密码 salt 随机数 type 会员类型 type_name 会员类型名 avatar 头像 signature 个性签名 appid 应用id appname 应用名 create_time 注册时间 update_time 更新时间 ip 注册ip * * $appid * $appkey * $callback * * $mobile_verifycode * * 绑定表 * member_id 会员id platform_id 第三方平台会员id char nick_name 昵称 type 会员类型 type_name 会员类型名称 avatar_url 头像地址 bind_time 绑定时间 bind_ip 绑定ip * * 返回 * member_id * member_name * type * avatar * access_token */ public function register() { try { $this->check_verifycode(); //验证码 $this->oldtype = $this->type = trim($this->input['type']); $member_name = $this->checkRegMemberName(); $this->checkRegType(); $this->checkRegMemberNameError(); $password = trim($this->input['password']); $identifierUserSystem = new identifierUserSystem(); $identifier = $identifierUserSystem->setIdentifier((int) $this->input['identifier'])->checkIdentifier(); //多用户系统 if (empty($this->type)) { $this->errorOutput(NO_MEMBER_TYPE); } $platformInfo = $this->Members->get_platform_name($this->type); if (empty($platformInfo)) { $this->errorOutput(REG_MEMBER_TYPE_ERROR); } else { if (!$platformInfo['status']) { $this->errorOutput(REG_MEMBER_TYPE_CLOSE); } } $type_name = $platformInfo['name']; $signature = trim($this->input['signature']); $ip = hg_getip(); $appid = intval($this->input['appid']); $appkey = trim($this->input['appkey']); $platform_id = ''; $mobile_verifycode = trim($this->input['mobile_verifycode']); $email = trim($this->input['email']); $reg_mail = $this->Members->check_reg_mail($email, 0, $identifier); if ($reg_mail == -4) { $this->errorOutput(EMAIL_FORMAT_ERROR); } elseif ($reg_mail == -5) { $this->errorOutput(EMAIL_NO_REGISTER); } elseif ($reg_mail == -6) { $this->errorOutput(EMAIL_HAS_BINDED); } $this->type == 'email' && $this->checkEmailVerifyCode($member_name); $this->type != 'email' && $email && $this->checkEmailVerifyCode($email); $_mobile = trim($this->input['mobile']); //简单验证手机号格式 if ($_mobile && !hg_verify_mobile($_mobile)) { $this->errorOutput(MOBILE_NUMBER_FORMAT_ERROR); } else { if ($_mobile && (isset($this->input['mobile_verifycode']) || defined('NO_VERIFY_MOBILEBIND') && NO_VERIFY_MOBILEBIND)) { $check_bind = new check_Bind(); if ($check_bind->checkmembernamereg($_mobile, $identifier)) { $this->errorOutput(MOBILE_REG_BIND); } } } if ($this->type != 'shouji' && $_mobile && isset($this->input['mobile_verifycode'])) { //验证码 $verifycode = $this->mSmsServer->get_verifycode_info($_mobile, $mobile_verifycode); if (empty($verifycode)) { $this->errorOutput(VERIFY_FAILED); } //删除验证码 $this->mSmsServer->mobile_verifycode_delete($_mobile, $mobile_verifycode); if (TIMENOW > $verifycode['create_time'] + VERIFYCODE_EXPIRED_TIME) { $this->errorOutput(VERIFY_EXPIRED); } $this->ismobileverify = 1; } else { if ($this->type != 'shouji' && $_mobile && defined('NO_VERIFY_MOBILEBIND') && NO_VERIFY_MOBILEBIND) { $this->ismobileverify = 1; } } $device_token = $this->Members->check_device_token(trim($this->input['device_token'])); if ($device_token === 0) { $this->errorOutput(ERROR_DEVICE_TOKEN); } $udid = $this->Members->check_udid(trim($this->input['uuid'])); if ($udid === 0) { $this->errorOutput(ERROR_UDID); } //验证设备号和ip是否在黑名单 if ($udid) { $device_res = $this->Blacklist->detailDeviceBlacklist(array('device_token' => $udid, 'identifier' => $identifier)); if ($device_res[0]['deadline'] == -1 && $device_res[0]['type'] == 2) { $this->errorOutput(DEVICE_BLACKLIST_FOREVER); } elseif ($device_res[0]['deadline'] == -1) { $this->errorOutput(DEVICE_BLACKLIST); } } if ($ip) { $ip_res = $this->Blacklist->detailIpBlacklist(array('ip' => ip2long($ip), 'identifier' => $identifier)); if ($ip_res[0]['deadline'] == -1 && $ip_res[0]['type'] == 2) { $this->errorOutput(IP_BLACKLIST_FOREVER); } elseif ($ip_res[0]['deadline'] == -1) { $this->errorOutput(IP_BLACKLIST); } } //密码 if (!$password) { $this->errorOutput(NO_PASSWORD); } //验证手机验证码 if ($this->type == 'shouji') { $check_bind = new check_Bind(); if ($check_bind->checkmembernamereg($member_name, $identifier)) { $this->errorOutput(MOBILE_REG_BIND); } $platform_id = $mobile = $member_name; $_mobile = $mobile ? $mobile : $_mobile; //简单验证手机号格式 if (!hg_verify_mobile($mobile)) { $this->errorOutput(MOBILE_NUMBER_FORMAT_ERROR); } if (!$mobile_verifycode) { $this->errorOutput(MOBILE_NOT_VERIFY); } //验证码 $verifycode = $this->mSmsServer->get_verifycode_info($mobile, $mobile_verifycode); if (empty($verifycode)) { $this->errorOutput(VERIFY_FAILED); } //删除验证码 $this->mSmsServer->mobile_verifycode_delete($mobile, $mobile_verifycode); if (TIMENOW > $verifycode['create_time'] + VERIFYCODE_EXPIRED_TIME) { $this->errorOutput(VERIFY_EXPIRED); } } //如果是m2o注册类型屏蔽字检测 if ($this->settings['App_banword']) { include ROOT_PATH . 'lib/class/banword.class.php'; $banword = new banword(); $signature_banword = $banword->exists($signature); if ($signature_banword && is_array($signature_banword)) { $this->errorOutput(SIGNATURE_INVALID); } } if ($this->type == 'm2o' && $this->settings['App_banword']) { $member_name_banword = $banword->exists($member_name); if ($member_name_banword && is_array($member_name_banword)) { $this->errorOutput(MEMBER_NAME_INVALID); } } //头像 $avatar = array(); if (isset($this->input['avatar']) && $_FILES['avatar']['tmp_name']) { $avatar = $_FILES['avatar']; } //验证会员名 $ret_verify = $this->mMember->verify_member_name($member_name, 0, $identifier, $type); switch ($ret_verify) { case -1: $this->errorOutput(MEMBER_NAME_ILLEGAL); break; case -2: $this->errorOutput(PROHIBITED_WORDS); break; case -3: $this->errorOutput(UC_MEMBER_NAME_REGISTER); break; case -4: $this->errorOutput(MEMBER_NAME_EXCEEDS_MAX); break; case -5: $this->errorOutput(USERNAME_BELOW_MINIMUM); break; case -6: $this->errorOutput(MEMBER_NAME_ERROR); break; case -7: $this->errorOutput(MEMBER_NAME_REGISTER); break; default: break; } //随机串 $salt = hg_generate_salt(); //密码md5 $md5_password = md5(md5($password) . $salt); $groupInfo = $this->Members->checkgroup_credits(0); $gradeInfo = $this->Members->checkgrade_credits(0); $data = array('member_name' => $member_name, 'password' => $md5_password, 'salt' => $salt, 'type' => $this->type, 'type_name' => $type_name, 'gid' => $groupInfo['gid'], 'gradeid' => $gradeInfo['gradeid'], 'signature' => $signature, 'mobile' => $_mobile, 'email' => $email, 'status' => $this->settings['member_status'], 'identifier' => $identifier, 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'create_time' => TIMENOW, 'update_time' => TIMENOW, 'ip' => $ip, 'guid' => guid(), 'reg_device_token' => $device_token, 'reg_udid' => $udid); //入ucenter $inuc = 0; if ($this->type == 'm2o' && $this->settings['ucenter']['open'] && !$identifier) { //邮箱 m2o类型必须传入email if (!$email) { $this->errorOutput(NO_EMAIL); } $virtual_email = $email; //忽略返回值 $reinfo = $this->uc_register(array('member_name' => $data['member_name'], 'password' => $password, 'email' => $virtual_email)); $inuc = $reinfo['member_id']; } //会员数据入库 $ret = $this->mMember->create($data); if (!$ret['member_id']) { $this->errorOutput(MEMBER_DATA_ADD_FAILED); } $member_id = $ret['member_id']; //编辑扩展信息 #@param platformMark 平台标示 if ($this->input['platformMark'] && $this->input['platformMark'] == 'dingdone' && $this->input['identifier']) { //为叮当注册根据app配置不同的扩展信息 $this->mMemberInfo->extension_editByApp($member_id, $this->input['member_info'], $this->input['identifier'], $_FILES); } else { $this->mMemberInfo->extension_edit($member_id, $this->input['member_info'], $_FILES); } //获取扩展信息 $extension = $this->getExtensionInfo($member_id, $identifier); if (!$identifier) { $invite_user = new invite(); $id = $this->input['invite_id'] ? $this->input['invite_id'] : 0; //邀请码id $invite_code = $this->input['invite_code'] ? $this->input['invite_code'] : $member_name; //如果未传邀请码则已用户名为邀请码去邀请数据库查询是否存在邀请信息,目前仅支持手机注册类型用户名; $invite = $invite_user->invite_rules($member_id, $invite_code, $id); //邀请用户处理 $this->invite_error($invite); } //uc打开平台id为uc 否则为自身id if ($this->type == 'm2o') { $platform_id = $this->settings['ucenter']['open'] && $reinfo['member_id'] > 0 && !$identifier ? $reinfo['member_id'] : $member_id; } elseif ($this->type == 'email') { $platform_id = $member_name; } $data['member_id'] = $member_id; //绑定表 $bind_data = array('member_id' => $member_id, 'platform_id' => $platform_id, 'nick_name' => $member_name, 'type' => $this->type, 'type_name' => $type_name, 'bind_time' => TIMENOW, 'bind_ip' => $ip, 'inuc' => $inuc, 'is_primary' => 1, 'identifier' => $identifier, 'reg_device_token' => $device_token, 'reg_udid' => $udid); $ret_bind = $this->mMember->bind_create($bind_data); if (empty($ret_bind)) { $this->errorOutput(BIND_DATA_ADD_FAILED); } $this->registerCreditRules($member_id); //注册相关积分规则 //如果注册时填写邮箱则可以同时入绑定表 if ($data['email']) { if ($this->type != 'email' && $this->isemailverify) { $_bind_data = $bind_data; $_bind_data['platform_id'] = $data['email']; $_bind_data['is_primary'] = 0; $_bind_data['type'] = 'email'; $_bind_data['type_name'] = '邮箱'; $_ret_bind = $this->mMember->bind_create($_bind_data); if (empty($_ret_bind)) { $this->errorOutput(BIND_DATA_ADD_FAILED); } unset($_bind_data, $_ret_bind); } } if ($data['mobile']) { if ($this->type != 'shouji' && $this->ismobileverify) { $_bind_data = $bind_data; $_bind_data['platform_id'] = $data['mobile']; $_bind_data['is_primary'] = 0; $_bind_data['type'] = 'shouji'; $_bind_data['type_name'] = '手机'; $_ret_bind = $this->mMember->bind_create($_bind_data); if (empty($_ret_bind)) { $this->errorOutput(BIND_DATA_ADD_FAILED); } unset($_bind_data, $_ret_bind); } } //头像入库 if (!empty($avatar)) { $avatar = $this->mMember->add_material($avatar, $member_id); if (!empty($avatar)) { $update_data = array('member_id' => $member_id, 'avatar' => daddslashes(serialize($avatar))); $ret_updata = $this->mMember->update($update_data); if (!$ret_updata['member_id']) { $this->errorOutput(AVATAR_ADD_FAILED); } } } else { $avatar_url = $this->input['avatar_url'] ? trim($this->input['avatar_url']) : ''; if ($avatar_url) { $avatar = $this->mMember->local_material($avatar_url, $member_id); if (!empty($avatar)) { $update_data = array('member_id' => $member_id, 'avatar' => daddslashes(serialize($avatar))); $ret_updata = $this->mMember->update($update_data); if (!$ret_updata['member_id']) { $this->errorOutput(AVATAR_ADD_FAILED); } } } } //到auth接口取access_token $callback = 'http://' . $this->settings['App_members']['host'] . '/' . $this->settings['App_members']['dir'] . 'login.php?a=verify_member&appid=' . $appid . '&appkey=' . $appkey; $encryptPassword = urlencode(passport_encrypt($password, CUSTOM_APPKEY)); $auth_data = array('user_name' => $member_name, 'appid' => $appid, 'appkey' => $appkey, 'ip' => $ip, 'verify_user_cb' => $callback, 'extend' => 'platform_id=' . $platform_id . '&password='******'&encrypt=1&type=' . $this->type . '&identifier=' . $identifier); $auth = $this->mMember->get_access_token($auth_data); if (!$auth['token']) { $this->errorOutput(MEMBERS_LOGIN_ERROR); } $return = array('member_id' => $member_id, 'member_name' => $ret['member_name'], 'nick_name' => $auth['nick_name'], 'platform_id' => $auth['platform_id'], 'inuc' => $auth['inuc'] ? $auth['inuc'] : 0, 'type' => $this->type, 'type_name' => $auth['type_name'], 'avatar' => $avatar, 'access_token' => $auth['token'], 'guid' => $auth['guid'], 'gid' => $auth['gid'], 'gradeid' => $auth['gradeid'], 'copywriting_credit' => $auth['copywriting_credit'], 'copywriting' => $auth['copywriting'], 'signature' => $auth['signature'], 'mobile' => $auth['mobile'], 'email' => $auth['email'], 'isVerify' => $auth['isVerify'], 'isComplete' => $auth['isComplete'], 'identifier' => $auth['identifier'], 'last_login_device' => $auth['last_login_device']); if ($extension) { $return['extension'] = $extension; } //会员痕迹 $member_trace_data = array('member_id' => $member_id, 'member_name' => $member_name, 'content_id' => $member_id, 'title' => $member_name, 'type' => 'register', 'op_type' => '注册', 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'create_time' => TIMENOW, 'ip' => hg_getip(), 'device_token' => $device_token, 'udid' => $udid); $this->mMember->member_trace_create($member_trace_data); //记录登陆信息 $loginInfoRecord = array('last_login_device' => $member_trace_data['device_token'], 'final_login_time' => $member_trace_data['create_time'], 'last_login_time' => $member_trace_data['create_time'], 'last_login_udid' => $member_trace_data['udid']); $this->mMember->loginInfoRecord($return['member_id'], $loginInfoRecord); $return = hg_mermber2members_compatible(array('member_name' => 'nick_name', 'access_token' => 'token'), $return, false); $this->addItem($return); $this->output(); } catch (Exception $e) { $this->errorOutput($e->getMessage(), $e->getCode()); } }
/** * 会员编辑 * $member_id * $member_name * $password * $old_password * $signature * $avatar file * $member_info json */ public function edit() { $this->input = hg_mermber2members_compatible(array('new_password' => 'password'), $this->input, false); $member_id = intval($this->user['user_id']); $app_id = $this->input['app_id']; //应用id if (!$member_id) { $this->errorOutput(NO_MEMBER_ID); } //检测该会员是否存在 $condition = " AND m.member_id = '" . $member_id . "' "; $field = 'm.member_id , m.member_name, m.password, m.salt, m.avatar, m.type,mb.nick_name'; $_member_info = $this->mMember->get_member_info($condition, $field, ' LEFT JOIN ' . DB_PREFIX . 'member_bind as mb ON mb.member_id = m.member_id'); $member_info = array(); $member_info = $_member_info[0]; if (empty($member_info)) { $this->errorOutput(NO_MEMBER); } $this->ReplaceCheck($member_info); //判定是否有值不更新 $member_name = trim($this->input['member_name']); if ($this->input['nick_name']) { $nick_name = trim($this->input['nick_name']); } if (!$nick_name && $this->settings['memberNameToNickName']) { $nick_name = $member_name; unset($member_name, $this->input['member_name']); } $password = trim($this->input['password']) ? trim($this->input['password']) : ''; $old_password = trim($this->input['old_password']); $signature = trim($this->input['signature']); $mobile = trim($this->input['mobile']); $email = trim($this->input['email']) ? trim($this->input['email']) : ''; $verifycode = trim($this->input['verifycode']); $device_token = $this->Members->check_device_token(trim($this->input['device_token'])); $udid = $this->Members->check_udid(trim($this->input['uuid'])); //检查唯一设备号 if ($device_token === 0) { $this->errorOutput(ERROR_DEVICE_TOKEN); } if ($udid === 0) { $this->errorOutput(ERROR_UDID); } //会员名、更新时间 $data = array('member_id' => $member_id, 'update_time' => TIMENOW); $check_bind = new check_Bind(); if ($mobile) { if (!hg_verify_mobile($mobile)) { $this->errorOutput(MOBILE_NUMBER_FORMAT_ERROR); } else { if ($check_bind->checkMobileBind($member_id) != $mobile) { $this->errorOutput(MOBILE_BIND_NOT_UPDATE); } } $data['mobile'] = $mobile; } if ($email) { if (!hg_check_email_format($email)) { $this->errorOutput(EMAIL_FORMAT_ERROR); } elseif ($check_bind->checkEmailBind($member_id) == $email) { $this->errorOutput(EMAIL_BIND_NOT_UPDATE); } $data['email'] = $email; } if ($member_name && !$this->mMember->isMemberNameUpdate($member_id)) { $this->errorOutput(NOT_EDIT_MEMBERNAME); } else { if ($member_name) { $member_name_exists = $this->mMember->member_name_exists($member_name, $member_id); if (!empty($member_name_exists)) { $this->errorOutput(MEMBER_NAME_EXISTS); } $data['member_name'] = $member_name; } } if ($this->settings['App_banword']) { include ROOT_PATH . 'lib/class/banword.class.php'; $banword = new banword(); $signature_banword = $banword->exists($signature); //个性签名检测 if ($signature_banword && is_array($signature_banword)) { $this->errorOutput(SIGNATURE_INVALID); } $nick_name_banword = $banword->exists($nick_name); //个性签名检测 if ($nick_name_banword && is_array($nick_name_banword)) { $this->errorOutput(NICKNAME_ILLEGAL); } } //如果是m2o注册类型屏蔽字检测 if (in_array($member_info['type'], array('m2o', 'uc')) && $this->settings['App_banword']) { $member_name_banword = $banword->exists($member_name); if ($member_name_banword && is_array($member_name_banword)) { //$this->errorOutput(var_export($banword,1)); $this->errorOutput(MEMBER_NAME_INVALID); } } $_old_password = ''; //用户原始密码 $is_no_old_password = 1; //是否需要旧密码修改资料,不涉及用户密码操作直接修改 //密码、随机串 if (isset($this->input['password']) && $password || isset($this->input['verifycode']) && $verifycode) { if (!$old_password && !$verifycode) { $this->errorOutput(OLD_PASSWORD_ERROR); } //根据原始密码修改密码 if ($old_password) { $is_no_old_password = 0; $_old_password = $old_password; //用作uc更改密码 $old_password = md5(md5($old_password) . $member_info['salt']); if ($old_password != $member_info['password']) { $this->errorOutput(OLD_PASSWORD_ERROR); } } //根据验证码修改密码 if ($verifycode) { if ($this->mSmsServer->get_verifycode_info($member_name, $verifycode)) { //验证成功之后删除 $this->mSmsServer->mobile_verifycode_delete($member_name, $verifycode); } else { $this->errorOutput(VERIFY_FAILED); } } } /** * 同步UC信息 */ if ($this->settings['ucenter']['open'] && in_array($member_info['type'], array('m2o', 'uc'))) { $_member_name = $this->user['user_name']; $is_password = $this->mMember->uc_user_edit($_member_name, $_old_password, $password, $email, $is_no_old_password); if ($is_password < 0) { if ($is_password == -1) { $this->errorOutput(OLD_PASSWORD_ERROR); } else { if ($is_password == -4) { $this->errorOutput(EMAIL_FORMAT_ERROR); } elseif ($is_password == -5) { $this->errorOutput(EMAIL_NO_REGISTER); } elseif ($is_password == -6) { $this->errorOutput(EMAIL_HAS_BINDED); } } } } if ($password) { $salt = hg_generate_salt(); $md5_password = md5(md5($password) . $salt); $data['password'] = $md5_password; $data['salt'] = $salt; } //个性签名 if (isset($this->input['signature'])) { $data['signature'] = $signature; } //头像 if ($_FILES['avatar']['tmp_name']) { $avatar = $_FILES['avatar']; } elseif ($this->input['avatar']) { $avatar = $this->input['avatar']; } //背景图 if ($_FILES['background']['tmp_name']) { $background = $_FILES['background']; } elseif ($this->input['background']) { $background = $this->input['background']; } $_avatar = array(); $_background = array(); //编辑头像 if (!empty($avatar) && is_array($avatar)) { if ($this->input['version'] == CLIENT_VERSION) { $avatar['name'] .= '.png'; } $_avatar = $this->mMember->add_material($avatar, $member_id); } elseif ($avatar && is_string($avatar) && is_url($avatar)) { $_avatar = $this->mMember->update_avatar($avatar, array(), $member_id, true); } //叮当更换头像时刷新im用户信息 if ($_avatar && $this->input['platformMark'] && $this->input['platformMark'] == 'dingdone' && $app_id) { $param = array('app_id' => $app_id, 'member_id' => $member_id, 'member_name' => $member_info['member_name']); $param['avatar_url'] = $_avatar['host'] . $_avatar['dir'] . $_avatar['filepath'] . $_avatar['filename']; $imInfo = $this->refreshImInfo($param); } //编辑背景图 if (!empty($background) && is_array($background)) { $_background = $this->mMember->add_material($background, $member_id); } if (!empty($_avatar)) { $data['avatar'] = serialize($_avatar); } $bind_info = array(); if ($nick_name) { $bind_info = array('nick_name' => $nick_name); } if ($_background) { $bind_info['background'] = serialize($_background); } $copywriting_credit = $this->editCreditRules($member_id, $data, $bind_info); //判断积分规则 //会员数据入库 $ret = $this->mMember->update($data); if ($bind_info) { $this->mMember->bind_update($bind_info, 'WHERE member_id = \'' . $member_id . '\''); } if (!$ret['member_id']) { $this->errorOutput(EDIT_FAILED); } //编辑扩展信息 if ($this->input['platformMark'] && $this->input['platformMark'] == 'dingdone' && $app_id) { //为叮当注册根据app配置不同的扩展信息 $extension = $this->mMemberInfo->extension_editByApp($member_id, $this->input['member_info'], $app_id, $_FILES); } else { $extension = $this->mMemberInfo->extension_edit($member_id, $this->input['member_info'], $_FILES); } //会员痕迹 $member_trace_data = array('member_id' => $member_id, 'member_name' => $member_name ? $member_name : $member_info['member_name'], 'content_id' => $member_id, 'title' => $member_name ? $member_name : $member_info['member_name'], 'type' => 'editmember', 'op_type' => '修改会员资料', 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'create_time' => TIMENOW, 'ip' => hg_getip(), 'device_token' => $device_token, 'udid' => $udid); $this->mMember->member_trace_create($member_trace_data); $return = array('member_id' => $member_id, 'member_name' => !$member_name ? $member_info['member_name'] : $member_name, 'nick_name' => !$nick_name ? $member_info['nick_name'] : $nick_name, 'type' => $member_info['type'], 'avatar' => !$_avatar ? $member_info['avatar'] : $_avatar, 'access_token' => $this->user['token'], 'update_avatar' => $avatar ? 1 : 0, 'copywriting_credit' => $copywriting_credit, 'background' => $_background ? $_background : array(), 'email' => $email ? $email : ''); if (isset($this->input['signature'])) { $return['signature'] = $signature; } //获取扩展信息 if ($app_id) { $extension = $this->getExtensionInfo($member_id, $app_id); $return['extension'] = $extension; } //获取会员基本信息返回 $condition = ''; $condition = " AND m.member_id = '" . $member_id . "' AND mb.is_primary=1"; $field = 'm.member_id , m.member_name, m.signature, m.email,m.mobile, mb.background, m.salt, m.avatar, m.type,mb.nick_name'; $memberBaseInfo = $this->mMember->get_member_info($condition, $field, ' LEFT JOIN ' . DB_PREFIX . 'member_bind as mb ON mb.member_id = m.member_id'); if (!empty($memberBaseInfo[0])) { foreach ($memberBaseInfo[0] as $k => $v) { $return[$k] = $v; } } if ($this->input['version'] == CLIENT_VERSION) { //头像 if ($this->input['m_avatar']) { $return = $return['avatar']; } //昵称 if ($this->input['m_name']) { if ($this->input['appid'] == 7 && $this->input['appkey'] == 'upnKAycZKVw4D7QSXH7D8uFrFOpRQyXb') { $return = 'success'; } else { $return = array('nick_name' => $return['member_name'], 'update_time' => '', 'member_name' => $return['member_name'], 'member_id' => $return['member_id']); } } //密码 if ($this->input['m_password']) { $return = array('member_id' => $return['member_id']); } //邮箱 if ($this->input['m_mail'] || $this->input['m_mobile']) { $return = "success"; } } $this->addItem($return); $this->output(); }
/** * 会员登录 * $member_name * $password * $type * $type_name * $appid * $appkey * * 返回 * member_id * member_name * type * avatar * access_token * * 绑定表 * member_id 会员id platform_id 第三方平台会员id char nick_name 昵称 type 会员类型 type_name 会员类型名称 avatar_url 头像地址 bind_time 绑定时间 bind_ip 绑定ip */ public function login() { try { $member_name = $this->checkUserName(trimall($this->input['member_name'])); $password = trim($this->input['password']); $ip = hg_getip(); $type = $this->input['type']; $this->checkLoginTypeSwitch(); $this->checkLoginTypeError($member_name, $type); $this->checkLoginPassword($password, $type); $this->check_verifycode($type); //验证码 $_type = ''; //防止本地M2O同步至UC后,再次验证本地密码BUG。 $platform_id = trim($this->input['platform_id']); $identifierUserSystem = new identifierUserSystem(); $identifier = $identifierUserSystem->setIdentifier((int) $this->input['identifier'])->checkIdentifier(); //多用户系统 $appid = intval($this->input['appid']); $appkey = trim($this->input['appkey']); $device_token = $this->Members->check_device_token(trim($this->input['device_token'])); $udid = $this->Members->check_udid(trim($this->input['uuid'])); //唯一设备号 if ($device_token === 0) { $this->errorOutput(ERROR_DEVICE_TOKEN); } if ($udid === 0) { $this->errorOutput(ERROR_UDID); } //验证设备号和ip是否在黑名单 if ($udid) { $device_res = $this->Blacklist->detailDeviceBlacklist(array('device_token' => $udid, 'identifier' => $identifier)); if ($device_res[0]['deadline'] == -1 && $device_res[0]['type'] == 2) { $this->errorOutput(DEVICE_BLACKLIST_FOREVER); } elseif ($device_res[0]['deadline'] == -1) { $this->errorOutput(DEVICE_BLACKLIST); } } if ($ip) { $ip_res = $this->Blacklist->detailIpBlacklist(array('ip' => ip2long($ip), 'identifier' => $identifier)); if ($ip_res[0]['deadline'] == -1 && $ip_res[0]['type'] == 2) { $this->errorOutput(IP_BLACKLIST_FOREVER); } elseif ($ip_res[0]['deadline'] == -1) { $this->errorOutput(IP_BLACKLIST); } } //登陆类型 shouji、sina、txweibo、qq、renren、douban if (!$type) { $this->errorOutput(NO_EXTERNAL_TYPE); } if ($type == 'uc' && $identifier) { $this->input['type'] = ''; $this->checkUserName($member_name, 1); $this->input['type'] && ($type = $this->input['type']); } if ($type == 'm2o' && $this->settings['ucenter']['open'] && !$identifier) { $check_login = $this->oAuthUc(true, true); //修复手机端传m2o类型,但是帐号属于UC类型,登陆失败问题 if ($check_login > 0) { $type = 'uc'; } } if ($type == 'uc' && $this->settings['ucenter']['open'] && !$identifier) { $uc_user = $this->oAuthUc(true); if ($uc_user['user_id'] == -1) { $type = 'm2o'; } } elseif ($type == 'uc' && !$this->settings['ucenter']['open'] && !$identifier) { $this->errorOutput(UC_LOGIN_ERROR); } $check_Bind = new check_Bind(); //所有类型的邮箱登陆 if ($member_name && $type == 'email') { $platform_id = $platform_id ? $platform_id : $member_name; if (!$check_Bind->bind_to_memberid($member_name, $type, true, $identifier)) { $this->errorOutput(LOGIN_NOMEMBER_ERROR); } } else { if ($type == 'shouji') { //会员名 if (!$member_name) { $this->errorOutput(NO_MEMBER_NAME); } $platform_id = $platform_id ? $platform_id : $member_name; if (!$check_Bind->bind_to_memberid($member_name, $type, true, $identifier)) { $this->errorOutput(LOGIN_NOMEMBER_ERROR); } } else { if ($type == 'm2o') { $is_mobile_login = false; $where = ' AND member_name="' . $member_name . '" AND type="m2o" AND identifier = \'' . $identifier . '\''; $sql = 'SELECT member_id FROM ' . DB_PREFIX . 'member WHERE 1'; $memberinfo = $this->db->query_first($sql . $where); if (!$memberinfo) { if (hg_verify_mobile($member_name)) { $where = ' AND member_name=\'' . $member_name . '\' AND type=\'shouji\' AND identifier = \'' . $identifier . '\''; $memberinfo = $this->db->query_first($sql . $where); if ($memberinfo) { $type = 'shouji'; $platform_id = $check_Bind->check_uc($memberinfo['member_id'], $type); //修复同步UC后,登陆密码错误的bug $platform_id = $platform_id ? $platform_id : $member_name; } if (empty($memberinfo)) { $type = 'shouji'; $member_id = $check_Bind->bind_to_memberid($member_name, $type, true, $identifier); if ($member_id) { $memberinfo = array('member_id' => $member_id); $platform_id = $member_name; } } } $memberinfo ? $memberinfo : $this->errorOutput(LOGIN_NOMEMBER_ERROR); } if ($type != 'shouji') { $bindinfo = $this->db->query_first('SELECT inuc FROM ' . DB_PREFIX . 'member_bind WHERE member_id=' . $memberinfo['member_id'] . ' AND type="m2o"'); $platform_id = $bindinfo['inuc'] ? $bindinfo['inuc'] : $memberinfo['member_id']; } } else { //新浪微博、腾讯微博、QQ、人人网、豆瓣 uc等 $nick_name = trimall($this->input['nick_name']); $type_name = trim($this->input['type_name']); $avatar_url = trim($this->input['avatar_url']); if ($type == 'uc' && $uc_user) { //$platform_id = $uc_user['user_id']; //手机 m2o注册至uc之后登陆类型使用“uc”导致的bug $sql = 'SELECT * FROM ' . DB_PREFIX . 'member_bind WHERE type=\'m2o\' AND inuc=' . $uc_user['user_id']; $bind_uc = $this->db->query_first($sql); if ($bind_uc) { $platform_id = $bind_uc['platform_id']; $nick_name = $bind_uc['nick_name']; $type_name = $bind_uc['type_name']; $avatar_url = $bind_uc['avatar_url']; $_type = $type; $type = $bind_uc['type']; } else { $platform_id = $uc_user['user_id']; $nick_name = $uc_user['user_name']; $type_name = 'UC会员'; $avatar_url = $uc_user['avatar']; $email = $uc_user['email']; } } if (!$platform_id) { $this->errorOutput(NO_MEMBER_ID); } if (!$nick_name) { $this->errorOutput(NO_NICKNAME); } $member_name = $nick_name; $condition = " AND mb.platform_id = '" . $platform_id . "' AND mb.type = '" . $type . "' AND mb.identifier = '" . $identifier . '\''; $bind = $this->mMember->get_bind_info($condition); $bind = $bind[0]; if (empty($type_name)) { $platformInfo = $this->Members->get_platform_name($type); if (empty($platformInfo)) { $this->errorOutput(LOGIN_MEMBER_TYPE_ERROR); } else { if (!$platformInfo['status']) { $this->errorOutput(LOGIN_MEMBER_TYPE_CLOSE); } } $type_name = $platformInfo['name']; } $avatar_array = array(); $avatar_array = $this->mMember->update_avatar($avatar_url, $bind); //会员表 $data = array('member_name' => $nick_name, 'email' => $email, 'type' => $type, 'type_name' => $type_name, 'update_time' => TIMENOW, 'avatar' => daddslashes(serialize($avatar_array)), 'guid' => guid()); //绑定表 $bind_data = array('platform_id' => $platform_id, 'type' => $type, 'avatar_url' => $avatar_url, 'reg_device_token' => $device_token, 'reg_udid' => $udid); if (empty($bind)) { if ($type == 'uc') { $isBindUc = 0; if ($memberId = $this->mMember->verifyPassword($member_name, $password, 'm2o')) { $isBindUc = $this->mMember->bind_uc($memberId, $uc_user['user_id']); } if (!$isBindUc && $password) { //随机串 $salt = hg_generate_salt(); $data['salt'] = $salt; //密码md5 $data['password'] = md5(md5($password) . $salt); } } if ($type != 'uc' || !$isBindUc) { //新增会员 $groupInfo = $this->Members->checkgroup_credits(0); $gradeInfo = $this->Members->checkgrade_credits(0); $data['gid'] = $groupInfo['gid']; $data['gradeid'] = $gradeInfo['gradeid']; $data['status'] = $this->settings['member_status']; $data['identifier'] = $identifier; $data['appid'] = intval($this->user['appid']); $data['appname'] = trim($this->user['display_name']); $data['create_time'] = TIMENOW; $data['ip'] = $ip; $data['reg_device_token'] = $device_token; $data['reg_udid'] = $udid; //会员数据入库 $ret = $this->mMember->create($data); if (!$ret['member_id']) { $this->errorOutput(MEMBER_DATA_ADD_FAILED); } $member_id = $ret['member_id']; //绑定表 $bind_data['nick_name'] = $nick_name; $bind_data['member_id'] = $member_id; $bind_data['type_name'] = $type_name; $bind_data['bind_time'] = TIMENOW; $bind_data['bind_ip'] = $ip; $bind_data['is_primary'] = 1; $bind_data['identifier'] = $identifier; if ($bind_data['type'] == 'uc') { $bind_data['inuc'] = $bind_data['platform_id']; } $ret_bind = $this->mMember->bind_create($bind_data); if (empty($ret_bind)) { $this->errorOutput(BIND_DATA_ADD_FAILED); } $this->registerCreditRules($member_id, $type); //新注册会员积分规则 } else { if ($type == 'uc' && $isBindUc) { $type = 'm2o'; } } } else { //更新会员 $member_id = $bind['member_id']; //验证会员是否存在 $condition = " AND m.member_id = " . $member_id; $ret_member = $this->mMember->get_member_info($condition); $ret_member = $ret_member[0]; if (empty($ret_member)) { $this->errorOutput(LOGIN_NOMEMBER_ERROR); } $update_bind_data = array('member_id' => $member_id, 'platform_id' => $platform_id, 'type' => $type, 'avatar_url' => $avatar_url); $ret_bind = $this->mMember->bind_update($update_bind_data); if (empty($ret_bind)) { $this->errorOutput(BIND_DATA_UPDATE_FAILED); } } } } } //到auth接口取access_token $encryptPassword = urlencode(passport_encrypt($password, CUSTOM_APPKEY)); $callback = 'http://' . $this->settings['App_members']['host'] . '/' . $this->settings['App_members']['dir'] . 'login.php?'; $func = 'a=verify_member&appid=' . $appid . '&appkey=' . $appkey; $callback .= urlencode($func); $extend = 'platform_id=' . $platform_id . '&password='******'&encrypt=1&type=' . $type . '&_type=' . $_type . '&identifier=' . $identifier; $auth_data = array('user_name' => $member_name, 'appid' => $appid, 'appkey' => $appkey, 'ip' => $ip, 'verify_user_cb' => $callback, 'extend' => urlencode($extend)); $auth = $this->mMember->get_access_token($auth_data); if (!$auth['token']) { $this->errorOutput(MEMBERS_LOGIN_ERROR); } //黑名单用户判断 $blacklist = $this->Members->blacklist($auth['user_id']); if ($blacklist[$auth['user_id']]['isblack']) { $this->errorOutput(MEMBER_BLACKLIST); } //判断结束 //权限判断 //判断结束 //编辑扩展信息 $this->mMemberInfo->extension_edit($auth['user_id'], $this->input['member_info'], $_FILES); //获取扩展信息 $extension = $this->getExtensionInfo($auth['user_id'], $identifier); //会员痕迹 $member_trace_data = array('member_id' => $auth['user_id'], 'member_name' => $member_name, 'content_id' => $auth['user_id'], 'title' => $member_name, 'type' => 'login', 'op_type' => '登陆', 'appid' => $this->user['appid'], 'appname' => $this->user['display_name'], 'create_time' => TIMENOW, 'ip' => hg_getip(), 'device_token' => $device_token, 'udid' => $udid); $memberTrace = $this->mMember->getMemberTrace(array('member_id' => $auth['user_id'], 'type' => 'login'), 'create_time'); $this->mMember->member_trace_create($member_trace_data); $return = array('member_id' => $auth['user_id'], 'platform_id' => $auth['platform_id'], 'inuc' => $auth['inuc'] ? $auth['inuc'] : 0, 'member_name' => $auth['user_name'], 'nick_name' => $auth['nick_name'], 'type' => $auth['type'], 'type_name' => $auth['type_name'], 'avatar' => $auth['avatar'] ? $auth['avatar'] : '', 'access_token' => $auth['token'], 'guid' => $auth['guid'], 'gid' => $auth['gid'], 'gradeid' => $auth['gradeid'], 'copywriting_credit' => $auth['copywriting_credit'], 'copywriting' => $auth['copywriting'], 'signature' => $auth['signature'], 'mobile' => $auth['mobile'], 'email' => $auth['email'], 'extension' => $extension ? $extension : array(), 'isVerify' => $auth['isVerify'], 'isComplete' => $auth['isComplete'], 'identifier' => $auth['identifier'], 'last_login_device' => $auth['last_login_device'], 'last_login_time' => date('Y-m-d H:i:s', $memberTrace['create_time'])); //记录登陆信息 $loginInfoRecord = array('last_login_device' => $member_trace_data['device_token'], 'final_login_time' => $member_trace_data['create_time'], 'last_login_time' => $memberTrace['create_time'], 'last_login_udid' => $member_trace_data['udid']); $this->mMember->loginInfoRecord($return['member_id'], $loginInfoRecord); $return = hg_mermber2members_compatible(array('member_name' => 'nick_name', 'access_token' => 'token'), $return, false); $this->addItem($return); $this->output(); } catch (Exception $e) { $this->errorOutput($e->getMessage(), $e->getCode()); } }