久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      【干貨】ThinkPHP6對接微信掃碼登錄

      在近幾年的互聯(lián)網(wǎng)網(wǎng)站中,使用微信登錄的場景可是越來越多。據(jù)統(tǒng)計2020年,全球微信高達11億,也確實如此,微信這個好用的社交工具,可以說小到一個小學(xué)生大到你的七大姑八大姨,很多人可能沒有QQ,但他一定有微信。所以微信登錄是程序員必備的一項工作技能。

      微信掃碼登錄對接ThinkPHP6,話不多說,直接上車。

      一、準備資料:

      1、訪問 https://open.weixin.qq.com/,注冊賬戶。

      2、開發(fā)者認證:企業(yè)。

      3、創(chuàng)建一個網(wǎng)站應(yīng)用:網(wǎng)站域名必須備案(可使用二級域名),獲得相應(yīng)的AppID和AppSecret,申請微信登錄且通過審核。

      二、接入微信登錄步驟:

      首先看下微信官網(wǎng)給出的步驟說明:https://developers.weixin.qq.com/doc/oplatform/Website_App/WeChat_Login/Wechat_Login.html

      1. 第三方發(fā)起微信授權(quán)登錄請求,微信用戶允許授權(quán)第三方應(yīng)用后,微信會拉起應(yīng)用或重定向到第三方網(wǎng)站,并且?guī)鲜跈?quán)臨時票據(jù)code參數(shù);

      2. 通過code參數(shù)加上AppID和AppSecret等,通過API換取access_token;

      3. 通過access_token進行接口調(diào)用,獲取用戶基本數(shù)據(jù)資源或幫助用戶實現(xiàn)基本操作。

      三、接入微信登錄實操環(huán)節(jié):

      1、放好微信登錄圖標(biāo),并添加鏈接。

      比如鏈接到www.a,com/index/user/weixindenglu。下面我們看下weixindenglu方法代碼。

      public function weixindenglu(){    $appid='wx868f988d79a4f2bb';    $redirect_uri=urldecode('http://www.dongpaiweb.cn/index/index/weixin.html');    $url='https://open.weixin.qq.com/connect/qrconnect?appid='.$appid.'&redirect_uri='.$redirect_uri.'&response_type=code&scope=snsapi_login&state=STATE#wechat_redirect';         header("location:".$url); }

      這個時候我們點擊微信小圖標(biāo)就會出現(xiàn)掃碼的界面。拿出手機趕緊微信掃碼。

      注意:$redirect_uri是我們的回調(diào)地址,意思是用戶微信掃碼后的處理地址)。

      2、獲得用戶的code。

      微信掃碼后就跳轉(zhuǎn)到了上面定義的回調(diào)地址weixin方法。我們看下weixin方法代碼:

          public function weixin(){         $code=input('get.code');     }

      code獲取很簡單,我們看下打印效果:

      【干貨】ThinkPHP6對接微信掃碼登錄

      3、獲得Access Token 和openid,我們在weixin()方法中繼續(xù)添加代碼:

      public function weixin(){         $code=input('get.code');         $appid='wx868f988d79a4f25b';         $appsecret='82b426f2882b6a1398b8312cc1de037b';         $url='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';                  //json對象變成數(shù)組         $res=json_decode(file_get_contents($url),true);         $access_token=$res['access_token'];         $openid=$res['openid'];      }

      這樣我們就獲取到了access_token和openid,我們看下打印效果:

      【干貨】ThinkPHP6對接微信掃碼登錄

      5、獲取用戶全部信息,我們在weixin()方法中繼續(xù)添加代碼:

      public function weixin(){         $code=input('get.code');         $appid='wx868f988d79a4f25b';         $appsecret='82b426f2882b6a1398b8312cc1de037b';         $url='https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';                  //json對象變成數(shù)組         $res=json_decode(file_get_contents($url),true);         $access_token=$res['access_token'];         $openid=$res['openid'];          $urlyonghu='https://api.weixin.qq.com/sns/userinfo?access_token='.$access_token.'&openid='.$openid;         $user=json_decode(file_get_contents($urlyonghu),true);         print_r($user);     }

      這樣我們就獲取了用戶的昵稱、地址、頭像等信息,看下打印效果:

      【干貨】ThinkPHP6對接微信掃碼登錄

      在我們獲取用戶微信信息后,我們就可以整理數(shù)據(jù)入庫了。

      如果是用戶第一次登錄,我們可以設(shè)置綁定手機號的界面,綁定手機號后即算是注冊成功。如果我們檢測到已經(jīng)綁定手機號,即代表登錄成功跳轉(zhuǎn)到成功界面。

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號