php 微信開發獲取使用者資訊如何實現

2022-03-28 09:38:00 字數 1842 閱讀 2357

獲取使用者資訊的大致演算法是

使用者授權登入第三方**,

重點:scope引數:

snsapi_basic 靜默登入,不需要使用者授權,只能獲取到openid;

snsapi_userinfo ,需要使用者點選授權,能獲取到openid和所有使用者資訊;

第一步:先獲取使用者的code值;

第二步:根據code值去獲取access_token,每次請求的值都不一樣,如果沒有使用,每五分鐘更新一次;

第三步:根據access_token獲取使用者資訊;

1.獲取code**實現:

getcode.php?1

2345

6789

1011

1213

1415

if(isset($_session['user']))

='wx1d7c6fcd6131143b3';

$redirect_url="";

$scope='snsapi_userinfo';//獲取的方式;

$url=..'&redirect_uri='.urlencode($redirect_url).'&response_type=code&scope='.$scope.'&state=123#wechat_redirect';

header("location:".$url);

2、根據code獲取access_token和openid?1

2345

6789

1011

1213

1415

1617

1819

2021

2223

24getopenid.php

<?php

//獲取使用者openid

=;

=;

$code=$_get['code'];

functiongetopenid(,,$code)

echogetopenid(,,$code);

**建設

php微信網頁授權獲取使用者資訊

配置 網域名稱 1.引導使用者進入授權頁面同意授權,獲取code 2.通過code換取網頁授權access token 與基礎支援中的access token不同 3.如果需要,開發者可以重新整理網頁授權access token,避免過期 4.通過網頁授權access token和openid獲取使...

微信小程式開發獲取使用者資訊

responsebody public map decodeuserinfo string encrypteddata,string iv,string code string wxspsecret 授權 必填 string grant type authorization code 請求引數 傳送...

微信小程式開發學習 獲取使用者資訊

1 使用wx.login介面獲取使用者登入憑證的code,因為這些涉及到使用者的隱私,所有這個code需要我們處理 3 用獲取的code請求自己的介面,從而獲取使用者的openid 4 通過wx.login 獲取到使用者登入態之後,需要維護登入態。開發者要注意不應該直接把 session key o...