1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 12:52:27 +08:00

Compare commits

...

11 Commits

Author SHA1 Message Date
1307super
53b0f26688 增加群发消息的预览,群发状态,群发速度 (#332)
* 增加群发消息的预览,群发状态,群发速度

* Update broadcast.go

* Update broadcast.go

* 修复开放平台代公众号jssdk bug
2020-10-24 22:10:01 +08:00
Elvin
430277c947 #330 PreOrder增加H5支付的mweb_url字段 (#335) 2020-10-21 15:08:36 +08:00
NaRro
71e3ddaab3 fix(platform): 修复jsTicket使用了错误的appID的问题. (#331)
而第三方平台开发者代替公众号使用 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.
2020-10-16 11:05:26 +08:00
huangx
0505969439 add CommonToken and MiniProgramMixMessage (#323)
Co-authored-by: huangxiang <huangxiang@didichuxing.com>
2020-08-29 18:50:48 +08:00
silenceper
3014901b48 补全 golint (#322) 2020-08-27 16:33:42 +08:00
huangx
2e191c0a44 feature: 小程序增加客服消息 (#319)
* add miniprogram customer_message

* fix golint comment

* rm unnecessary unmarshal in Send

Co-authored-by: huangxiang <huangxiang@didichuxing.com>
2020-08-27 13:46:36 +08:00
huangx
4c35924b8c feature: 公众号客服消息增加「小程序卡片消息」类型;添加 GetCustomerMessageManager (#320)
* fix officialaccount customer_message

* fix golint comment

Co-authored-by: huangxiang <huangxiang@didichuxing.com>
2020-08-25 19:41:53 +08:00
huangx
ed508654a1 bugfix officialaccount/message/template json non-pointer error (#318)
Co-authored-by: huangxiang <huangxiang@didichuxing.com>
2020-08-17 17:30:04 +08:00
huangx
a18fe5b58a add miniprogram/subscribe listTemplates (#314)
Co-authored-by: huangxiang <huangxiang@didichuxing.com>
2020-08-17 15:29:59 +08:00
huangx
a6eb2eedc3 check errcode in ListUserOpenIDs (#312)
Co-authored-by: huangxiang <huangxiang@didichuxing.com>
2020-08-11 09:46:59 +08:00
NaRro
404d522d09 feat: 增加获取第三方公众号授权链接的接口 (#310) 2020-08-08 16:57:31 +08:00
19 changed files with 388 additions and 27 deletions

View File

@@ -51,3 +51,11 @@ linters-settings:
funlen: funlen:
lines: 66 lines: 66
statements: 40 statements: 40
issues:
include:
- EXC0002 # disable excluding of issues about comments from golint
exclude-rules:
- linters:
- stylecheck
text: "ST1000:"

View File

@@ -1,3 +1,4 @@
//Package config 小程序config配置
package config package config
import ( import (

View File

@@ -0,0 +1,57 @@
package message
import "encoding/xml"
// MsgType 基本消息类型
type MsgType string
// EventType 事件类型
type EventType string
// InfoType 第三方平台授权事件类型
type InfoType string
const (
//MsgTypeText 文本消息
MsgTypeText MsgType = "text"
//MsgTypeImage 图片消息
MsgTypeImage = "image"
//MsgTypeLink 图文链接
MsgTypeLink = "link"
//MsgTypeMiniProgramPage 小程序卡片
MsgTypeMiniProgramPage = "miniprogrampage"
)
// CommonToken 消息中通用的结构
type CommonToken struct {
XMLName xml.Name `xml:"xml"`
ToUserName string `xml:"ToUserName"`
FromUserName string `xml:"FromUserName"`
CreateTime int64 `xml:"CreateTime"`
MsgType MsgType `xml:"MsgType"`
}
// MiniProgramMixMessage 小程序回调的消息结构
type MiniProgramMixMessage struct {
CommonToken
MsgID int64 `xml:"MsgId"`
// 文本消息
Content string `xml:"Content"`
// 图片消息
PicURL string `xml:"PicUrl"`
MediaID string `xml:"MediaId"`
// 小程序卡片消息
Title string `xml:"Title"`
AppID string `xml:"AppId"`
PagePath string `xml:"PagePath"`
ThumbURL string `xml:"ThumbUrl"`
ThumbMediaID string `xml:"ThumbMediaId"`
// 进入会话事件
Event string `xml:"Event"`
SessionFrom string `xml:"SessionFrom"`
}

View File

@@ -0,0 +1,124 @@
package message
import (
"fmt"
"github.com/silenceper/wechat/v2/miniprogram/context"
"github.com/silenceper/wechat/v2/util"
)
const (
customerSendMessage = "https://api.weixin.qq.com/cgi-bin/message/custom/send"
)
//Manager 消息管理者,可以发送消息
type Manager struct {
*context.Context
}
//NewCustomerMessageManager 实例化消息管理者
func NewCustomerMessageManager(context *context.Context) *Manager {
return &Manager{
context,
}
}
//MediaText 文本消息的文字
type MediaText struct {
Content string `json:"content"`
}
//MediaResource 消息使用的临时素材id
type MediaResource struct {
MediaID string `json:"media_id"`
}
//MediaMiniprogrampage 小程序卡片
type MediaMiniprogrampage struct {
Title string `json:"title"`
Appid string `json:"appid"`
Pagepath string `json:"pagepath"`
ThumbMediaID string `json:"thumb_media_id"`
}
// MediaLink 发送图文链接
type MediaLink struct {
Title string `json:"title"`
Description string `json:"description"`
URL string `json:"url"`
ThumbURL string `json:"thumb_url"`
}
//CustomerMessage 客服消息
type CustomerMessage struct {
ToUser string `json:"touser"` //接受者OpenID
Msgtype MsgType `json:"msgtype"` //客服消息类型
Text *MediaText `json:"text,omitempty"` //可选
Image *MediaResource `json:"image,omitempty"` //可选
Link *MediaLink `json:"link,omitempty"` //可选
Miniprogrampage *MediaMiniprogrampage `json:"miniprogrampage,omitempty"` //可选
}
//NewCustomerTextMessage 文本消息结构体构造方法
func NewCustomerTextMessage(toUser, text string) *CustomerMessage {
return &CustomerMessage{
ToUser: toUser,
Msgtype: MsgTypeText,
Text: &MediaText{
Content: text,
},
}
}
//NewCustomerImgMessage 图片消息的构造方法
func NewCustomerImgMessage(toUser, mediaID string) *CustomerMessage {
return &CustomerMessage{
ToUser: toUser,
Msgtype: MsgTypeImage,
Image: &MediaResource{
MediaID: mediaID,
},
}
}
//NewCustomerLinkMessage 图文链接消息的构造方法
func NewCustomerLinkMessage(toUser, title, description, url, thumbURL string) *CustomerMessage {
return &CustomerMessage{
ToUser: toUser,
Msgtype: MsgTypeLink,
Link: &MediaLink{
Title: title,
Description: description,
URL: url,
ThumbURL: thumbURL,
},
}
}
//NewCustomerMiniprogrampageMessage 小程序卡片消息的构造方法
func NewCustomerMiniprogrampageMessage(toUser, title, pagepath, thumbMediaID string) *CustomerMessage {
return &CustomerMessage{
ToUser: toUser,
Msgtype: MsgTypeMiniProgramPage,
Miniprogrampage: &MediaMiniprogrampage{
Title: title,
Pagepath: pagepath,
ThumbMediaID: thumbMediaID,
},
}
}
//Send 发送客服消息
func (manager *Manager) Send(msg *CustomerMessage) error {
accessToken, err := manager.Context.GetAccessToken()
if err != nil {
return err
}
uri := fmt.Sprintf("%s?access_token=%s", customerSendMessage, accessToken)
response, err := util.PostJSON(uri, msg)
if err != nil {
return err
}
return util.DecodeWithCommonError(response, "SendCustomerMessage")
}

View File

@@ -7,6 +7,7 @@ import (
"github.com/silenceper/wechat/v2/miniprogram/config" "github.com/silenceper/wechat/v2/miniprogram/config"
"github.com/silenceper/wechat/v2/miniprogram/context" "github.com/silenceper/wechat/v2/miniprogram/context"
"github.com/silenceper/wechat/v2/miniprogram/encryptor" "github.com/silenceper/wechat/v2/miniprogram/encryptor"
"github.com/silenceper/wechat/v2/miniprogram/message"
"github.com/silenceper/wechat/v2/miniprogram/qrcode" "github.com/silenceper/wechat/v2/miniprogram/qrcode"
"github.com/silenceper/wechat/v2/miniprogram/subscribe" "github.com/silenceper/wechat/v2/miniprogram/subscribe"
"github.com/silenceper/wechat/v2/miniprogram/tcb" "github.com/silenceper/wechat/v2/miniprogram/tcb"
@@ -66,3 +67,8 @@ func (miniProgram *MiniProgram) GetTcb() *tcb.Tcb {
func (miniProgram *MiniProgram) GetSubscribe() *subscribe.Subscribe { func (miniProgram *MiniProgram) GetSubscribe() *subscribe.Subscribe {
return subscribe.NewSubscribe(miniProgram.ctx) return subscribe.NewSubscribe(miniProgram.ctx)
} }
// GetCustomerMessage 客服消息接口
func (miniProgram *MiniProgram) GetCustomerMessage() *message.Manager {
return message.NewCustomerMessageManager(miniProgram.ctx)
}

View File

@@ -11,6 +11,10 @@ const (
//发送订阅消息 //发送订阅消息
//https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html //https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.send.html
subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send" subscribeSendURL = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send"
// 获取当前帐号下的个人模板列表
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getTemplateList.html
getTemplateURL = "https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate"
) )
// Subscribe 订阅消息 // Subscribe 订阅消息
@@ -38,6 +42,21 @@ type DataItem struct {
Value string `json:"value"` Value string `json:"value"`
} }
//TemplateItem template item
type TemplateItem struct {
PriTmplID string `json:"priTmplId"`
Title string `json:"title"`
Content string `json:"content"`
Example string `json:"example"`
Type int64 `json:"type"`
}
//TemplateList template list
type TemplateList struct {
util.CommonError
Data []TemplateItem `json:"data"`
}
// Send 发送订阅消息 // Send 发送订阅消息
func (s *Subscribe) Send(msg *Message) (err error) { func (s *Subscribe) Send(msg *Message) (err error) {
var accessToken string var accessToken string
@@ -52,3 +71,23 @@ func (s *Subscribe) Send(msg *Message) (err error) {
} }
return util.DecodeWithCommonError(response, "Send") return util.DecodeWithCommonError(response, "Send")
} }
//ListTemplates 获取当前帐号下的个人模板列表
// https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/subscribe-message/subscribeMessage.getTemplateList.html
func (s *Subscribe) ListTemplates() (*TemplateList, error) {
accessToken, err := s.GetAccessToken()
if err != nil {
return nil, err
}
uri := fmt.Sprintf("%s?access_token=%s", getTemplateURL, accessToken)
response, err := util.HTTPGet(uri)
if err != nil {
return nil, err
}
templateList := TemplateList{}
err = util.DecodeWithError(response, &templateList, "ListTemplates")
if err != nil {
return nil, err
}
return &templateList, nil
}

View File

@@ -11,6 +11,10 @@ const (
sendURLByTag = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall" sendURLByTag = "https://api.weixin.qq.com/cgi-bin/message/mass/sendall"
sendURLByOpenID = "https://api.weixin.qq.com/cgi-bin/message/mass/send" sendURLByOpenID = "https://api.weixin.qq.com/cgi-bin/message/mass/send"
deleteSendURL = "https://api.weixin.qq.com/cgi-bin/message/mass/delete" deleteSendURL = "https://api.weixin.qq.com/cgi-bin/message/mass/delete"
previewSendURL = "https://api.weixin.qq.com/cgi-bin/message/mass/preview"
massStatusSendURL = "https://api.weixin.qq.com/cgi-bin/message/mass/get"
getSpeedSendURL = "https://api.weixin.qq.com/cgi-bin/message/mass/speed/get"
setSpeedSendURL = "https://api.weixin.qq.com/cgi-bin/message/mass/speed/set"
) )
//MsgType 发送消息类型 //MsgType 发送消息类型
@@ -34,11 +38,12 @@ const (
//Broadcast 群发消息 //Broadcast 群发消息
type Broadcast struct { type Broadcast struct {
*context.Context *context.Context
preview bool
} }
//NewBroadcast new //NewBroadcast new
func NewBroadcast(ctx *context.Context) *Broadcast { func NewBroadcast(ctx *context.Context) *Broadcast {
return &Broadcast{ctx} return &Broadcast{ctx, false}
} }
//User 发送的用户 //User 发送的用户
@@ -52,6 +57,14 @@ type Result struct {
util.CommonError util.CommonError
MsgID int64 `json:"msg_id"` MsgID int64 `json:"msg_id"`
MsgDataID int64 `json:"msg_data_id"` MsgDataID int64 `json:"msg_data_id"`
MsgStatus string `json:"msg_status"`
}
//SpeedResult 群发速度返回结果
type SpeedResult struct {
util.CommonError
Speed int64 `json:"speed"`
RealSpeed int64 `json:"realspeed"`
} }
//sendRequest 发送请求的数据 //sendRequest 发送请求的数据
@@ -250,7 +263,66 @@ func (broadcast *Broadcast) Delete(msgID int64, articleIDx int64) error {
return util.DecodeWithCommonError(data, "Delete") return util.DecodeWithCommonError(data, "Delete")
} }
//TODO 发送预览,群发消息状态,发送速度 // Preview 预览
func (broadcast *Broadcast) Preview() *Broadcast {
broadcast.preview = true
return broadcast
}
// GetMassStatus 获取群发状态
func (broadcast *Broadcast) GetMassStatus(msgID string) (*Result, error) {
ak, err := broadcast.GetAccessToken()
if err != nil {
return nil, err
}
req := map[string]interface{}{
"msg_id": msgID,
}
url := fmt.Sprintf("%s?access_token=%s", massStatusSendURL, ak)
data, err := util.PostJSON(url, req)
if err != nil {
return nil, err
}
res := &Result{}
err = util.DecodeWithError(data, res, "GetMassStatus")
return res, err
}
// GetSpeed 获取群发速度
func (broadcast *Broadcast) GetSpeed() (*SpeedResult, error) {
ak, err := broadcast.GetAccessToken()
if err != nil {
return nil, err
}
req := map[string]interface{}{}
url := fmt.Sprintf("%s?access_token=%s", getSpeedSendURL, ak)
data, err := util.PostJSON(url, req)
if err != nil {
return nil, err
}
res := &SpeedResult{}
err = util.DecodeWithError(data, res, "GetSpeed")
return res, err
}
// SetSpeed 设置群发速度
func (broadcast *Broadcast) SetSpeed(speed int) (*SpeedResult, error) {
ak, err := broadcast.GetAccessToken()
if err != nil {
return nil, err
}
req := map[string]interface{}{
"speed": speed,
}
url := fmt.Sprintf("%s?access_token=%s", setSpeedSendURL, ak)
data, err := util.PostJSON(url, req)
if err != nil {
return nil, err
}
res := &SpeedResult{}
err = util.DecodeWithError(data, res, "SetSpeed")
return res, err
}
func (broadcast *Broadcast) chooseTagOrOpenID(user *User, req *sendRequest) (ret *sendRequest, url string) { func (broadcast *Broadcast) chooseTagOrOpenID(user *User, req *sendRequest) (ret *sendRequest, url string) {
sendURL := "" sendURL := ""
@@ -259,6 +331,11 @@ func (broadcast *Broadcast) chooseTagOrOpenID(user *User, req *sendRequest) (ret
"is_to_all": true, "is_to_all": true,
} }
sendURL = sendURLByTag sendURL = sendURLByTag
} else {
if broadcast.preview {
// 预览
req.ToUser = user.OpenID
sendURL = previewSendURL
} else { } else {
if user.TagID != 0 { if user.TagID != 0 {
req.Filter = map[string]interface{}{ req.Filter = map[string]interface{}{
@@ -272,5 +349,6 @@ func (broadcast *Broadcast) chooseTagOrOpenID(user *User, req *sendRequest) (ret
sendURL = sendURLByOpenID sendURL = sendURLByOpenID
} }
} }
}
return req, sendURL return req, sendURL
} }

View File

@@ -1,3 +1,4 @@
//Package device 设备相关接口
package device package device
import ( import (

View File

@@ -73,6 +73,20 @@ func NewCustomerVoiceMessage(toUser, mediaID string) *CustomerMessage {
} }
} }
//NewCustomerMiniprogrampageMessage 小程序卡片消息的构造方法
func NewCustomerMiniprogrampageMessage(toUser, title, appID, pagePath, thumbMediaID string) *CustomerMessage {
return &CustomerMessage{
ToUser: toUser,
Msgtype: MsgTypeMiniprogrampage,
Miniprogrampage: &MediaMiniprogrampage{
Title: title,
AppID: appID,
Pagepath: pagePath,
ThumbMediaID: thumbMediaID,
},
}
}
//MediaText 文本消息的文字 //MediaText 文本消息的文字
type MediaText struct { type MediaText struct {
Content string `json:"content"` Content string `json:"content"`
@@ -134,7 +148,7 @@ type MediaWxcard struct {
//MediaMiniprogrampage 小程序消息 //MediaMiniprogrampage 小程序消息
type MediaMiniprogrampage struct { type MediaMiniprogrampage struct {
Title string `json:"title"` Title string `json:"title"`
Appid string `json:"appid"` AppID string `json:"appid"`
Pagepath string `json:"pagepath"` Pagepath string `json:"pagepath"`
ThumbMediaID string `json:"thumb_media_id"` ThumbMediaID string `json:"thumb_media_id"`
} }

View File

@@ -24,6 +24,8 @@ const (
MsgTypeVoice = "voice" MsgTypeVoice = "voice"
//MsgTypeVideo 表示视频消息 //MsgTypeVideo 表示视频消息
MsgTypeVideo = "video" MsgTypeVideo = "video"
//MsgTypeMiniprogrampage 表示小程序卡片消息
MsgTypeMiniprogrampage = "miniprogrampage"
//MsgTypeShortVideo 表示短视频消息[限接收] //MsgTypeShortVideo 表示短视频消息[限接收]
MsgTypeShortVideo = "shortvideo" MsgTypeShortVideo = "shortvideo"
//MsgTypeLocation 表示坐标消息[限接收] //MsgTypeLocation 表示坐标消息[限接收]

View File

@@ -106,7 +106,7 @@ func (tpl *Template) List() (templateList []*TemplateItem, err error) {
return return
} }
var res resTemplateList var res resTemplateList
err = util.DecodeWithError(response, res, "ListTemplate") err = util.DecodeWithError(response, &res, "ListTemplate")
if err != nil { if err != nil {
return return
} }

View File

@@ -93,6 +93,11 @@ func (officialAccount *OfficialAccount) GetTemplate() *message.Template {
return message.NewTemplate(officialAccount.ctx) return message.NewTemplate(officialAccount.ctx)
} }
// GetCustomerMessageManager 客服消息接口
func (officialAccount *OfficialAccount) GetCustomerMessageManager() *message.Manager {
return message.NewMessageManager(officialAccount.ctx)
}
// GetDevice 获取智能设备的实例 // GetDevice 获取智能设备的实例
func (officialAccount *OfficialAccount) GetDevice() *device.Device { func (officialAccount *OfficialAccount) GetDevice() *device.Device {
return device.NewDevice(officialAccount.ctx) return device.NewDevice(officialAccount.ctx)

View File

@@ -132,7 +132,7 @@ func (user *User) GetTag() (tags []*TagInfo, err error) {
return result.Tags, nil return result.Tags, nil
} }
//OpenidListByTag 获取标签下粉丝列表 //OpenIDListByTag 获取标签下粉丝列表
func (user *User) OpenIDListByTag(tagID int32, nextOpenID ...string) (userList *TagOpenIDList, err error) { func (user *User) OpenIDListByTag(tagID int32, nextOpenID ...string) (userList *TagOpenIDList, err error) {
accessToken, err := user.GetAccessToken() accessToken, err := user.GetAccessToken()
if err != nil { if err != nil {

View File

@@ -52,6 +52,8 @@ type Info struct {
// OpenidList 用户列表 // OpenidList 用户列表
type OpenidList struct { type OpenidList struct {
util.CommonError
Total int `json:"total"` Total int `json:"total"`
Count int `json:"count"` Count int `json:"count"`
Data struct { Data struct {
@@ -124,13 +126,14 @@ func (user *User) ListUserOpenIDs(nextOpenid ...string) (*OpenidList, error) {
return nil, err return nil, err
} }
userlist := new(OpenidList) userlist := OpenidList{}
err = json.Unmarshal(response, userlist)
err = util.DecodeWithError(response, &userlist, "ListUserOpenIDs")
if err != nil { if err != nil {
return nil, err return nil, err
} }
return userlist, nil return &userlist, nil
} }
// ListAllUserOpenIDs 返回所有用户OpenID列表 // ListAllUserOpenIDs 返回所有用户OpenID列表

View File

@@ -1,8 +1,10 @@
//Package context 开放平台相关context
package context package context
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"net/url"
"time" "time"
"github.com/silenceper/wechat/v2/util" "github.com/silenceper/wechat/v2/util"
@@ -14,6 +16,8 @@ const (
queryAuthURL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%s" queryAuthURL = "https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token=%s"
refreshTokenURL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%s" refreshTokenURL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=%s"
getComponentInfoURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%s" getComponentInfoURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token=%s"
componentLoginURL = "https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=%s&pre_auth_code=%s&redirect_uri=%s&auth_type=%d&biz_appid=%s"
bindComponentURL = "https://mp.weixin.qq.com/safe/bindcomponent?action=bindcomponent&auth_type=%d&no_scan=1&component_appid=%s&pre_auth_code=%s&redirect_uri=%s&biz_appid=%s#wechat_redirect"
//TODO 获取授权方选项信息 //TODO 获取授权方选项信息
//getComponentConfigURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option?component_access_token=%s" //getComponentConfigURL = "https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_option?component_access_token=%s"
//TODO 获取已授权的账号信息 //TODO 获取已授权的账号信息
@@ -86,6 +90,24 @@ func (ctx *Context) GetPreCode() (string, error) {
return ret.PreCode, nil return ret.PreCode, nil
} }
// GetComponentLoginPage 获取第三方公众号授权链接(扫码授权)
func (ctx *Context) GetComponentLoginPage(redirectURI string, authType int, bizAppID string) (string, error) {
code, err := ctx.GetPreCode()
if err != nil {
return "", err
}
return fmt.Sprintf(componentLoginURL, ctx.AppID, code, url.QueryEscape(redirectURI), authType, bizAppID), nil
}
// GetBindComponentURL 获取第三方公众号授权链接(链接跳转,适用移动端)
func (ctx *Context) GetBindComponentURL(redirectURI string, authType int, bizAppID string) (string, error) {
code, err := ctx.GetPreCode()
if err != nil {
return "", err
}
return fmt.Sprintf(bindComponentURL, authType, ctx.AppID, code, url.QueryEscape(redirectURI), bizAppID), nil
}
// ID 微信返回接口中各种类型字段 // ID 微信返回接口中各种类型字段
type ID struct { type ID struct {
ID int `json:"id"` ID int `json:"id"`

View File

@@ -16,10 +16,10 @@ type Js struct {
} }
//NewJs init //NewJs init
func NewJs(context *context.Context) *Js { func NewJs(context *context.Context, appID string) *Js {
js := new(Js) js := new(Js)
js.Context = context js.Context = context
jsTicketHandle := credential.NewDefaultJsTicket(context.AppID, credential.CacheKeyOfficialAccountPrefix, context.Cache) jsTicketHandle := credential.NewDefaultJsTicket(appID, credential.CacheKeyOfficialAccountPrefix, context.Cache)
js.SetJsTicketHandle(jsTicketHandle) js.SetJsTicketHandle(jsTicketHandle)
return js return js
} }

View File

@@ -37,7 +37,7 @@ func (officialAccount *OfficialAccount) PlatformOauth() *oauth.Oauth {
// PlatformJs 平台代获取js-sdk配置 // PlatformJs 平台代获取js-sdk配置
func (officialAccount *OfficialAccount) PlatformJs() *js.Js { func (officialAccount *OfficialAccount) PlatformJs() *js.Js {
return js.NewJs(officialAccount.GetContext()) return js.NewJs(officialAccount.GetContext(), officialAccount.appID)
} }
//DefaultAuthrAccessToken 默认获取授权ak的方法 //DefaultAuthrAccessToken 默认获取授权ak的方法

View File

@@ -63,6 +63,7 @@ type PreOrder struct {
TradeType string `xml:"trade_type,omitempty"` TradeType string `xml:"trade_type,omitempty"`
PrePayID string `xml:"prepay_id,omitempty"` PrePayID string `xml:"prepay_id,omitempty"`
CodeURL string `xml:"code_url,omitempty"` CodeURL string `xml:"code_url,omitempty"`
MWebURL string `xml:"mweb_url,omitempty"`
ErrCode string `xml:"err_code,omitempty"` ErrCode string `xml:"err_code,omitempty"`
ErrCodeDes string `xml:"err_code_des,omitempty"` ErrCodeDes string `xml:"err_code_des,omitempty"`
} }

View File

@@ -2,7 +2,7 @@ package util
import "time" import "time"
//GetCurrTs return current timestamps //GetCurrTS return current timestamps
func GetCurrTS() int64 { func GetCurrTS() int64 {
return time.Now().Unix() return time.Now().Unix()
} }