From 71e3ddaab3c8530f692831cd3fff0c463f6444c5 Mon Sep 17 00:00:00 2001 From: NaRro <501xs05@163.com> Date: Fri, 16 Oct 2020 11:05:26 +0800 Subject: [PATCH] =?UTF-8?q?fix(platform):=20=E4=BF=AE=E5=A4=8DjsTicket?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E4=BA=86=E9=94=99=E8=AF=AF=E7=9A=84appID?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98.=20(#331)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 而第三方平台开发者代替公众号使用 JS SDK 的步骤如下: 1、在申请第三方平台时填写的网页开发域名,将作为旗下授权公众号的 JS SDK 安全域名(详情见“接入前必读”-“申请资料说明”) 2、在第三方平台的网页中正常引入 JS 文件 3、通过 config 接口注入权限验证配置,但在获取 jsapi_ticket 时,不通过公众号的 access_token 来获取,而是通过第三方平台的授权公众号 token(公众号授权给第三方平台后,第三方平台通过“接口说明”中的 api_authorizer_token 接口得到的 token),来获取 jsapi_ticket,然后使用这个 jsapi_ticket 来得到 signature,进行 JS SDK 的配置和开发。**注意 JS SDK 的其他配置中,其他信息均为正常的公众号的资料(而非第三方平台的)**。 4、通过 ready 接口处理成功验证 5、通过 error 接口处理失败验证 fix: #329. --- openplatform/officialaccount/js/js.go | 4 ++-- openplatform/officialaccount/officialaccount.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openplatform/officialaccount/js/js.go b/openplatform/officialaccount/js/js.go index 2dd75a8..160d52f 100644 --- a/openplatform/officialaccount/js/js.go +++ b/openplatform/officialaccount/js/js.go @@ -16,10 +16,10 @@ type Js struct { } //NewJs init -func NewJs(context *context.Context) *Js { +func NewJs(context *context.Context, appID string) *Js { js := new(Js) js.Context = context - jsTicketHandle := credential.NewDefaultJsTicket(context.AppID, credential.CacheKeyOfficialAccountPrefix, context.Cache) + jsTicketHandle := credential.NewDefaultJsTicket(appID, credential.CacheKeyOfficialAccountPrefix, context.Cache) js.SetJsTicketHandle(jsTicketHandle) return js } diff --git a/openplatform/officialaccount/officialaccount.go b/openplatform/officialaccount/officialaccount.go index 882bd88..7729e90 100644 --- a/openplatform/officialaccount/officialaccount.go +++ b/openplatform/officialaccount/officialaccount.go @@ -37,7 +37,7 @@ func (officialAccount *OfficialAccount) PlatformOauth() *oauth.Oauth { // PlatformJs 平台代获取js-sdk配置 func (officialAccount *OfficialAccount) PlatformJs() *js.Js { - return js.NewJs(officialAccount.GetContext()) + return js.NewJs(officialAccount.GetContext(), officialAccount.appID) } //DefaultAuthrAccessToken 默认获取授权ak的方法