Example #1
0
 /**
  * @param $mobile
  * @param $password
  * @return Wk_AdminUser
  * @throws Wk_Exception
  */
 public function submitAdminUserLogin($mobile, $password)
 {
     $password = md5(md5(self::ADMIN_PASSWORD_SALT . $password) . self::ADMIN_PASSWORD_SALT);
     $user = TAR_AdminUser::findOne("where mobile = ? and password = ? and is_deleted = 0", "ss", $mobile, $password);
     if (!isset($user) && empty($user)) {
         throw new Wk_Exception("管理员账号不存在", -1);
     }
     $user->lastLoginTime = date("Y-m-d H:i:s");
     $user->lastLoginIp = WkUtils::getClientIp();
     $user->save();
     $retUser = new Wk_AdminUser();
     $retUser->id = $user->id;
     $retUser->mobile = $user->mobile;
     $retUser->nickname = "nick" . $user->mobile;
     return $retUser;
 }
Example #2
0
 /**
  * 微信登录
  * @param $openId
  * @return Wk_User
  * @throws Wk_Exception
  */
 public function submitLoginWithWechat($openId)
 {
     $firstLogin = false;
     $wechatUserInfo = TAR_WechatUser::findOne("where open_id = ?", "s", $openId);
     if (!isset($wechatUserInfo) || empty($wechatUserInfo)) {
         throw new Wk_Exception("", TErrorConstants::E_SNS_LOGIN);
     }
     $user = TAR_User::findOne("where open_id = ?", "s", $openId);
     if (!isset($user) || empty($user)) {
         $firstLogin = true;
         $user = new TAR_User();
     }
     $user->headImgUrl = $wechatUserInfo->headImgUrl;
     $user->nickname = $wechatUserInfo->nickname;
     $user->createTime = date("Y-m-d H:i:s");
     $user->mobile = "";
     //        微信渠道注册
     $user->source = 1;
     $user->city = $wechatUserInfo->city;
     $user->province = $wechatUserInfo->province;
     $user->lastLoginIp = WkUtils::getClientIp();
     $user->lastLoginTime = date("Y-m-d H:i:s");
     $user->save();
     $tokenstring = md5(md5($user->id . $user->openId . date("Y-m")) . self::PASSWORD_SALT);
     $token = TAR_Usertoken::findOne("where token = ? and is_deleted = 0", "s", $tokenstring);
     if (!isset($token) || empty($token)) {
         $token = new TAR_Usertoken();
     }
     $token->token = $tokenstring;
     $token->userId = $user->id;
     $token->expire = "0000-00-00 00:00:00";
     $token->logintype = "wechat";
     $token->save();
     $retUser = new Wk_User();
     $retUser->mobile = $user->mobile;
     $retUser->city = $user->city;
     $retUser->province = $user->province;
     $retUser->avatarUrl = $user->headImgUrl;
     $retUser->nickname = $user->nickname;
     $retUser->userid = $user->id;
     $retUser->token = $token->token;
     return $retUser;
 }