Mini Program Login Credential Verification

Last edited on 2026-07-04

This API should be called on the server side and cannot be called directly on the client side (Mini Program, web page, APP, etc.). For details, please refer to API Call Guide.

API English Name: code2Session

Verifies login credentials. After obtaining the temporary login credential code via the wx.login API, send it to your developer server and call this API to complete the login flow. For more usage details, see Mini Program Login.

1. Call Method

HTTPS Call

GET https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JS_CODE&grant_type=GRANT_TYPE

Cloud Call

  • This API does not support cloud call.

Third-party Call

  • This API does not support third-party platform calls.

2. Request Parameters

Query Parameters Query String Parameters

ParameterTypeRequiredDescription
appidstringYesMini Program appId
secretstringYesMini Program appSecret
js_codestringYesThe `code` obtained during login. You can retrieve it via wx.login.
grant_typestringYesThe authorization type. Enter `authorization_code` here.

Request Body Request Payload

None

3. Response Parameters

Response Body Response Payload

ParameterTypeDescription
session_keystringSession key
unionidstringThe unique identifier of the user on the Open Platform. This is returned if the current Mini Program is bound to a WeChat Open Platform account. For details, see UnionID Mechanism Description.
openidstringUnique user identifier
errcodenumberError code. Returned when the request fails.
errmsgstringError message. Returned when the request fails.

4. Notes

No special notes for this API

5. Code Example

Request Example

GET https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code

Response Example

{
  "openid": "xxxxxx",
  "session_key": "xxxxx",
  "unionid": "xxxxx",
  "errcode": 0,
  "errmsg": "xxxxx"
}

6. Error Codes

The following is the error code list of this API, other error codes can refer to Common Error Codes; When encountering errors in calling the API, you can use the official API Diagnostic Tool to assist in locating and analyzing problems.

Error CodeError DescriptionSolution
-1system errorThe system is busy. Please try again later.
40029Invalid `code`Invalid `js_code`
40226code blockedHigh-risk user. Mini Program login is intercepted. For details on risk levels, see User Security Solutions
45011api minute-quota reach limit  mustslower  retry next minuteAPI calls are too frequent. Please try again later.

7. Applicable Scope

API callable status for different account types:
Mini ProgramMini Game
✔ ✔
  • ✔:This account type can call this API。
  • Other account types not explicitly declared cannot call this API unless otherwise specified.