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

[feature] Format the code and improve Mini Program authorization to o… (#473)

* [feature] Format the code and improve Mini Program authorization to obtain openid(miniprogram/auth/auth.go Code2Session)

* [feature] CheckEncryptedData (https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/user-info/auth.checkEncryptedData.html)

* upgrade json error

* upgrade json error

Co-authored-by: houseme <houseme@outlook.com>
This commit is contained in:
houseme
2021-09-08 11:03:23 +08:00
committed by GitHub
parent 47adf42208
commit 96c1f98944
90 changed files with 787 additions and 760 deletions

View File

@@ -8,7 +8,7 @@ import (
)
const (
//获取会话状态
// 获取会话状态
serviceStateGetAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/get?access_token=%s"
// 变更会话状态
serviceStateTransAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/trans?access_token=%s"
@@ -28,11 +28,11 @@ type ServiceStateGetSchema struct {
}
// ServiceStateGet 获取会话状态
//0 未处理 新会话接入。可选择1.直接用API自动回复消息。2.放进待接入池等待接待人员接待。3.指定接待人员进行接待
//1 由智能助手接待 可使用API回复消息。可选择转入待接入池或者指定接待人员处理。
//2 待接入池排队中 在待接入池中排队等待接待人员接入。可选择转为指定人员接待
//3 由人工接待 人工接待中。可选择结束会话
//4 已结束 会话已经结束或未开始。不允许变更会话状态,等待用户发起咨询
// 0 未处理 新会话接入。可选择1.直接用API自动回复消息。2.放进待接入池等待接待人员接待。3.指定接待人员进行接待
// 1 由智能助手接待 可使用API回复消息。可选择转入待接入池或者指定接待人员处理。
// 2 待接入池排队中 在待接入池中排队等待接待人员接入。可选择转为指定人员接待
// 3 由人工接待 人工接待中。可选择结束会话
// 4 已结束 会话已经结束或未开始。不允许变更会话状态,等待用户发起咨询
// 注一个微信用户向一个客服帐号发起咨询后在48h内或主动结束会话前包括接待人员手动结束或企业通过API结束会话都算是一次会话
func (r *Client) ServiceStateGet(options ServiceStateGetOptions) (info ServiceStateGetSchema, err error) {
var (

View File

@@ -1,6 +1,7 @@
//go:build linux && cgo && msgaudit
// +build linux,cgo,msgaudit
//Package msgaudit only for linux
// Package msgaudit only for linux
package msgaudit
// #cgo LDFLAGS: -L${SRCDIR}/lib -lWeWorkFinanceSdk_C

View File

@@ -1,6 +1,7 @@
//go:build !linux || !cgo || !msgaudit
// +build !linux !cgo !msgaudit
//Package msgaudit for unsupport platform
// Package msgaudit for unsupport platform
package msgaudit
import (

View File

@@ -9,30 +9,30 @@ import (
"github.com/silenceper/wechat/v2/work/context"
)
//Oauth auth
// Oauth auth
type Oauth struct {
*context.Context
}
var (
//oauthTargetURL 企业微信内跳转地址
// oauthTargetURL 企业微信内跳转地址
oauthTargetURL = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
//oauthUserInfoURL 获取用户信息地址
// oauthUserInfoURL 获取用户信息地址
oauthUserInfoURL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=%s&code=%s"
//oauthQrContentTargetURL 构造独立窗口登录二维码
// oauthQrContentTargetURL 构造独立窗口登录二维码
oauthQrContentTargetURL = "https://open.work.weixin.qq.com/wwopen/sso/qrConnect?appid=%s&agentid=%s&redirect_uri=%s&state=%s"
)
//NewOauth new init oauth
// NewOauth new init oauth
func NewOauth(ctx *context.Context) *Oauth {
return &Oauth{
ctx,
}
}
//GetTargetURL 获取授权地址
// GetTargetURL 获取授权地址
func (ctr *Oauth) GetTargetURL(callbackURL string) string {
//url encode
// url encode
urlStr := url.QueryEscape(callbackURL)
return fmt.Sprintf(
oauthTargetURL,
@@ -41,9 +41,9 @@ func (ctr *Oauth) GetTargetURL(callbackURL string) string {
)
}
//GetQrContentTargetURL 构造独立窗口登录二维码
// GetQrContentTargetURL 构造独立窗口登录二维码
func (ctr *Oauth) GetQrContentTargetURL(callbackURL string) string {
//url encode
// url encode
urlStr := url.QueryEscape(callbackURL)
return fmt.Sprintf(
oauthQrContentTargetURL,
@@ -54,17 +54,17 @@ func (ctr *Oauth) GetQrContentTargetURL(callbackURL string) string {
)
}
//ResUserInfo 返回得用户信息
// ResUserInfo 返回得用户信息
type ResUserInfo struct {
util.CommonError
//当用户为企业成员时返回
// 当用户为企业成员时返回
UserID string `json:"UserId"`
DeviceID string `json:"DeviceId"`
//非企业成员授权时返回
// 非企业成员授权时返回
OpenID string `json:"OpenId"`
}
//UserFromCode 根据code获取用户信息
// UserFromCode 根据code获取用户信息
func (ctr *Oauth) UserFromCode(code string) (result ResUserInfo, err error) {
var accessToken string
accessToken, err = ctr.GetAccessToken()

View File

@@ -14,7 +14,7 @@ type Work struct {
ctx *context.Context
}
//NewWork init work
// NewWork init work
func NewWork(cfg *config.Config) *Work {
defaultAkHandle := credential.NewWorkAccessToken(cfg.CorpID, cfg.CorpSecret, credential.CacheKeyWorkPrefix, cfg.Cache)
ctx := &context.Context{
@@ -24,12 +24,12 @@ func NewWork(cfg *config.Config) *Work {
return &Work{ctx: ctx}
}
//GetContext get Context
// GetContext get Context
func (wk *Work) GetContext() *context.Context {
return wk.ctx
}
//GetOauth get oauth
// GetOauth get oauth
func (wk *Work) GetOauth() *oauth.Oauth {
return oauth.NewOauth(wk.ctx)
}