WeChat Login API

Mini Program login and session exchange.

GitHub OpenAPI
Business capability
Customer Sign-In AE-160.10

Operations 1

Each operation below carries the questions people ask an LLM about it and the instructions they give an agent to run it. Generated by API Evangelist overlay

GET /sns/jscode2session Exchange a login code for openid and session key · auth.code2Session #
Ask an LLM
“How do I turn a temporary login code from a WeChat Mini Program into an openid and session key?”
“Can I decrypt user data with the session key returned from a login code exchange?”
Tell an agent
Exchange login code {js_code} for openid and session key using app {appid} and secret {secret}.
Convert mini program login code {js_code} into a session key for decrypting encrypted data.

Specifications

Work with this as data

Every API here is available over the APIs.io API and to AI agents over MCP.

MCP server

One button, every client — Claude, Cursor, VS Code and the rest.

https://apis.io/mcp

Tools for apis

7 MCP tools reach this
  • find_apisBrowse and filter every API in the catalog.
  • get_api_artifactsOne API's artifacts, grouped by type.
  • get_openapiThe primary OpenAPI for this API.
  • find_similar_apisAPIs that look like this one.
  • apis_io_searchSTART HERE — APIs, providers and tags for one query, each with its total.
  • resolveTurn a domain, URL or GitHub org into the provider it belongs to.
  • find_cohortsEvery scored population of providers in the catalog.
All 92 tools →

Call it yourself

curl for this page
This API
curl "https://apis.io/api/v1/apis/wechat:wechat-login-api"
All apis
curl "https://apis.io/api/v1/apis?limit=25"

Calls without X-API-Key need no key. Calls with it need a paid plan — get a key.

Get an API key

Free tier, no form to fill in. Signing in shares your email address with us — we store it to create your key and to recognise you if you sign in with another provider. By signing up you are subscribing to the APIs.io and API Evangelist newsletters — you can unsubscribe from any issue. See our Privacy Policy and Terms.

A second provider on the same verified email joins the account you already have.

OpenAPI Specification

wechat-login-api-openapi.yml Raw ↑
openapi: 3.2.0
info:
  title: WeChat Mini Program Server API (subset) Login API
  description: 'Subset OpenAPI description for the WeChat (Weixin) Mini Programs server-side

    API hosted at `api.weixin.qq.com`.'
  version: 1.0.0
  contact:
    name: WeChat Developer Community
    url: https://developers.weixin.qq.com/community/
  license:
    name: Proprietary
servers:
- url: https://api.weixin.qq.com
  description: WeChat production API
tags:
- name: Login
  description: Mini Program login and session exchange.
paths:
  /sns/jscode2session:
    get:
      tags:
      - Login
      summary: auth.code2Session
      description: 'Exchange a temporary login `code` returned by `wx.login()` in the Mini

        Program client for a stable `openid` and `session_key`. The

        `session_key` is used to decrypt encrypted user data delivered by other

        Mini Program APIs.'
      operationId: code2Session
      parameters:
      - in: query
        name: appid
        required: true
        schema:
          type: string
        description: Mini Program AppID.
      - in: query
        name: secret
        required: true
        schema:
          type: string
        description: Mini Program AppSecret.
      - in: query
        name: js_code
        required: true
        schema:
          type: string
        description: Temporary login credential `code` from `wx.login()`.
      - in: query
        name: grant_type
        required: true
        schema:
          type: string
          enum:
          - authorization_code
        description: Must be `authorization_code`.
      responses:
        '200':
          description: Session exchange result.
          content:
            application/json:
              schema:
                oneOf:
                - type: object
                  properties:
                    openid:
                      type: string
                      description: Mini Program-scoped user identifier.
                    session_key:
                      type: string
                      description: Session key used to decrypt encrypted payloads.
                    unionid:
                      type: string
                      description: WeChat Open Platform-wide UnionID (when applicable).
                - $ref: '#/components/schemas/WeChatError'
components:
  schemas:
    WeChatError:
      type: object
      description: Standard WeChat API error envelope.
      properties:
        errcode:
          type: integer
          description: Numeric WeChat error code; `0` indicates success.
        errmsg:
          type: string
          description: Human-readable error message.
externalDocs:
  description: WeChat Mini Program Server API
  url: https://developers.weixin.qq.com/miniprogram/en/dev/api-backend/