jfinal 微信授權登入

2021-09-23 23:52:08 字數 2158 閱讀 2887

第一步,獲取code,上述鏈結中有ios平台和android平台獲取code的示例,暫不做描述

第二步,通過code獲取access_token和openid

private static final string weixin_auth_login_url = "";	// 授權登入url
// 獲取access_token和openid

string accesstoken = jologin.optstring("access_token"); // 介面呼叫憑證

string refreshtoken = jologin.optstring("refresh_token"); // 使用者重新整理access_token

string scope = jologin.optstring("scope"); // 使用者授權的作用域

string expiresin = jologin.optstring("expires_in"); // access_token介面呼叫憑證超時時間,單位秒

第三步,通過access_token和openid獲取使用者資訊

// 獲取使用者資訊

string nickname = jouser.optstring("nickname"); // 使用者暱稱

string headimgurl = jouser.optstring("headimgurl"); // 使用者頭像

string unionid = jouser.optstring("unionid"); // 使用者統一標識

string *** = jouser.optstring("***"); // 使用者性別,1為男性,2為女性

最後,生成token並處理需要的邏輯

string username = null;

string password = null;

string mail = null;

string phone = null;

string *** = null;

string headimgurl = wxuser.getheadimgurl();

string nickname = wxuser.getnickname();

string openid = wxuser.getopenid();

user user = userservice.findinfobyopenid(wxuser.getopenid());

if (user == null)

string newtoken = tokenmanager.getme().generatetoken(user);

// 處理別的邏輯

jsonobject.put("token", newtoken);

jsonobject.put("user", user);

jsonobject.put("code", 1);

jsonobject.put("msg", "登入成功");

renderjson(jsonobject.tojsonstring());

return;

微信授權登入

使用者同意授權url 對urlencode之後 private static string redirect url 使用者同意授權url private static string authorization url 建立授權url param state return throws except...

微信授權登入

首先說一下我寫這個的初衷 注意了 使用開放平台,需要備案的網域名稱才可以。且開放平台需要認證 使用公眾平台,那就更不要說了,更需要認證。開發反而不難了,因為那個對著api文件花些時間就可以了,就不貼了,那個沒啥意思,上面的資訊值金子 需要認證,需要認證,需要認證 開放平台api 公眾平台api 當然...

iOS 微信授權登入

通過access token進行介面呼叫,獲取使用者基本資料資源或幫助使用者實現基本操作。3 準備工作 3.1 更改plist檔案如下 這樣就可以允許http傳輸了 那麼 如下 ibaction sendauthrequest 4.1 引數說明 4.3 返回結果說明 通過code獲取access t...