From 8b7800032d47bccfde324978351716aae0e75bee Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Mon, 5 Oct 2026 17:01:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(subscription):=20=E8=AE=A2=E9=98=85?= =?UTF-8?q?=E5=AE=A2=E6=88=B7=E7=AB=AF=E5=A2=9E=E5=8A=A0=E5=A3=B0=E6=98=8E?= =?UTF-8?q?=E5=AE=9A=E5=88=B6=E9=A1=B5=E4=B8=8E=E9=89=B4=E6=9D=83=E6=8E=A2?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SubscriptionClient 新增 Ping() 与 DeclareCustomPage():提供者子服务器用「产品 ApiKey+密钥」换令牌后,调用主服务器 Provider/Page/Save 声明本产品定制页的远端入口(供消费者「我的订阅」打开)。 --- subscription/client.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/subscription/client.py b/subscription/client.py index 4d41439..b336dbc 100644 --- a/subscription/client.py +++ b/subscription/client.py @@ -109,6 +109,34 @@ class SubscriptionClient: headers = {'Authorization': f'Bearer {token}'} return self._HttpRequest(Method, Path, Json=Json, Params=Params, Headers=headers) + # ── 提供者子服务器业务操作(ApiKey + 密钥 换取令牌后调用) ────────── + + def Ping(self): + """鉴权连通性探测(验证 ApiKey+密钥 可正常换取令牌并访问提供者接口)""" + return self._CallProvider('GET', '/API/Subscription/Provider/Ping') + + def DeclareCustomPage(self, RemoteEntry, RemoteModule='default'): + """声明本产品定制页的远端入口(幂等覆盖) + + 消费者在「我的订阅」里打开该产品时,GERP 宿主前端按 RemoteEntry 运行时 + 加载远端组件并原生渲染(微服务前端;跨源需该 URL 提供 CORS)。 + + Returns: + dict:{'GroupUUID', 'GroupName', 'RemoteEntry', 'RemoteModule'} + """ + return self._CallProvider( + 'POST', '/API/Subscription/Provider/Page/Save', + Json={'RemoteEntry': RemoteEntry, 'RemoteModule': RemoteModule}, + ) + + def _CallProvider(self, Method, Path, Json=None): + """调用提供者接口并解包 {code, msg, data}(code!=0 抛 SubscriptionClientError)""" + payload = self.Request(Method, Path, Json=Json) + if not isinstance(payload, dict) or payload.get('code') != 0: + msg = (payload or {}).get('msg') if isinstance(payload, dict) else '' + raise SubscriptionClientError(msg or '主服务器返回失败', ResponseBody=payload) + return payload.get('data') + # ── 内部:HTTP 收发 ──────────────────────────────────────────── def _HttpRequest(self, Method, Path, Json=None, Params=None, Headers=None):