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

2021-07-31 11:34:00 字數 2576 閱讀 3675

第一種獲取方案

1、首先呼叫wx.login()介面 讓使用者授權驗證,也就是我們肉眼觀察到的,你是否對***xx授權這種資訊。

2、使用者成功授權後,呼叫wx.getuserinfo() 介面獲取使用者資訊。

完整**如下

wx

.login(

}); }

});

第二種比較複雜了,需要與後台進行互動才能獲得userinfo,但是這種方案獲得的資料是完整的(包含openid)。

1、呼叫wx.login()介面 授權 在success 成功函式的引數中包含code。

2、呼叫wx.getuserinfo()介面success 函式中包含encrypteddata、iv

3、將上述引數傳給後台解析,生成userinfo

**如下

後台解析

/**

* 獲取粉絲資訊

* 其中的引數就是前端傳遞過來的

*/public

function

wxuserinfo

($code,$encrypteddata,$iv)

if(!$userinfo)

//$userinfo = json_decode($userinfo,true);

//載入使用者服務

//$userservice = load_service("user");

//$userservice->checkuser($this->projectid,$userinfo);

echo

}

curlhttp 函式是乙個自定函式 該函式的原始碼檢視我的這篇文章

//獲取粉絲資訊

function

getuserinfo

require_once rootpath . "/extends/wxuser/wxbizdatacrypt.php";

$data = array();

$errcode = $pc->decryptdata($encrypteddata, $iv, $data );

if ($errcode == 0) else

}

自己寫的小工具 request.js

//遠端請求

//檔案上傳

},//get 請求

},//post 請求

},//檔案上傳

覺得不錯請打賞,您的十分滿意是筆者的無限動力

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

後端解密,獲得使用者具體資訊。官方介面文件 使用spring boot中的resttemplate來傳送請求 public loginresult dologin string code catch exception e 官方介面文件 org.bouncycastlegroupid bcprov ...

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

getuserinfo bind getuserinfo getuserinfo 獲取使用者資訊 button 獲取應用例項 這是全域性變數的配置 data hasuserinfo false caniuse wx.caniuse button.open type.getuserinfo 這是判斷是...

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

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