mirror of
https://github.com/silenceper/wechat.git
synced 2026-03-01 00:35:26 +08:00
71e3ddaab3
而第三方平台开发者代替公众号使用 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.
61 lines
2.0 KiB
Go
61 lines
2.0 KiB
Go
package officialaccount
|
|
|
|
import (
|
|
"github.com/silenceper/wechat/v2/credential"
|
|
"github.com/silenceper/wechat/v2/officialaccount"
|
|
offConfig "github.com/silenceper/wechat/v2/officialaccount/config"
|
|
opContext "github.com/silenceper/wechat/v2/openplatform/context"
|
|
"github.com/silenceper/wechat/v2/openplatform/officialaccount/js"
|
|
"github.com/silenceper/wechat/v2/openplatform/officialaccount/oauth"
|
|
)
|
|
|
|
//OfficialAccount 代公众号实现业务
|
|
type OfficialAccount struct {
|
|
//授权的公众号的appID
|
|
appID string
|
|
*officialaccount.OfficialAccount
|
|
}
|
|
|
|
//NewOfficialAccount 实例化
|
|
//appID :为授权方公众号 APPID,非开放平台第三方平台 APPID
|
|
func NewOfficialAccount(opCtx *opContext.Context, appID string) *OfficialAccount {
|
|
officialAccount := officialaccount.NewOfficialAccount(&offConfig.Config{
|
|
AppID: opCtx.AppID,
|
|
EncodingAESKey: opCtx.EncodingAESKey,
|
|
Token: opCtx.Token,
|
|
Cache: opCtx.Cache,
|
|
})
|
|
//设置获取access_token的函数
|
|
officialAccount.SetAccessTokenHandle(NewDefaultAuthrAccessToken(opCtx, appID))
|
|
return &OfficialAccount{appID: appID, OfficialAccount: officialAccount}
|
|
}
|
|
|
|
// PlatformOauth 平台代发起oauth2网页授权
|
|
func (officialAccount *OfficialAccount) PlatformOauth() *oauth.Oauth {
|
|
return oauth.NewOauth(officialAccount.GetContext())
|
|
}
|
|
|
|
// PlatformJs 平台代获取js-sdk配置
|
|
func (officialAccount *OfficialAccount) PlatformJs() *js.Js {
|
|
return js.NewJs(officialAccount.GetContext(), officialAccount.appID)
|
|
}
|
|
|
|
//DefaultAuthrAccessToken 默认获取授权ak的方法
|
|
type DefaultAuthrAccessToken struct {
|
|
opCtx *opContext.Context
|
|
appID string
|
|
}
|
|
|
|
//NewDefaultAuthrAccessToken New
|
|
func NewDefaultAuthrAccessToken(opCtx *opContext.Context, appID string) credential.AccessTokenHandle {
|
|
return &DefaultAuthrAccessToken{
|
|
opCtx: opCtx,
|
|
appID: appID,
|
|
}
|
|
}
|
|
|
|
//GetAccessToken 获取ak
|
|
func (ak *DefaultAuthrAccessToken) GetAccessToken() (string, error) {
|
|
return ak.opCtx.GetAuthrAccessToken(ak.appID)
|
|
}
|