{
  "openapi": "3.0.1",
  "info": {
    "title": "微信小程序静默恢复登录态",
    "version": "1.0.0",
    "description": "增量同步到 Apifox：POST /api/passport/restoreMpWxLogin"
  },
  "servers": [
    {
      "url": "https://aizhctdev.yyangpt.cn/index.php?s=",
      "description": "开发环境"
    }
  ],
  "tags": [
    {
      "name": "用户认证模块/登录"
    }
  ],
  "paths": {
    "/api/passport/restoreMpWxLogin": {
      "post": {
        "tags": [
          "用户认证模块/登录"
        ],
        "summary": "微信小程序静默恢复登录态",
        "description": "清除微信缓存、本地 token 丢失或 token 过期后，通过微信 code 自动恢复已绑定用户登录态。\n\n认证：不需要 Access-Token。\n\n业务规则：\n- 前端清缓存后，本地没有 AccessToken，可调用该接口恢复登录。\n- 后端根据微信 openid 查找绑定账号。\n- 优先查 yoshop_user_oauth。\n- 兼容历史数据：如果 user_oauth 查不到，会回退查 yoshop_user.last_login_openid。\n- 如果同一个 openid 历史命中多个用户，不自动恢复，要求重新登录。\n- 用户主动退出登录后，该接口不会自动恢复登录。\n- 同一个微信先后登录多个账号时，以最后一次手动登录成功的账号为准。",
        "operationId": "post_api_passport_restoreMpWxLogin",
        "parameters": [
          {
            "name": "content-type",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "default": "application/json;charset=utf-8"
            },
            "description": "请求内容类型"
          },
          {
            "name": "platform",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "default": "MP-WEIXIN"
            },
            "description": "客户端平台"
          },
          {
            "name": "version",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "default": "2.0.48"
            },
            "description": "客户端版本"
          },
          {
            "name": "enterprise-no",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "企业编号，可选"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RestoreMpWxLoginRequest"
              },
              "example": {
                "form": {
                  "code": "wx.login 返回的 code"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "登录成功或业务失败。业务状态以响应体 status 字段为准。",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RestoreMpWxLoginResponse"
                },
                "examples": {
                  "success": {
                    "summary": "登录成功",
                    "value": {
                      "status": 200,
                      "message": "登录成功",
                      "data": {
                        "userId": 10001,
                        "token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                      }
                    }
                  },
                  "codeEmpty": {
                    "summary": "缺少 code",
                    "value": {
                      "status": 500,
                      "message": "缺少微信登录凭证",
                      "data": {
                        "restoreCode": "WECHAT_CODE_EMPTY"
                      }
                    }
                  },
                  "sessionInvalid": {
                    "summary": "微信身份无效",
                    "value": {
                      "status": 500,
                      "message": "微信身份识别失败",
                      "data": {
                        "restoreCode": "WECHAT_SESSION_INVALID"
                      }
                    }
                  },
                  "logoutDisabled": {
                    "summary": "主动退出后禁止静默登录",
                    "value": {
                      "status": 500,
                      "message": "用户已主动退出登录，请重新登录",
                      "data": {
                        "restoreCode": "LOGOUT_DISABLED"
                      }
                    }
                  },
                  "needBind": {
                    "summary": "微信未绑定账号",
                    "value": {
                      "status": 500,
                      "message": "当前微信未绑定账号，请重新登录",
                      "data": {
                        "restoreCode": "NEED_BIND"
                      }
                    }
                  },
                  "accountNotFound": {
                    "summary": "账号不存在",
                    "value": {
                      "status": 500,
                      "message": "账号不存在",
                      "data": {
                        "restoreCode": "ACCOUNT_NOT_FOUND"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "x-apifox-folder": "用户认证模块/登录"
      }
    }
  },
  "components": {
    "schemas": {
      "RestoreMpWxLoginRequest": {
        "type": "object",
        "required": [
          "form"
        ],
        "properties": {
          "form": {
            "type": "object",
            "required": [
              "code"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "小程序 uni.login / wx.login 返回的临时登录凭证"
              }
            }
          }
        }
      },
      "RestoreMpWxLoginResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "description": "业务状态码，200 表示成功，500 表示业务失败"
          },
          "message": {
            "type": "string",
            "description": "提示信息"
          },
          "data": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "userId": {
                    "type": "integer",
                    "description": "用户 ID"
                  },
                  "token": {
                    "type": "string",
                    "description": "新生成的登录 token，前端保存为 AccessToken"
                  }
                }
              },
              {
                "type": "object",
                "properties": {
                  "restoreCode": {
                    "type": "string",
                    "description": "静默恢复失败业务码",
                    "enum": [
                      "WECHAT_CODE_EMPTY",
                      "WECHAT_SESSION_INVALID",
                      "LOGOUT_DISABLED",
                      "NEED_BIND",
                      "ACCOUNT_NOT_FOUND"
                    ]
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}