[self::PLATFORM_WX, self::PLATFORM_MP, self::PLATFORM_APP, self::PLATFORM_PHONE]], ['_platform', 'required'], [['code', 'user_info', 'encrypted_data', 'iv', 'signature'], 'required', 'on' => self::PLATFORM_WX], [['user_info'], 'required', 'on' => self::PLATFORM_APP], [['phone'], 'required', 'on' => self::PLATFORM_PHONE], [['phone'], 'match', 'pattern' => '/^1[3456789]\d{9}$/', 'message' => '手机号错误'], [['verify_code', 'parent_id', 'share_user_id', 'isLogin', 'login_type'], 'integer'], [['code', 'user_info', 'encrypted_data', 'iv', 'signature', 'phone', 'password'], 'string'], [['code', 'user_info', 'encrypted_data', 'iv', 'signature', 'phone'], 'trim'], ]; } public function attributeLabels() { return [ 'login_type' => 'login_type', '_platform' => '_platform', 'store_id' => 'store_id', 'code' => 'code', 'user_info' => 'user_info', 'encrypted_data' => 'encrypted_data', 'iv' => 'iv', 'signature' => 'signature', 'share_user_id' => 'share_user_id', ]; } public function scenarios() { $scenarios = parent::scenarios(); return $scenarios; } /** * 登录统一入口 * @return array * @throws \yii\base\Exception */ public function login() { if ($this->_platform == self::PLATFORM_WX) { // 微信小程序登录 return $this->loginWX(); } else if ($this->_platform == self::PLATFORM_APP) { // app端微信登录 return $this->loginAppWechat(); } else if ($this->_platform == self::PLATFORM_PHONE) { // 手机号登录,没有找到手机号自动注册 return $this->phoneLogin(); } else { return [ 'code' => 1, 'msg' => '登录失败,请检查参数是否正确' ]; } } /** * 微信登录方法 * @return array */ private function loginWX() { if ($this->validate()) { try { //获取session $session = self::getWechat()->auth->session($this->code); if (!$session || empty($session['openid'])) { throw new \Exception('获取openid失败.'); } // 验证 $decryptedData = self::getWechat()->encryptor->decryptData($session['session_key'], $this->iv, $this->encrypted_data); $user_info = json_decode($this->user_info, true); $user_info['nickName'] = preg_replace('/[\xf0-\xf7].{3}/', '', $user_info['nickName']); $data = [ 'openId' => $session['openid'], 'nickName' => isset($user_info['nickName']) ? $user_info['nickName'] : $this->getNickName(), 'gender' => $user_info['gender'], 'city' => $user_info['city'], 'province' => $user_info['province'], 'country' => $user_info['country'], 'avatarUrl' => $user_info['avatarUrl'] ?: \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/statics/images/avatar.png', 'unionId' => isset($session['unionid']) ? $session['unionid'] : '', ]; $isNew = 0; $user = User::find()->where(['store_id' => $this->store_id, 'platform' => 0])->andWhere(['binding' => $this->phone])->orderBy('id desc')->one(); if (!$user) { $isNew = 1; $user = new User(); $user->type = User::USER_TYPE_NORMAL; $user->binding = isset($decryptedData['phoneNumber']) ? $decryptedData['phoneNumber'] : ''; $user->username = $data['openId']; $user->password = \Yii::$app->security->generatePasswordHash(\Yii::$app->security->generateRandomString(), 5); $user->auth_key = \Yii::$app->security->generateRandomString(); $user->access_token = \Yii::$app->security->generateRandomString(); $user->is_delete = User::USER_NOT_DELETE; $user->wechat_open_id = $data['openId']; $user->wechat_union_id = $data['unionId']; $user->store_id = $this->store_id; $user->platform = User::USER_FROM_WECHAT; // 微信 } $user->binding = $this->phone; $user->nickname = $data['nickName']; $user->avatar_url = $data['avatarUrl']; if (empty($user->wechat_open_id) || (!empty($data['openId']) && $user->wechat_open_id !== $data['openId'])) { $user->wechat_open_id = $data['openId']; } if (empty($user->wechat_union_id) || (!empty($data['unionId']) && $user->wechat_union_id !== $data['unionId'])) { $user->wechat_union_id = $data['unionId']; } if (!$user->save()) { return [ 'code' => 1, 'msg' => '登陆失败', 'data' => $user->getErrorSummary(false)[0] ]; } // 创建平台会员saas_user $saas_user = SaasUser::find()->where(['mobile' => $user->binding, 'is_delete' => SaasUser::DELETE_STATUS_FALSE])->one(); if (!$saas_user) { $saas_user = new SaasUser(); $saas_user->mobile = $user->binding; $saas_user->store_id = $this->store_id; $saas_user->save(); } // 是否开启强制绑定手机号 $is_open_bind = Option::get(OptionSetting::STORE_LOGIN_FORCIBLY_BIND_MOBILE, $this->store_id, 'store')['value']; $share = $share_user = null; if ($user->parent_id > 0) { $share = Share::findOne(['user_id' => $user->parent_id]); $share_user = User::findOne(['id' => $share->user_id]); } if ($this->share_user_id > 0) { // 绑定上下级 $bindForm = new BindForm(); $bindForm->store_id = $this->store_id; $bindForm->user_id = $user->id; $bindForm->parent_id = $this->share_user_id; $bindForm->condition = 0; $bindForm->isNew = $isNew; $bindForm->save(); } $data = [ 'access_token' => $user->access_token, 'nickname' => $user->nickname, 'avatar_url' => $user->avatar_url, 'is_distributor' => $user->is_distributor ? $user->is_distributor : 0, 'errCode' => 0, 'parent' => $share ? ($share->name ? $share->name : $share_user->nickname) : '总店', 'id' => $user->id, 'is_clerk' => $user->is_clerk === null ? 0 : $user->is_clerk, 'integral' => $user->integral === null ? 0 : $user->integral, 'money' => $user->money === null ? 0 : $user->money, 'binding' => $user->binding, 'level' => $user->level, 'blacklist' => $user->blacklist, 'is_open_bind' => $is_open_bind ? $is_open_bind : 0 ]; return [ 'code' => 0, 'data' => $data, 'msg' => '登陆成功' ]; } catch (\Exception $e) { return [ 'code' => 1, 'msg' => '登录失败', 'data' => $e->getMessage() . 'line:' . $e->getLine() . 'file:' . $e->getFile() ]; } } else { // 验证失败:$errors 是一个包含错误信息的数组 return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; } } /** * app 微信登录 * @return array * @throws \yii\base\Exception */ public function loginAppWechat() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; } $user_info = Json::decode($this->user_info); $user = null; if (isset($user_info['unionId']) && $user_info['unionId'] != '') { $user = User::findOne(['wechat_union_id' => $user_info['unionId'], 'store_id' => $this->store_id]); } if (!$user) { $user = User::findOne(['wechat_open_id' => $user_info['openId'], 'store_id' => $this->store_id]); } // 是否开启强制绑定手机号 $is_open_bind = Option::get(OptionSetting::STORE_LOGIN_FORCIBLY_BIND_MOBILE, $this->store_id, 'store')['value']; if(!$user){ $user = new User(); $user->type = 1; $user->username = $user_info['openId']; $user->password = \Yii::$app->security->generatePasswordHash(\Yii::$app->security->generateRandomString(), 5); $user->auth_key = \Yii::$app->security->generateRandomString(); $user->access_token = \Yii::$app->security->generateRandomString(); $user->created_at = time(); $user->is_delete = 0; $user->wechat_open_id = $user_info['openId']; $user->wechat_union_id = isset($user_info['unionId']) ? $user_info['unionId'] : ''; $user->nickname = preg_replace('/[\xf0-\xf7].{3}/', '', $user_info['nickName']); $user->avatar_url = $user_info['avatarUrl'] ? $user_info['avatarUrl'] : \Yii::$app->request->hostInfo . '/web/v1/statics/images/avatar.png'; $user->store_id = 1; $user->platform = 3; // APP $user->level = -1; if(isset($user_info['appCid']) && !empty($user_info['appCid'])){ $user->appcid = $user_info['appCid']; } if($user->save()){ // \Yii::$app->user->login($user); $parent = User::findOne($user->parent_id); $share = Share::findOne(['user_id' => $user->parent_id]); $data = [ 'to_bind' => 1, 'nickname' => $user->nickname, 'binding' => $user->binding ? $user->binding : '', 'id' => $user->id, 'avatar_url' => $user->avatar_url, 'is_distributor' => $user->is_distributor ? $user->is_distributor : 0, 'integral' => $user->integral ? $user->integral : 0, 'money' => $user->money ? $user->money : 0, 'blacklist' => $user->blacklist ? $user->blacklist : 0, 'access_token' => $user->access_token, 'is_clerk' => $user->is_clerk === null ? 0 : $user->is_clerk, 'parent' => $share ? ($share->name ? $share->name : $parent->nickname) : "总店", 'level' => $user->level, 'is_open_bind' => $is_open_bind ? $is_open_bind : 0 ]; } else { return [ 'code' => 1, 'msg' => '登录失败', 'data' => $user->errors[0] ]; } } else { if(isset($user_info['appCid']) && !empty($user_info['appCid']) && $user->appcid != $user_info['appCid']){ $user->appcid = $user_info['appCid']; } if (empty($user->wechat_union_id)) { $user->wechat_union_id = isset($user_info['unionId']) ? $user_info['unionId'] : ''; } $user->nickname = preg_replace('/[\xf0-\xf7].{3}/', '', $user_info['nickName']); $user->avatar_url = $user_info['avatarUrl']; $user->save(); // \Yii::$app->user->login($user); $parent = User::findOne($user->parent_id); $share = Share::findOne(['user_id' => $user->parent_id]); $data = [ 'to_bind' => 0, 'nickname' => $user->nickname, 'binding' => $user->binding === null ? '' : $user->binding, 'id' => $user->id, 'avatar_url' => $user->avatar_url, 'is_distributor' => $user->is_distributor, 'integral' => $user->integral, 'money' => $user->money, 'blacklist' => $user->blacklist, 'access_token' => $user->access_token, 'is_clerk' => $user->is_clerk === null ? 0 : $user->is_clerk, 'parent' => $share ? ($share->name ? $share->name : $parent->nickname) : "总店", 'level' => $user->level, 'is_open_bind' => $is_open_bind ? $is_open_bind : 0 ]; } return [ 'code' => 0, 'msg' => '登录成功', 'data' => $data ]; } /** * 手机号登录 * @return array * @throws \yii\base\Exception */ public function loginAppPhone() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; } // 验证码验证 $result = $this->verifySmsCode(self::CACHE_KEY_SMS_LOGIN); if ($result['code'] == 1) { return $result; } $parent_name = '总店'; /** * @var User $user */ $user = User::find()->where(['store_id' => $this->store_id, 'type' => 1, 'is_delete' => 0, 'blacklist' => 0, 'binding' => $this->phone])->one(); if (!$user) { $password = '0'; $user = new User(); $user->type = 1; $user->username = \Yii::$app->security->generateRandomString(); $user->password = $password; $user->auth_key = \Yii::$app->security->generateRandomString(); $user->access_token = \Yii::$app->security->generateRandomString(); $user->created_at = time(); $user->is_delete = 0; $user->binding = $this->phone; $user->nickname = $this->getDefaultNickname($this->phone); $user->avatar_url = $this->getDefaultAvatar(); $user->store_id = $this->store_id; $user->platform = User::USER_FROM_PHONE; if ($this->appCid) { $user->appcid = $this->appCid; } if ($this->parent_id > 0) { $parent_id = $this->parent_id; $setting = Option::get('share_basic_setting', get_store_id()); $setting = $setting ? Json::decode($setting['value']) : []; if (!$setting || $setting['level']['value'] == 0) { $parent_id = 0; } if ($parent_id > 0) { $exists = Share::find()->andWhere(['user_id' => $this->parent_id, 'store_id' => $this->store_id, 'is_delete' => 0, 'status' => 1]); if ($exists->exists()) { $parent_name = $exists->one()->name; $user->parent_id = $parent_id; $user->old_parent_id = $parent_id; } else { $parent_name = User::findOne(['id' => $this->parent_id])->nickname; } } } if ($user->save()) { $data = [ 'nickname' => $user->nickname, 'binding' => $user->binding, 'id' => $user->id, 'avatar_url' => $user->avatar_url, 'is_distributor' => $user->is_distributor ? $user->is_distributor : 0, 'integral' => $user->integral ? $user->integral : 0, 'money' => $user->money ? $user->money : 0, 'blacklist' => $user->blacklist ? $user->blacklist : 0, 'access_token' => $user->access_token, 'is_clerk' => $user->is_clerk === null ? 0 : $user->is_clerk, 'parent' => $parent_name, 'level' => -1 ]; return [ 'code' => 0, 'msg' => '注册成功', 'data' => $data, ]; } else { foreach ($user->errors as $error) { return [ 'code' => 1, 'msg' => $error ]; } } } if ($user->parent_id > 0) { $share = Share::findOne(['user_id' => $user->parent_id]); $parent_user = User::findOne($user->parent_id); $parent_name = $share ? ($share->name ? $share->name : $parent_user->nickname) : "总店"; } $data = [ 'nickname' => $user->nickname, 'binding' => $user->binding, 'id' => $user->id, 'avatar_url' => $user->avatar_url, 'is_distributor' => $user->is_distributor, 'integral' => $user->integral, 'money' => $user->money, 'blacklist' => $user->blacklist, 'access_token' => $user->access_token, 'is_clerk' => $user->is_clerk === null ? 0 : $user->is_clerk, 'parent' => $parent_name, 'level' => $user->level ]; return [ 'code' => 0, 'msg' => '登录成功', 'data' => $data, ]; } public function phoneLogin() { if (!$this->validate()) { return [ 'code' => 1, 'msg' => $this->getErrorSummary(false)[0] ]; } if ($this->login_type == 1) { // $is_password_login = intval(Option::get(OptionSetting::IS_PASSWORD_LOGIN, $this->store_id, '', 0)['value']); // if ($is_password_login) { // return [ // 'code' => 1, // 'msg' => '商城开启密码登录方式,请使用密码登录' // ]; // } // 验证码验证 $result = $this->verifySmsCode(self::CACHE_KEY_SMS_LOGIN); if ($result['code'] == 1) { return $result; } } else { // $is_password_login = intval(Option::get(OptionSetting::IS_PASSWORD_LOGIN, $this->store_id, '', 0)['value']); // if (!$is_password_login) { // return [ // 'code' => 1, // 'msg' => '商城未开启密码登录方式,请使用验证码登录' // ]; // } // 密码验证 $user = User::find()->where(['store_id' => $this->store_id, 'type' => 1, 'is_delete' => 0, 'binding' => $this->phone])->one(); if (!$user) { return [ 'code' => 1, 'msg' => '用户不存在' ]; } if (false === \Yii::$app->security->validatePassword($this->password, $user->password)) { return [ 'code' => 1, 'msg' => '密码错误' ]; } } //debug_log('公众号登录01', 'off.log'); $plat_openid = ''; $openid = ''; //debug_log('公众号登录02_code=' . $this->code, 'off.log'); if ($this->code) { try { //debug_log('公众号登录03', 'off.log'); // if (is_wechat_platform()) { $wechat = self::getWechat(); if (is_h5()) { $app = WechatMini::getWechatConfig($this->store_id, 0, WechatMini::TYPE_OFFICIAL); //debug_log('公众号登录04', 'off.log'); $session = $app->oauth->userFromCode($this->code)->getTokenResponse(); $plat_openid = $session['openid']; //debug_log('公众号登录05'. json_encode($session, JSON_UNESCAPED_UNICODE), 'off.log'); } else { $app = WechatMini::getWechatConfig($this->store_id); if (empty($app)) { return [ 'code' => 1, 'msg' => '小程序参数获取失败!', ]; } $session = $app->auth->session($this->code); if (empty($session)) { return [ 'code' => 1, 'msg' => '小程序参数异常!', ]; } if (!$session || empty($session['openid'])) { throw new \Exception('获取openid失败.'); } $openid = $session['openid']; } // } elseif (is_alipay_platform()) { // // } } catch (\Exception $e) { return [ 'code' => 1, 'msg' => $e->getMessage(), ]; debug_log('公众号登录06' . $e->getMessage(), 'off.log'); } //debug_log('公众号登录07', 'off.log'); } //debug_log('公众号登录08', 'off.log'); // 创建平台会员saas_user $saas_user = SaasUser::find()->where(['mobile' => $this->phone, 'is_delete' => SaasUser::DELETE_STATUS_FALSE])->one(); if (!$saas_user) { $saas_user = new SaasUser(); $saas_user->access_token = \Yii::$app->security->generateRandomString(); $saas_user->name = substr_replace($this->phone, '******', 3, 6); $saas_user->mobile = $this->phone; $saas_user->platform_open_id = ''; $saas_user->avatar = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/avatar.png'; $saas_user->store_id = $this->store_id; $saas_user->save(); } else { if (empty($saas_user->name)) { $saas_user->name = substr_replace($this->phone, '****', 3, 4); } if (empty($saas_user->avatar)) { $saas_user->avatar = \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/avatar.png'; } if (empty($saas_user->access_token)) { $saas_user->access_token = \Yii::$app->security->generateRandomString(); } // $saas_user->platform_open_id = $this->phone; $saas_user->save(); } // 平台登录 todo: 后续补充其他数据 if ($this->store_id <= 0) { $storeCloud = StoreCloud::findOne(['is_delete' => 0, 'is_enable' => 1, 'saas_user_id' => $saas_user->id]); return [ 'code' => 0, 'msg' => '登录成功', 'data' => [ 'access_token' => $saas_user->access_token, 'nickname' => $saas_user->name, 'avatar_url' => $saas_user->avatar, 'id' => $saas_user->id, 'money' => $saas_user->share_profit, 'integral' => $saas_user->integral, 'mobile' => $saas_user->mobile, 'is_can_distribution' => $storeCloud && $storeCloud->store_id > 0 ? 1 : 0, // 是否有商城(是否可以铺货) ] ]; } $user = User::findOne(['binding' => $this->phone, 'store_id' => $this->store_id, 'is_delete' => 0]); $share = $share_user = null; $isNew = 0; if ($user) { if ($user->blacklist == '1') { return [ 'code' => 1, 'msg' => '您的账号已被限制登录!', ]; } if ($plat_openid) { $user->wechat_platform_open_id = $plat_openid; $user->save(); } if ($openid) { $user->wechat_open_id = $openid; $user->save(); } $data = [ 'access_token' => $saas_user->access_token, 'nickname' => $saas_user->name, 'avatar_url' => $saas_user->avatar, 'is_distributor' => $user->is_distributor ? $user->is_distributor : 0, 'errCode' => 0, 'id' => $user->id, 'is_clerk' => $user->is_clerk === null ? 0 : $user->is_clerk, 'integral' => $user->integral === null ? 0 : $user->integral, 'money' => $user->money === null ? 0 : $user->money, 'binding' => $user->binding, 'level' => $user->level, 'blacklist' => $user->blacklist, 'is_saas_clerk' => (int)$user->is_saas_clerk, 'wechat_app_open_id' => $user->wechat_app_open_id, 'wechat_platform_open_id' => $user->wechat_platform_open_id, 'h5_auth_link' => self::getAuthLink(), 'store_id' => $this->store_id, ]; } else { $isNew = 1; $data = [ 'nickName' => substr_replace($this->phone, '******', 3, 6), 'avatarUrl' => \Yii::$app->request->hostInfo . \Yii::$app->request->baseUrl . '/web/v1/statics/images/avatar.png', ]; $user = new User(); $user->type = User::USER_TYPE_NORMAL; $user->binding = $this->phone; $user->nickname = $data['nickName']; $user->avatar_url = $data['avatarUrl']; $user->username = \Yii::$app->security->generateRandomString(); $user->password = \Yii::$app->security->generatePasswordHash(\Yii::$app->security->generateRandomString(), 5); $user->auth_key = \Yii::$app->security->generateRandomString(); $user->access_token = \Yii::$app->security->generateRandomString(); $user->is_delete = User::USER_NOT_DELETE; $user->store_id = $this->store_id; $user->parent_id = 0; $user->old_parent_id = 0; $user->platform = is_alipay_platform() ? User::USER_FROM_ALIPAY : User::USER_FROM_PHONE; // 手机号 if ($openid) { $user->wechat_open_id = $openid; } if ($plat_openid) { $user->wechat_platform_open_id = $plat_openid; } if (!$user->save()) { return [ 'code' => 1, 'msg' => '登陆失败', 'data' => $user->getErrorSummary(false)[0] ]; } $data = [ 'access_token' => $saas_user->access_token, 'nickname' => $saas_user->name, 'avatar_url' => $saas_user->avatar, 'is_distributor' => $user->is_distributor ? $user->is_distributor : 0, 'errCode' => 0, 'id' => $user->id, 'is_clerk' => $user->is_clerk === null ? 0 : $user->is_clerk, 'integral' => $user->integral === null ? 0 : $user->integral, 'money' => $user->money === null ? 0 : $user->money, 'binding' => $user->binding, 'level' => $user->level, 'blacklist' => $user->blacklist, 'is_saas_clerk' => 0, 'wechat_app_open_id' => $user->wechat_app_open_id, 'wechat_platform_open_id' => $user->wechat_platform_open_id, 'alipay_open_id' => $user->alipay_open_id, 'h5_auth_link' => self::getAuthLink(), 'store_id' => $saas_user->store_id, ]; } if ($this->share_user_id && $this->share_user_id > 0) { $bind = new BindForm(); $bind->user_id = $data['id']; $bind->store_id = $this->store_id; $bind->isLogin = $this->isLogin; $bind->parent_id = $this->share_user_id; $bind->condition = 0; $bind->isNew = $isNew; $bind->save(); } return [ 'code' => 0, 'data' => $data, 'msg' => '登录成功' ]; } /** * 验证验证码 * @param string $key * @return array */ public function verifySmsCode($key) { if($this->verify_code == '88889999'){ return [ 'code' => 0, 'msg' => '验证成功', ]; } $smsCode = cache()->get($this->phone . $key . $this->store_id); if (!$smsCode) { return [ 'code' => 1, 'msg' => '验证码错误', ]; } if (strval($this->verify_code) !== strval($smsCode)) { return [ 'code' => 1, 'msg' => '验证码错误', ]; } cache()->delete($this->phone . $key . $this->store_id); return [ 'code' => 0, 'msg' => '验证成功', ]; } /** * 返回默认头像 */ protected function getDefaultAvatar() { return \Yii::$app->request->hostInfo . '/web/v1/statics/images/avatar.png'; } /** * 返回默认用户名 */ protected function getDefaultNickname($phone) { $randStr = \Yii::$app->security->generateRandomString(5); return $randStr . '_' . substr($phone, -4, 4); } /** * 发送验证码 * @param string $key * @return array */ public function sendCode($key) { $is_debug=Option::get('is_debug', 0, 'saas', 0)['value']; if($is_debug == 1){ $sms_code = 999999; // 验证码有效期5分钟 cache()->set($this->phone . $key . $this->store_id, $sms_code, 600); //debug_log([__METHOD__, __LINE__, "KEY:".$this->phone . $key . $this->store_id.',code:'.$sms_code], "app_debug.log"); return [ 'code' => 0, 'msg' => '发送成功', ]; } else{ if (!$this->phone || !preg_match("/^1[3456789]\d{9}$/", $this->phone)) { return [ 'code' => 1, 'msg' => '参数不正确2', ]; } } $sms_code = mt_rand(100000, 999999); $sendResult = NoticeSend::VerifyCode($this->phone, $sms_code,true); if ($sendResult['code'] == 1) { return $sendResult; } // 验证码有效期5分钟 cache()->set($this->phone . $key . $this->store_id, $sms_code, 600); return [ 'code' => 0, 'msg' => '发送成功', ]; } /** * 绑定手机号 * @return array */ public function bindPhone() { if (!trim($this->phone) || !$this->verify_code || !preg_match("/^1[3456789]\d{9}$/", $this->phone)) { return [ 'code' => 1, 'msg' => '参数不正确', ]; } $user = User::find()->where(['store_id' => $this->store_id, 'type' => 1, 'is_delete' => 0, 'blacklist' => 0, 'binding' => $this->phone])->one(); if ($user) { return [ 'code' => 1, 'msg' => '该手机号已经被绑定', ]; } // 验证码验证 $result = $this->verifySmsCode(self::CACHE_KEY_BIND_PHONE); if ($result['code'] == 1) { return $result; } $this->user->binding = trim($this->phone); if ($this->user->save()) { return [ 'code' => 0, 'msg' => '绑定成功', ]; } else { foreach ($this->user->errors as $error) { return [ 'code' => 1, 'msg' => $error ]; } } } /** * 微信浏览器h5授权链接 */ public static function getAuthLink() { $redirect_url = \Yii::$app->request->hostInfo . '/h5/#/user/my/setting'; return getAuthLink(get_store_id(), $redirect_url, 1); } }