RedLine 微信授权接口

需要先申请好 AppKeyAppSecret,照着下面的顺序复制 Python 代码、替换文字,就能完成调用。

整套流程:查出微信的 OpenID → 填入小程序 AppID → 获取 code

接口 Base URL(所有请求都从这里开始) https://wechat.316199.xyz

你只需要准备 3 样东西

  1. 1 一个已经授权的微信账号

    先去 RedLine 主站的“微信授权”页面扫码并授权成功,会得到一个 OpenID,把它保存下来。这里负责调用接口,不负责扫码登录。

  2. 2 AppKey 和 AppSecret

    在主站的“API接口”页面申请。可以把它们理解成接口账号和接口密码。

  3. 3 一台能运行 Python 3 的电脑

    第一次使用时,在终端执行下面这条命令,安装请求工具。

    终端里执行一次
    python -m pip install requests
AppSecret 只显示一次。 不要发给别人,也不要上传到公开仓库。忘记后无法找回,只能去主站重置。

先查出你的微信 OpenID

这一步只查询账号信息,不获取 code,也不扣积分。

GET https://wechat.316199.xyz/api/yyb/get-info

复制下面的 Python 代码

只需要替换第 4、5 行引号里的内容,然后运行。

01_get_info.py
import requests

BASE_URL = "https://wechat.316199.xyz"
APP_KEY = "换成你的 AppKey"
APP_SECRET = "换成你的 AppSecret"

response = requests.get(
    f"{BASE_URL}/api/yyb/get-info",
    headers={
        "AppKey": APP_KEY,
        "AppSecret": APP_SECRET,
    },
    timeout=30,
)

result = response.json()
print(result)

if result.get("success"):
    accounts = result["data"]["wechat_auth"]["accounts"]
    for account in accounts:
        print("微信备注:", account["remark"])
        print("OpenID:", account["openid"])
        print("是否可用:", account["is_valid"])
运行后重点看哪一行?

找到程序打印的 OpenID,复制它。只有“是否可用”显示 True 的微信账号才能继续下一步。

查看接口原始返回示例
JSON 返回内容
{
  "success": true,
  "data": {
    "user": {
      "username": "示例用户",
      "points": 120.5
    },
    "app_key": {
      "total_call_count": 7,
      "get_info_call_count": 4,
      "get_code_call_count": 3,
      "last_used_at": "2026-07-03 08:00:00"
    },
    "wechat_auth": {
      "accounts": [
        {
          "id": "account-1",
          "remark": "我的微信",
          "openid": "o123456789",
          "nickname": "微信昵称",
          "status": "online",
          "is_valid": true
        }
      ]
    },
    "billing": {
      "billing_date_cn": "2026-07-03",
      "free_quota": 1,
      "used_success_count": 0,
      "over_quota_cost_points": 10
    }
  }
}

用 OpenID 获取小程序 code

把上一步查到的 OpenID 和目标小程序 AppID 填进代码,就可以发起请求。

POST https://wechat.316199.xyz/api/yyb/get-code

复制下面的 Python 代码

替换第 4 到 7 行引号里的内容,然后运行。

02_get_code.py
import requests

BASE_URL = "https://wechat.316199.xyz"
APP_KEY = "换成你的 AppKey"
APP_SECRET = "换成你的 AppSecret"
OPENID = "换成第 1 步查到的 OpenID"
APPID = "换成目标小程序的 AppID"

response = requests.post(
    f"{BASE_URL}/api/yyb/get-code",
    headers={
        "AppKey": APP_KEY,
        "AppSecret": APP_SECRET,
    },
    json={
        "openid": OPENID,
        "appid": APPID,
    },
    timeout=30,
)

result = response.json()

if result.get("success"):
    print("获取成功,code 是:", result["data"]["code"])
else:
    print("获取失败,原因是:", result.get("message"))
怎么判断成功?

返回里的 successtrue,就从 data.code 读取 code。失败时直接看 message,里面会写明原因。

查看成功返回示例
JSON 返回内容
{
  "success": true,
  "message": "获取 code 成功",
  "data": {
    "code": "021abc...",
    "openid": "o123456789",
    "appid": "wx1234567890abcdef",
    "billing": {
      "billing_date_cn": "2026-07-03",
      "free_quota": 1,
      "used_before": 0,
      "used_free_quota": true,
      "charged_cents": 0,
      "charged_points": 0,
      "deducted": false,
      "refunded": false
    }
  }
}
关于费用: 每天有免费成功调用次数。免费次数用完后,成功获取一次 code 扣 10 积分;接口请求失败不会扣这次积分。

先看状态码,再看 message

代码运行失败不用慌。打印接口返回内容后,对照下面排查。

查看失败返回示例
JSON 返回内容
{
  "success": false,
  "message": "该 OpenID 不属于当前用户,或授权账号已删除"
}