Skip to content

Commit

Permalink
Merge branch 'v2' of github.com:silenceper/wechat into feature/remove…
Browse files Browse the repository at this point in the history
…-redis
  • Loading branch information
houseme committed Nov 2, 2023
2 parents 7bf2053 + a5e674b commit b797312
Show file tree
Hide file tree
Showing 41 changed files with 1,325 additions and 611 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Go

on:
push:
branches: [ master,release-*,v2 ]
branches: [ master,release-*,v2,feature/** ]
pull_request:
branches: [ master,release-*,v2 ]
branches: [ master,release-*,v2,feature/** ]

jobs:
golangci:
Expand Down
15 changes: 9 additions & 6 deletions credential/default_access_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,22 @@ func (ak *DefaultAccessToken) GetAccessToken() (accessToken string, err error) {
func (ak *DefaultAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) {
// 先从cache中取
accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.appID)
val := ak.cache.Get(accessTokenCacheKey)
if accessToken = val.(string); accessToken != "" {
return

if val := ak.cache.Get(accessTokenCacheKey); val != nil {
if accessToken = val.(string); accessToken != "" {
return
}
}

// 加上lock,是为了防止在并发获取token时,cache刚好失效,导致从微信服务器上获取到不同token
ak.accessTokenLock.Lock()
defer ak.accessTokenLock.Unlock()

// 双检,防止重复从微信服务器获取
val = ak.cache.Get(accessTokenCacheKey)
if accessToken = val.(string); accessToken != "" {
return
if val := ak.cache.Get(accessTokenCacheKey); val != nil {
if accessToken = val.(string); accessToken != "" {
return
}
}

// cache失效,从微信服务器获取
Expand Down
11 changes: 11 additions & 0 deletions doc/api/work.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ host: https://qyapi.weixin.qq.com/
| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|:---------:|------|:----------------------------------------| ---------- | ------------------------------- |----------|
| 获取子部门ID列表 | GET | /cgi-bin/department/simplelist | YES | (r *Client) DepartmentSimpleList| MARKWANG |
| 获取部门列表 | GET | /cgi-bin/department/list | YES | (r *Client) DepartmentList| just5325, ourines |
| 获取部门成员 | GET | /cgi-bin/user/simplelist | YES | (r *Client) UserSimpleList | MARKWANG |
| 获取成员ID列表 | Post | /cgi-bin/user/list_id | YES | (r *Client) UserListId | MARKWANG |



## 素材管理
[官方文档](https://developer.work.weixin.qq.com/document/path/91054)

Expand All @@ -116,5 +118,14 @@ host: https://qyapi.weixin.qq.com/
| ---------------- | -------- | --------------------- | ---------- | -------------------------- | -------- |
| 群机器人发送消息 | POST | /cgi-bin/webhook/send | YES | (r *Client) RobotBroadcast | chcthink |

## 打卡

[官方文档](https://developer.work.weixin.qq.com/document/path/96497)

| 名称 | 请求方式 | URL | 是否已实现 | 使用方法 | 贡献者 |
|----------| -------- | --------------------- | ---------- | -------------------------- |---------|
| 获取打卡日报数据 | POST | /cgi-bin/checkin/getcheckin_daydata | YES | (r *Client) GetDayData | Thinker |
| 获取打卡月报数据 | POST | /cgi-bin/checkin/getcheckin_monthdata | YES | (r *Client) GetMonthData | Thinker |

## 应用管理
TODO
20 changes: 10 additions & 10 deletions domain/openapi/mgnt.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package openapi

import "github.com/silenceper/wechat/v2/util"

// GetAPIQuotaParams 查询API调用额度参数
// GetAPIQuotaParams 查询 API 调用额度参数
type GetAPIQuotaParams struct {
CgiPath string `json:"cgi_path"` // api的请求地址,例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ,也不要漏了"/",否则都会76003的报错
CgiPath string `json:"cgi_path"` // api 的请求地址,例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ,也不要漏了"/",否则都会 76003 的报错
}

// APIQuota API调用额度
// APIQuota API 调用额度
type APIQuota struct {
util.CommonError
Quota struct {
Expand All @@ -17,20 +17,20 @@ type APIQuota struct {
} `json:"quota"` // 详情
}

// GetRidInfoParams 查询rid信息参数
// GetRidInfoParams 查询 rid 信息参数
type GetRidInfoParams struct {
Rid string `json:"rid"` // 调用接口报错返回的rid
Rid string `json:"rid"` // 调用接口报错返回的 rid
}

// RidInfo rid信息
// RidInfo rid 信息
type RidInfo struct {
util.CommonError
Request struct {
InvokeTime int64 `json:"invoke_time"` // 发起请求的时间戳
CostInMs int64 `json:"cost_in_ms"` // 请求毫秒级耗时
RequestURL string `json:"request_url"` // 请求的URL参数
RequestBody string `json:"request_body"` // post请求的请求参数
RequestURL string `json:"request_url"` // 请求的 URL 参数
RequestBody string `json:"request_body"` // post 请求的请求参数
ResponseBody string `json:"response_body"` // 接口请求返回参数
ClientIP string `json:"client_ip"` // 接口请求的客户端ip
} `json:"request"` // 该rid对应的请求详情
ClientIP string `json:"client_ip"` // 接口请求的客户端 ip
} `json:"request"` // 该 rid 对应的请求详情
}
4 changes: 2 additions & 2 deletions miniprogram/message/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const (
MsgTypeMiniProgramPage = "miniprogrampage"
// MsgTypeEvent 事件
MsgTypeEvent MsgType = "event"
// DataTypeXML XML格式数据
// DataTypeXML XML 格式数据
DataTypeXML = "xml"
// DataTypeJSON JSON格式数据
// DataTypeJSON JSON 格式数据
DataTypeJSON = "json"
)

Expand Down
4 changes: 2 additions & 2 deletions miniprogram/message/customer_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type MediaText struct {
Content string `json:"content"`
}

// MediaResource 消息使用的临时素材id
// MediaResource 消息使用的临时素材 id
type MediaResource struct {
MediaID string `json:"media_id"`
}
Expand All @@ -51,7 +51,7 @@ type MediaLink struct {

// CustomerMessage 客服消息
type CustomerMessage struct {
ToUser string `json:"touser"` // 接受者OpenID
ToUser string `json:"touser"` // 接受者 OpenID
Msgtype MsgType `json:"msgtype"` // 客服消息类型
Text *MediaText `json:"text,omitempty"` // 可选
Image *MediaResource `json:"image,omitempty"` // 可选
Expand Down
Loading

0 comments on commit b797312

Please sign in to comment.