{
  "openapi": "3.0.3",
  "info": {
    "title": "VWCG-960 微信小程序登录态恢复",
    "version": "1.0.0",
    "description": "微信小程序清缓存后通过最近企业路由恢复登录态，并区分主动退出与清缓存。"
  },
  "servers": [
    {
      "url": "https://saidi.yyangpt.cn/aizhct",
      "description": "小程序统一访问地址"
    }
  ],
  "paths": {
    "/api/passport/resolveMpWxEnterprise": {
      "post": {
        "summary": "微信小程序识别最近登录企业",
        "description": "清缓存或无本地登录态时调用。请求头不带 enterprise-no，走默认项目。后台通过 wx.login code 换取 openid，并查询默认库最近企业路由。若用户主动退出过，返回 enterpriseNo 为空并带 logoutDisabled=1。",
        "tags": [
          "用户认证模块/微信小程序登录态恢复"
        ],
        "x-apifox-folder": "用户认证模块/微信小程序登录态恢复",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ResolveMpWxEnterpriseRequest"
              },
              "example": {
                "form": {
                  "code": "0f3a1b...",
                  "appid": "wxb4e2e1480798187c"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "识别成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ResolveMpWxEnterpriseResponse"
                },
                "examples": {
                  "hasEnterprise": {
                    "summary": "存在最近企业",
                    "value": {
                      "status": 200,
                      "message": "识别成功",
                      "data": {
                        "appid": "wxb4e2e1480798187c",
                        "openid": "oz3la7GpnxnSzCMohXV27YlbkrUw",
                        "enterpriseNo": "10001"
                      }
                    }
                  },
                  "logoutDisabled": {
                    "summary": "用户主动退出后不返回企业",
                    "value": {
                      "status": 200,
                      "message": "识别成功",
                      "data": {
                        "appid": "wxb4e2e1480798187c",
                        "openid": "oz3la7GpnxnSzCMohXV27YlbkrUw",
                        "enterpriseNo": "",
                        "logoutDisabled": 1
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/passport/restoreMpWxLogin": {
      "post": {
        "summary": "微信小程序静默恢复登录态",
        "description": "新版本可传 openid + enterprise_no + user_id；后台会校验 openid 与 user_id 在当前企业库确实绑定后才发 token。旧版本不传 user_id 时继续按 openid 恢复。",
        "tags": [
          "用户认证模块/微信小程序登录态恢复"
        ],
        "x-apifox-folder": "用户认证模块/微信小程序登录态恢复",
        "parameters": [
          {
            "$ref": "#/components/parameters/EnterpriseNoHeader"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RestoreMpWxLoginRequest"
              },
              "examples": {
                "newClient": {
                  "summary": "新版本传 openid",
                  "value": {
                    "form": {
                      "openid": "oz3la7GpnxnSzCMohXV27YlbkrUw",
                      "appid": "wxb4e2e1480798187c",
                      "enterprise_no": "10001"
                    }
                  }
                },
                "legacyClient": {
                  "summary": "旧版本传 code",
                  "value": {
                    "form": {
                      "code": "0f3a1b...",
                      "enterprise_no": "10001"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "登录成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LoginTokenResponse"
                },
                "example": {
                  "status": 200,
                  "message": "登录成功",
                  "data": {
                    "userId": 123,
                    "token": "login-token"
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/passport/bindMpWxEnterpriseRoute": {
      "post": {
        "summary": "微信小程序记录最近登录企业",
        "description": "正常登录成功后调用，默认库记录 appid + openid 最近登录的 enterprise_no + user_id；同一微信多账号时最新登录成功的用户覆盖旧记录。",
        "tags": [
          "用户认证模块/微信小程序登录态恢复"
        ],
        "x-apifox-folder": "用户认证模块/微信小程序登录态恢复",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/BindMpWxEnterpriseRouteRequest"
              },
              "example": {
                "form": {
                  "openid": "oz3la7GpnxnSzCMohXV27YlbkrUw",
                  "appid": "wxb4e2e1480798187c",
                  "enterprise_no": "10001"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "记录成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmptySuccessResponse"
                },
                "example": {
                  "status": 200,
                  "message": "记录成功",
                  "data": []
                }
              }
            }
          }
        }
      }
    },
    "/api/passport/disableMpWxEnterpriseRoute": {
      "post": {
        "summary": "微信小程序禁用最近登录企业恢复",
        "description": "退出登录可按 openid/code 禁用当前微信；修改密码后可只传 enterprise_no + user_id，禁用该企业该用户所有 openid 自动恢复。",
        "tags": [
          "用户认证模块/微信小程序登录态恢复"
        ],
        "x-apifox-folder": "用户认证模块/微信小程序登录态恢复",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/DisableMpWxEnterpriseRouteRequest"
              },
              "example": {
                "form": {
                  "openid": "oz3la7GpnxnSzCMohXV27YlbkrUw",
                  "appid": "wxb4e2e1480798187c",
                  "enterprise_no": "10001"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "记录成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmptySuccessResponse"
                },
                "example": {
                  "status": 200,
                  "message": "记录成功",
                  "data": []
                }
              }
            }
          }
        }
      }
    },
    "/api/passport/logout": {
      "post": {
        "summary": "退出登录",
        "description": "用户主动退出登录。请求头带 enterprise-no 时由 Nginx 转发到企业项目，企业库记录 user_oauth.silent_login_disabled=1；新版本会同时调用 disableMpWxEnterpriseRoute 禁用默认路由恢复。旧版本不传 openid 时仍按当前用户绑定关系处理。",
        "tags": [
          "用户认证模块/微信小程序登录态恢复"
        ],
        "x-apifox-folder": "用户认证模块/微信小程序登录态恢复",
        "parameters": [
          {
            "$ref": "#/components/parameters/EnterpriseNoHeader"
          },
          {
            "$ref": "#/components/parameters/AccessTokenHeader"
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LogoutRequest"
              },
              "example": {
                "form": {
                  "openid": "oz3la7GpnxnSzCMohXV27YlbkrUw",
                  "appid": "wxb4e2e1480798187c",
                  "enterprise_no": "10001"
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "操作成功",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/EmptySuccessResponse"
                },
                "example": {
                  "status": 200,
                  "message": "操作成功",
                  "data": []
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "parameters": {
      "EnterpriseNoHeader": {
        "name": "enterprise-no",
        "in": "header",
        "required": false,
        "description": "企业编号。静默登录和退出登录企业项目接口需要携带；默认项目路由接口不要携带。",
        "schema": {
          "type": "string",
          "example": "10001"
        }
      },
      "AccessTokenHeader": {
        "name": "Access-Token",
        "in": "header",
        "required": false,
        "description": "登录 token。退出登录时通常需要携带。",
        "schema": {
          "type": "string"
        }
      }
    },
    "schemas": {
      "ResolveMpWxEnterpriseRequest": {
        "type": "object",
        "required": [
          "form"
        ],
        "properties": {
          "form": {
            "type": "object",
            "required": [
              "code",
              "appid"
            ],
            "properties": {
              "code": {
                "type": "string",
                "description": "wx.login 返回的临时登录凭证"
              },
              "appid": {
                "type": "string",
                "description": "小程序 appid"
              }
            }
          }
        }
      },
      "RestoreMpWxLoginRequest": {
        "type": "object",
        "required": [
          "form"
        ],
        "properties": {
          "form": {
            "type": "object",
            "required": [
              "enterprise_no"
            ],
            "properties": {
              "openid": {
                "type": "string",
                "description": "微信 openid，新版本优先传"
              },
              "code": {
                "type": "string",
                "description": "wx.login code，旧版本兼容"
              },
              "appid": {
                "type": "string"
              },
              "enterprise_no": {
                "type": "string",
                "description": "企业编号"
              },
              "user_id": {
                "type": "integer",
                "description": "最近登录用户ID；用于按企业+用户精确恢复或禁用静默登录",
                "example": 10086
              }
            }
          }
        }
      },
      "BindMpWxEnterpriseRouteRequest": {
        "type": "object",
        "required": [
          "form"
        ],
        "properties": {
          "form": {
            "type": "object",
            "required": [
              "appid",
              "enterprise_no"
            ],
            "properties": {
              "openid": {
                "type": "string"
              },
              "code": {
                "type": "string",
                "description": "旧版本兼容"
              },
              "appid": {
                "type": "string"
              },
              "enterprise_no": {
                "type": "string"
              },
              "user_id": {
                "type": "integer",
                "description": "最近登录用户ID；用于按企业+用户精确恢复或禁用静默登录",
                "example": 10086
              }
            }
          }
        }
      },
      "DisableMpWxEnterpriseRouteRequest": {
        "type": "object",
        "required": [
          "form"
        ],
        "properties": {
          "form": {
            "type": "object",
            "required": [],
            "properties": {
              "openid": {
                "type": "string"
              },
              "code": {
                "type": "string",
                "description": "退出时如果没有 openid，可传 wx.login code"
              },
              "appid": {
                "type": "string",
                "description": "小程序 appid；按 openid/code 禁用时必传，按 enterprise_no + user_id 批量禁用时可不传"
              },
              "enterprise_no": {
                "type": "string",
                "description": "当前企业编号；与 user_id 一起传时禁用该企业该用户所有 openid 自动恢复"
              },
              "user_id": {
                "type": "integer",
                "description": "最近登录用户ID；用于按企业+用户精确恢复或禁用静默登录",
                "example": 10086
              }
            }
          }
        }
      },
      "LogoutRequest": {
        "type": "object",
        "properties": {
          "form": {
            "type": "object",
            "properties": {
              "openid": {
                "type": "string"
              },
              "code": {
                "type": "string",
                "description": "旧版本兼容"
              },
              "appid": {
                "type": "string"
              },
              "enterprise_no": {
                "type": "string"
              },
              "user_id": {
                "type": "integer",
                "description": "最近登录用户ID；用于按企业+用户精确恢复或禁用静默登录",
                "example": 10086
              }
            }
          }
        }
      },
      "ResolveMpWxEnterpriseResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "example": 200
          },
          "message": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "properties": {
              "appid": {
                "type": "string"
              },
              "openid": {
                "type": "string"
              },
              "enterpriseNo": {
                "type": "string",
                "description": "最近企业编号；为空时进入正常登录"
              },
              "logoutDisabled": {
                "type": "integer",
                "description": "1 表示用户主动退出过，不允许静默恢复"
              },
              "userId": {
                "type": "integer",
                "description": "最近登录用户ID；为空或0时旧版本逻辑按 openid 查当前企业绑定用户",
                "example": 10086
              }
            }
          },
          "trace_id": {
            "type": "string"
          }
        }
      },
      "LoginTokenResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "example": 200
          },
          "message": {
            "type": "string"
          },
          "data": {
            "type": "object",
            "properties": {
              "userId": {
                "type": "integer"
              },
              "token": {
                "type": "string"
              }
            }
          },
          "trace_id": {
            "type": "string"
          }
        }
      },
      "EmptySuccessResponse": {
        "type": "object",
        "properties": {
          "status": {
            "type": "integer",
            "example": 200
          },
          "message": {
            "type": "string"
          },
          "data": {
            "oneOf": [
              {
                "type": "array"
              },
              {
                "type": "object"
              },
              {
                "type": "string"
              }
            ]
          },
          "trace_id": {
            "type": "string"
          }
        }
      }
    }
  }
}
