LoginSignup
0
0

More than 1 year has passed since last update.

Weixin Openplatform OAuth2.0 Authorization Code Grant 連携メモ

Posted at

Weixin Openplatform のOAuth2.0 Authorization Code Grant 連携方法についてメモする。

シーケンス

wechat_acg.png

認可リクエスト

GET https://open.weixin.qq.com/connect/qrconnect
?appid d=APPID
&redirect_uri=REDIRECT_URI
&response_type=code
&scope=SCOPE
&state=STATE
パラメータ 必須 説明
appid アプリケーション識別子
redirect_uri リダイレクトURI
response_type code
scope 認可スコープ。Webアプリの場合はsnsapi_loginのみ。複数指定時は,区切り。
state CSRF対策文字列

認可レスポンス

redirect_uri?code=CODE&state=STATE

トークンリクエスト

GET https://api.weixin.qq.com/sns/oauth2/access_token
?appid=APPID
&secret=SECRET
&code=CODE
&grant_type=authorization_code
パラメータ 必須 Description
appid アプリケーション識別子
secret アプリケーション登録時に発行されたシークレット
code 認可コード
grant_type authorization_code

トークンレスポンス

{ 
"access_token":"ACCESS_TOKEN", 
"expires_in":7200, 
"refresh_token":"REFRESH_TOKEN",
"openid":"OPENID", 
"scope":"SCOPE",
"unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
}

openid : ユーザーID。

unionid : ユーザーがユーザー情報取得を認可した際に表示される識別子。WeixinOpenPlatformアカウント内で一意。同じWeixinOpenPlatformアカウントのアプリケーションは、同じunionidを共有する。

Userinfo APIリクエスト

GET https://api.weixin.qq.com/sns/userinfo
?access_token=ACCESS_TOKEN
&openid=OPENID
パラメータ 必須 説明
access_token アクセストークン
openid ユーザーID。トークンレスポンスで取得した値。
lang 定義域:zh_CN(default)、 zh_TW、 en

Userinfo API レスポンス

{
"openid":"OPENID",
"nickname":"NICKNAME",
"sex":1,
"province":"PROVINCE",
"city":"CITY",
"country":"COUNTRY",
"headimgurl": "http://wx.qlogo.cn/mmopen/g3MonUZtNHkdmzicIlibx6iaFqAc56vxLSUfpb6n5WKSYVY0ChQKkiaJSgQ1dZuTOgvLLrhJbERQQ4eMsv84eavHiaiceqxibJxCfHe/0",
"privilege":[
"PRIVILEGE1",
"PRIVILEGE2"
],
"unionid": " o6_bmasdasdsad6_2sgVt7hMZOPfL"
}

参考情報

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0