鍍金池/ 問答/PHP/ 當(dāng)用戶綁定手機(jī)與數(shù)據(jù)庫手機(jī)一致時(shí)捆綁之前的用戶ID

當(dāng)用戶綁定手機(jī)與數(shù)據(jù)庫手機(jī)一致時(shí)捆綁之前的用戶ID

當(dāng)用戶綁定手機(jī)與數(shù)據(jù)庫手機(jī)一致時(shí)捆綁之前的用戶ID

原先使用的公眾號(hào)被停。新申請(qǐng)的公眾號(hào) 用戶只要進(jìn)來 通過微信授權(quán)自動(dòng)登錄 因?yàn)閛penid新的 相當(dāng)于生成一個(gè)新的用戶。現(xiàn)在想用戶通過 手機(jī)驗(yàn)證 捆綁之前的用戶。

附上代碼

請(qǐng)大家?guī)统龀鲋饕?/p>

 public function bind(Request $request, Application $wechat) {

        $user = session('wechat.oauth_user');
        $user = User::where('id_wechat', $user->id)->first();

        if($user->body_phone != 0){
            return redirect('/');
        }

        if ($request->isMethod('post')) {

            if(!$request->input('mobile', null)
            || !$request->input('vcode', null)){
                return view('application.info', [
                    'title' => '綁定失敗',
                    'icon' => 'warn',
                    'content' => '請(qǐng)將表單填寫完整,謝謝'
                ]);
            }

           
            if(Captcha::where('body_mobile', $request->input('mobile'))->where('body_code', $request->input('vcode'))->count() == 0){
                return view('application.info', [
                    'title' => '綁定失敗',
                    'icon' => 'warn',
                    'content' => '您填寫的驗(yàn)證碼不正確'
                ]);
            }

            Captcha::where('body_mobile', $request->input('mobile'))->where('body_code', $request->input('vcode'))->delete();

            $user->body_phone = $request->input('mobile');
            $user->save();

            return redirect('/');
            
        } else {

            return view('application.accountBind', [
                'title' => '賬戶激活'
            ]);

        }

    }
    
    

這段是原先網(wǎng)頁授權(quán)后 一定要通過手機(jī)激活才能繼續(xù)訪問。。

那么我怎么加上 如何寫呢?

回答
編輯回答
悶騷型

原有數(shù)據(jù)表是否需要保留?
如果不需要,按照樓上的答案,通過手機(jī)號(hào)查找userid,更新對(duì)應(yīng)的openid即可;
如果需要,通過手機(jī)號(hào)查找數(shù)據(jù),復(fù)制該條到新表中,使用全新的openid也可以。

2017年6月23日 00:30
編輯回答
逗婦惱

通過手機(jī)號(hào)查找user_id,然后更新對(duì)應(yīng)的openid,這樣不行嗎?

2017年2月14日 15:23