Skip to main content

一、问题背景

企业微信平台的服务端 API 要求调用方 IP 在白名单内。Edge Function(Supabase / Deno Deploy)是 serverless 架构,每次请求的出口 IP 不固定,无法直接加入平台白名单。 需要一个固定出口 IP 的代理层,所有对平台 API 的请求通过它中转,这样只需在平台白名单中添加代理服务器的 IP 即可。

二、代理服务

2.1 地址

https://gateway.superun.ai/proxy/forward

2.2 工作原理

代理是完全透明的——不解析、不修改请求内容,只负责将请求原样转发到目标地址,并将响应原样返回。

2.3 接口规范

[GET|POST|PUT|DELETE|PATCH] https://gateway.superun.ai/proxy/forward?target_url={encodeURIComponent 编码后的目标URL}
参数位置说明
target_urlQuery 参数(必填)目标请求的完整 URL,需要 encodeURIComponent 编码
superun-cloud-api-keyHeader(必填)Superun Cloud API Key,用于身份验证。在 Deno 环境中通过 Deno.env.get("SUPERUN_CLOUD_API_KEY") 获取
Method / Headers / Body透传:过滤掉 hop-by-hop 头和 superun-cloud-api-key 后原样转发,响应同样原样返回
错误响应
状态码响应体含义
401 Unauthorizedsuperun-cloud-api-key is missing or invalid. This API is only available in superun Cloud Edge Functionsuperun-cloud-api-key 缺少或无效。该接口仅允许在 Superun Cloud Edge Function 中调用
403 ForbiddenProxy host was not supported, please contact the superun team目标域名未在代理白名单中,需向 Superun 团队申请开通
502 Bad GatewayBad Gateway代理无法连接到目标服务器
500 Internal Server ErrorInternal Server Error代理自身异常

三、Edge Function 调用方式

3.1 通用 proxyFetch 函数

const PROXY_BASE = "https://gateway.superun.ai/proxy/forward";
const SUPERUN_API_KEY = Deno.env.get("SUPERUN_CLOUD_API_KEY")!;

async function proxyFetch(
  targetUrl: string,
  init?: RequestInit
): Promise<Response> {
  const proxyUrl = `${PROXY_BASE}?target_url=${encodeURIComponent(targetUrl)}`;
  const headers = new Headers(init?.headers);
  headers.set("superun-cloud-api-key", SUPERUN_API_KEY);
  return fetch(proxyUrl, {
    method: init?.method ?? "GET",
    headers,
    body: init?.body,
  });
}

3.2 使用示例

GET 请求(企微获取 access_token):
const url = `https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=${corpId}&corpsecret=${corpSecret}`;
const resp = await proxyFetch(url);
const data = await resp.json();

四、白名单配置

代理服务器的固定出口 IP:
43.153.7.159
43.153.29.204

五、域名白名单

代理服务对目标域名实施白名单机制。只有经过 Superun 团队审批的域名才能通过代理转发,未授权的域名将返回 403 Forbidden 如需新增代理域名,请联系 Superun 团队申请开通。

superun 网站

访问该网站以了解更多功能和示例.