mirror of
https://github.com/silenceper/wechat.git
synced 2026-02-04 21:02:25 +08:00
而第三方平台开发者代替公众号使用 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.
微信开放平台
快速入门
服务端处理
wc := wechat.NewWechat()
memory := cache.NewMemory()
cfg := &openplatform.Config{
AppID: "xxx",
AppSecret: "xxx",
Token: "xxx",
EncodingAESKey: "xxx",
Cache: memory,
}
openPlatform := wc.GetOpenPlatform(cfg)
// 传入request和responseWriter
server := openPlatform.GetServer(req, rw)
//设置接收消息的处理方法
server.SetMessageHandler(func(msg message.MixMessage) *message.Reply {
if msg.InfoType == message.InfoTypeVerifyTicket {
componentVerifyTicket, err := openPlatform.SetComponentAccessToken(msg.ComponentVerifyTicket)
if err != nil {
log.Println(err)
return nil
}
//debug
fmt.Println(componentVerifyTicket)
rw.Write([]byte("success"))
return nil
}
//handle other message
//
return nil
})
//处理消息接收以及回复
err := server.Serve()
if err != nil {
fmt.Println(err)
return
}
//发送回复的消息
server.Send()
待授权处理消息
//授权的第三方公众号的appID
appID := "xxx"
openPlatform := wc.GetOpenPlatform(cfg)
openPlatform.GetOfficialAccount(appID)