1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-23 13:42:25 +08:00

Compare commits

...

13 Commits

Author SHA1 Message Date
Leo
134a7c8f70 Merge d55a170570 into da5067bcb2 2023-10-09 15:27:06 +08:00
曹晶
da5067bcb2 fix(work): fix json Unmarshal Error in GetExternalUserDetail api (#732)
fix json Unmarshal Error, err=json: cannot unmarshal number into Go struct field
WechatChannel.follow_user.wechat_channels.source of type string
2023-10-09 02:02:37 -05:00
houseme
8f10936479 fix: util.DecodeWithError result (#729) 2023-10-07 12:55:11 +08:00
曹晶
9bfebc8a27 fix(work): fix DepartmentGet with commonError is invalid or not struct (#728)
fix DepartmentGet with commonError is invalid or not struct
2023-09-25 14:15:33 +08:00
silenceper
4f6cbc3d59 remove goreleaser (#727) 2023-09-24 20:24:15 +08:00
markwang
49c4cfaf54 fix:GetAccessTokenContext从cache中获取字符窜为空时,从微信服务器获取 (#721)
Co-authored-by: markwang <www.wang61@qq.com>
2023-09-24 10:47:43 +08:00
曹晶
ead8a6fadb fix(work): fix UserGet api error userid not found (#723)
fix UserGet api error userid not found
2023-09-24 10:46:38 +08:00
曹晶
ae40639b56 feat(work): add DepartmentGet api (#718)
get single department detail
2023-09-24 10:46:18 +08:00
曹晶
8bb145155e fix(work): fix GroupChatMember struct without State (#717)
fix GroupChatMember struct without State in joinway config
2023-09-24 10:45:43 +08:00
febelery
85bf989242 feat: 添加发放红包接口 (#726)
* feat: 添加发放红包接口

* feat: 添加发放红包接口

* chore: golang ci lint

---------

Co-authored-by: ross <ross@ross.ross>
2023-09-24 10:44:18 +08:00
Feng
b4f2d1793c feat: Add Checkin (#719)
* feat: Add Checkin

- Implement 'getcheckindata' API

* refactor: Change variable names

* refactor: Change struct name
2023-09-24 10:43:41 +08:00
曹晶
4a2c44c7c8 Feature/upload attachment (#720)
* feat(work): add UploadAttachment API

add UploadAttachment API

* feat(work): add UploadAttachment API

add UploadAttachment API

* feat(work): add UploadAttachment API

add UploadAttachment API
2023-09-24 10:43:11 +08:00
yuan
d55a170570 fix: memory 并发读写问题 2023-05-20 15:45:24 +08:00
17 changed files with 366 additions and 125 deletions

View File

@@ -1,29 +0,0 @@
name: goreleaser
on:
push:
tags:
- '*'
jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
-
name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.16
-
name: Run GoReleaser
uses: goreleaser/goreleaser-action@v4
with:
version: latest
args: release --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@@ -1,29 +0,0 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod download
# you may remove this if you don't need go generate
- go generate ./...
builds:
- skip: true
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'

6
cache/memory.go vendored
View File

@@ -26,25 +26,31 @@ func NewMemory() *Memory {
// Get return cached value // Get return cached value
func (mem *Memory) Get(key string) interface{} { func (mem *Memory) Get(key string) interface{} {
mem.Lock()
if ret, ok := mem.data[key]; ok { if ret, ok := mem.data[key]; ok {
mem.Unlock()
if ret.Expired.Before(time.Now()) { if ret.Expired.Before(time.Now()) {
mem.deleteKey(key) mem.deleteKey(key)
return nil return nil
} }
return ret.Data return ret.Data
} }
mem.Unlock()
return nil return nil
} }
// IsExist check value exists in memcache. // IsExist check value exists in memcache.
func (mem *Memory) IsExist(key string) bool { func (mem *Memory) IsExist(key string) bool {
mem.Lock()
if ret, ok := mem.data[key]; ok { if ret, ok := mem.data[key]; ok {
mem.Unlock()
if ret.Expired.Before(time.Now()) { if ret.Expired.Before(time.Now()) {
mem.deleteKey(key) mem.deleteKey(key)
return false return false
} }
return true return true
} }
mem.Unlock()
return false return false
} }

View File

@@ -66,8 +66,9 @@ func (ak *DefaultAccessToken) GetAccessToken() (accessToken string, err error) {
func (ak *DefaultAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) { func (ak *DefaultAccessToken) GetAccessTokenContext(ctx context.Context) (accessToken string, err error) {
// 先从cache中取 // 先从cache中取
accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.appID) accessTokenCacheKey := fmt.Sprintf("%s_access_token_%s", ak.cacheKeyPrefix, ak.appID)
if val := ak.cache.Get(accessTokenCacheKey); val != nil { val := ak.cache.Get(accessTokenCacheKey)
return val.(string), nil if accessToken = val.(string); accessToken != "" {
return
} }
// 加上lock是为了防止在并发获取token时cache刚好失效导致从微信服务器上获取到不同token // 加上lock是为了防止在并发获取token时cache刚好失效导致从微信服务器上获取到不同token
@@ -75,8 +76,9 @@ func (ak *DefaultAccessToken) GetAccessTokenContext(ctx context.Context) (access
defer ak.accessTokenLock.Unlock() defer ak.accessTokenLock.Unlock()
// 双检,防止重复从微信服务器获取 // 双检,防止重复从微信服务器获取
if val := ak.cache.Get(accessTokenCacheKey); val != nil { val = ak.cache.Get(accessTokenCacheKey)
return val.(string), nil if accessToken = val.(string); accessToken != "" {
return
} }
// cache失效从微信服务器获取 // cache失效从微信服务器获取

View File

@@ -180,7 +180,7 @@ type MediaInfo struct {
CreateTime int64 `json:"create_time"` // 上传时间,时间戳。 CreateTime int64 `json:"create_time"` // 上传时间,时间戳。
ExpireTime int64 `json:"expire_time"` // 过期时间,时间戳。 ExpireTime int64 `json:"expire_time"` // 过期时间,时间戳。
DramaID int64 `json:"drama_id"` // 所属剧目 id。 DramaID int64 `json:"drama_id"` // 所属剧目 id。
FileSize string `json:"file_size"` // 媒资文件大小,单位:字节。 FileSize int64 `json:"file_size"` // 媒资文件大小,单位:字节。
Duration int64 `json:"duration"` // 播放时长,单位:秒。 Duration int64 `json:"duration"` // 播放时长,单位:秒。
Name string `json:"name"` // 媒资文件名。 Name string `json:"name"` // 媒资文件名。
Description string `json:"description"` // 描述。 Description string `json:"description"` // 描述。

View File

@@ -27,7 +27,7 @@ import (
) )
// SingleFileUpload 单文件上传 // SingleFileUpload 单文件上传
func (s *MiniDrama) SingleFileUpload(ctx context.Context, in *SingleFileUploadRequest) (out *SingleFileUploadResponse, err error) { func (s *MiniDrama) SingleFileUpload(ctx context.Context, in *SingleFileUploadRequest) (out SingleFileUploadResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, singleFileUpload); err != nil { if address, err = s.requestAddress(ctx, singleFileUpload); err != nil {
return return
@@ -76,12 +76,12 @@ func (s *MiniDrama) SingleFileUpload(ctx context.Context, in *SingleFileUploadRe
return return
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "SingleFileUpload") err = util.DecodeWithError(response, &out, "SingleFileUpload")
return return
} }
// PullUpload 拉取上传 // PullUpload 拉取上传
func (s *MiniDrama) PullUpload(ctx context.Context, in *PullUploadRequest) (out *PullUploadResponse, err error) { func (s *MiniDrama) PullUpload(ctx context.Context, in *PullUploadRequest) (out PullUploadResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, pullUpload); err != nil { if address, err = s.requestAddress(ctx, pullUpload); err != nil {
return return
@@ -92,12 +92,12 @@ func (s *MiniDrama) PullUpload(ctx context.Context, in *PullUploadRequest) (out
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "PullUpload") err = util.DecodeWithError(response, &out, "PullUpload")
return return
} }
// GetTask 查询任务状态 // GetTask 查询任务状态
func (s *MiniDrama) GetTask(ctx context.Context, in *GetTaskRequest) (out *GetTaskResponse, err error) { func (s *MiniDrama) GetTask(ctx context.Context, in *GetTaskRequest) (out GetTaskResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, getTask); err != nil { if address, err = s.requestAddress(ctx, getTask); err != nil {
return return
@@ -109,12 +109,12 @@ func (s *MiniDrama) GetTask(ctx context.Context, in *GetTaskRequest) (out *GetTa
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "GetTask") err = util.DecodeWithError(response, &out, "GetTask")
return return
} }
// ApplyUpload 申请分片上传 // ApplyUpload 申请分片上传
func (s *MiniDrama) ApplyUpload(ctx context.Context, in *ApplyUploadRequest) (out *ApplyUploadResponse, err error) { func (s *MiniDrama) ApplyUpload(ctx context.Context, in *ApplyUploadRequest) (out ApplyUploadResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, applyUpload); err != nil { if address, err = s.requestAddress(ctx, applyUpload); err != nil {
return return
@@ -126,13 +126,13 @@ func (s *MiniDrama) ApplyUpload(ctx context.Context, in *ApplyUploadRequest) (ou
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "ApplyUpload") err = util.DecodeWithError(response, &out, "ApplyUpload")
return return
} }
// UploadPart 上传分片 // UploadPart 上传分片
// Content-Type 需要指定为 multipart/form-data; boundary=<delimiter><箭头括号>表示必须替换为有效值的变量。 // Content-Type 需要指定为 multipart/form-data; boundary=<delimiter><箭头括号>表示必须替换为有效值的变量。
func (s *MiniDrama) UploadPart(ctx context.Context, in *UploadPartRequest) (out *UploadPartResponse, err error) { func (s *MiniDrama) UploadPart(ctx context.Context, in *UploadPartRequest) (out UploadPartResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, uploadPart); err != nil { if address, err = s.requestAddress(ctx, uploadPart); err != nil {
return return
@@ -165,12 +165,12 @@ func (s *MiniDrama) UploadPart(ctx context.Context, in *UploadPartRequest) (out
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "UploadPart") err = util.DecodeWithError(response, &out, "UploadPart")
return return
} }
// CommitUpload 确认上传 // CommitUpload 确认上传
func (s *MiniDrama) CommitUpload(ctx context.Context, in *CommitUploadRequest) (out *CommitUploadResponse, err error) { func (s *MiniDrama) CommitUpload(ctx context.Context, in *CommitUploadRequest) (out CommitUploadResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, commitUpload); err != nil { if address, err = s.requestAddress(ctx, commitUpload); err != nil {
return return
@@ -182,12 +182,12 @@ func (s *MiniDrama) CommitUpload(ctx context.Context, in *CommitUploadRequest) (
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "CommitUpload") err = util.DecodeWithError(response, &out, "CommitUpload")
return return
} }
// ListMedia 获取媒体列表 // ListMedia 获取媒体列表
func (s *MiniDrama) ListMedia(ctx context.Context, in *ListMediaRequest) (out *ListMediaResponse, err error) { func (s *MiniDrama) ListMedia(ctx context.Context, in *ListMediaRequest) (out ListMediaResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, listMedia); err != nil { if address, err = s.requestAddress(ctx, listMedia); err != nil {
return return
@@ -199,12 +199,12 @@ func (s *MiniDrama) ListMedia(ctx context.Context, in *ListMediaRequest) (out *L
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "ListMedia") err = util.DecodeWithError(response, &out, "ListMedia")
return return
} }
// GetMedia 获取媒资详细信息 // GetMedia 获取媒资详细信息
func (s *MiniDrama) GetMedia(ctx context.Context, in *GetMediaRequest) (out *GetMediaResponse, err error) { func (s *MiniDrama) GetMedia(ctx context.Context, in *GetMediaRequest) (out GetMediaResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, getMedia); err != nil { if address, err = s.requestAddress(ctx, getMedia); err != nil {
return return
@@ -216,12 +216,12 @@ func (s *MiniDrama) GetMedia(ctx context.Context, in *GetMediaRequest) (out *Get
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "GetMedia") err = util.DecodeWithError(response, &out, "GetMedia")
return return
} }
// GetMediaLink 获取媒资播放链接 // GetMediaLink 获取媒资播放链接
func (s *MiniDrama) GetMediaLink(ctx context.Context, in *GetMediaLinkRequest) (out *GetMediaLinkResponse, err error) { func (s *MiniDrama) GetMediaLink(ctx context.Context, in *GetMediaLinkRequest) (out GetMediaLinkResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, getMediaLink); err != nil { if address, err = s.requestAddress(ctx, getMediaLink); err != nil {
return return
@@ -233,12 +233,12 @@ func (s *MiniDrama) GetMediaLink(ctx context.Context, in *GetMediaLinkRequest) (
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "GetMediaLink") err = util.DecodeWithError(response, &out, "GetMediaLink")
return return
} }
// DeleteMedia 删除媒体 // DeleteMedia 删除媒体
func (s *MiniDrama) DeleteMedia(ctx context.Context, in *DeleteMediaRequest) (out *DeleteMediaResponse, err error) { func (s *MiniDrama) DeleteMedia(ctx context.Context, in *DeleteMediaRequest) (out DeleteMediaResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, deleteMedia); err != nil { if address, err = s.requestAddress(ctx, deleteMedia); err != nil {
return return
@@ -250,12 +250,12 @@ func (s *MiniDrama) DeleteMedia(ctx context.Context, in *DeleteMediaRequest) (ou
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "DeleteMedia") err = util.DecodeWithError(response, &out, "DeleteMedia")
return return
} }
// AuditDrama 审核剧本 // AuditDrama 审核剧本
func (s *MiniDrama) AuditDrama(ctx context.Context, in *AuditDramaRequest) (out *AuditDramaResponse, err error) { func (s *MiniDrama) AuditDrama(ctx context.Context, in *AuditDramaRequest) (out AuditDramaResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, auditDrama); err != nil { if address, err = s.requestAddress(ctx, auditDrama); err != nil {
return return
@@ -267,12 +267,12 @@ func (s *MiniDrama) AuditDrama(ctx context.Context, in *AuditDramaRequest) (out
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "AuditDrama") err = util.DecodeWithError(response, &out, "AuditDrama")
return return
} }
// ListDramas 获取剧目列表 // ListDramas 获取剧目列表
func (s *MiniDrama) ListDramas(ctx context.Context, in *ListDramasRequest) (out *ListDramasResponse, err error) { func (s *MiniDrama) ListDramas(ctx context.Context, in *ListDramasRequest) (out ListDramasResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, listDramas); err != nil { if address, err = s.requestAddress(ctx, listDramas); err != nil {
return return
@@ -284,12 +284,12 @@ func (s *MiniDrama) ListDramas(ctx context.Context, in *ListDramasRequest) (out
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "ListDramas") err = util.DecodeWithError(response, &out, "ListDramas")
return return
} }
// GetDrama 获取剧目信息 // GetDrama 获取剧目信息
func (s *MiniDrama) GetDrama(ctx context.Context, in *GetDramaRequest) (out *GetDramaResponse, err error) { func (s *MiniDrama) GetDrama(ctx context.Context, in *GetDramaRequest) (out GetDramaResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, getDrama); err != nil { if address, err = s.requestAddress(ctx, getDrama); err != nil {
return return
@@ -300,12 +300,12 @@ func (s *MiniDrama) GetDrama(ctx context.Context, in *GetDramaRequest) (out *Get
return return
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "GetDrama") err = util.DecodeWithError(response, &out, "GetDrama")
return return
} }
// GetCdnUsageData 查询 CDN 用量数据 // GetCdnUsageData 查询 CDN 用量数据
func (s *MiniDrama) GetCdnUsageData(ctx context.Context, in *GetCdnUsageDataRequest) (out *GetCdnUsageDataResponse, err error) { func (s *MiniDrama) GetCdnUsageData(ctx context.Context, in *GetCdnUsageDataRequest) (out GetCdnUsageDataResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, getCdnUsageData); err != nil { if address, err = s.requestAddress(ctx, getCdnUsageData); err != nil {
return return
@@ -316,12 +316,12 @@ func (s *MiniDrama) GetCdnUsageData(ctx context.Context, in *GetCdnUsageDataRequ
return return
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "GetCdnUsageData") err = util.DecodeWithError(response, &out, "GetCdnUsageData")
return return
} }
// GetCdnLogs 查询 CDN 日志 // GetCdnLogs 查询 CDN 日志
func (s *MiniDrama) GetCdnLogs(ctx context.Context, in *GetCdnLogsRequest) (out *GetCdnLogsResponse, err error) { func (s *MiniDrama) GetCdnLogs(ctx context.Context, in *GetCdnLogsRequest) (out GetCdnLogsResponse, err error) {
var address string var address string
if address, err = s.requestAddress(ctx, getCdnLogs); err != nil { if address, err = s.requestAddress(ctx, getCdnLogs); err != nil {
return return
@@ -332,7 +332,7 @@ func (s *MiniDrama) GetCdnLogs(ctx context.Context, in *GetCdnLogsRequest) (out
return return
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "GetCdnLogs") err = util.DecodeWithError(response, &out, "GetCdnLogs")
return return
} }

View File

@@ -37,7 +37,7 @@ func (s *VirtualPayment) SetSessionKey(sessionKey string) {
} }
// QueryUserBalance 查询虚拟支付余额 // QueryUserBalance 查询虚拟支付余额
func (s *VirtualPayment) QueryUserBalance(ctx context.Context, in *QueryUserBalanceRequest) (out *QueryUserBalanceResponse, err error) { func (s *VirtualPayment) QueryUserBalance(ctx context.Context, in *QueryUserBalanceRequest) (out QueryUserBalanceResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -60,12 +60,12 @@ func (s *VirtualPayment) QueryUserBalance(ctx context.Context, in *QueryUserBala
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "QueryUserBalance") err = util.DecodeWithError(response, &out, "QueryUserBalance")
return return
} }
// CurrencyPay currency pay 扣减代币(一般用于代币支付) // CurrencyPay currency pay 扣减代币(一般用于代币支付)
func (s *VirtualPayment) CurrencyPay(ctx context.Context, in *CurrencyPayRequest) (out *CurrencyPayResponse, err error) { func (s *VirtualPayment) CurrencyPay(ctx context.Context, in *CurrencyPayRequest) (out CurrencyPayResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -88,12 +88,12 @@ func (s *VirtualPayment) CurrencyPay(ctx context.Context, in *CurrencyPayRequest
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "CurrencyPay") err = util.DecodeWithError(response, &out, "CurrencyPay")
return return
} }
// QueryOrder 查询创建的订单(现金单,非代币单) // QueryOrder 查询创建的订单(现金单,非代币单)
func (s *VirtualPayment) QueryOrder(ctx context.Context, in *QueryOrderRequest) (out *QueryOrderResponse, err error) { func (s *VirtualPayment) QueryOrder(ctx context.Context, in *QueryOrderRequest) (out QueryOrderResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -116,12 +116,12 @@ func (s *VirtualPayment) QueryOrder(ctx context.Context, in *QueryOrderRequest)
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "QueryOrder") err = util.DecodeWithError(response, &out, "QueryOrder")
return return
} }
// CancelCurrencyPay 取消订单 代币支付退款 (currency_pay 接口的逆操作) // CancelCurrencyPay 取消订单 代币支付退款 (currency_pay 接口的逆操作)
func (s *VirtualPayment) CancelCurrencyPay(ctx context.Context, in *CancelCurrencyPayRequest) (out *CancelCurrencyPayResponse, err error) { func (s *VirtualPayment) CancelCurrencyPay(ctx context.Context, in *CancelCurrencyPayRequest) (out CancelCurrencyPayResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -144,13 +144,13 @@ func (s *VirtualPayment) CancelCurrencyPay(ctx context.Context, in *CancelCurren
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "CancelCurrencyPay") err = util.DecodeWithError(response, &out, "CancelCurrencyPay")
return return
} }
// NotifyProvideGoods 通知发货 // NotifyProvideGoods 通知发货
// 通知已经发货完成(只能通知现金单),正常通过 xpay_goods_deliver_notify 消息推送返回成功就不需要调用这个 api 接口。这个接口用于异常情况推送不成功时手动将单改成已发货状态 // 通知已经发货完成(只能通知现金单),正常通过 xpay_goods_deliver_notify 消息推送返回成功就不需要调用这个 api 接口。这个接口用于异常情况推送不成功时手动将单改成已发货状态
func (s *VirtualPayment) NotifyProvideGoods(ctx context.Context, in *NotifyProvideGoodsRequest) (out *NotifyProvideGoodsResponse, err error) { func (s *VirtualPayment) NotifyProvideGoods(ctx context.Context, in *NotifyProvideGoodsRequest) (out NotifyProvideGoodsResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -174,12 +174,12 @@ func (s *VirtualPayment) NotifyProvideGoods(ctx context.Context, in *NotifyProvi
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "NotifyProvideGoods") err = util.DecodeWithError(response, &out, "NotifyProvideGoods")
return return
} }
// PresentCurrency 代币赠送接口,由于目前不支付按单号查赠送单的功能,所以当需要赠送的时候可以一直重试到返回 0 或者返回 268490004重复操作为止 // PresentCurrency 代币赠送接口,由于目前不支付按单号查赠送单的功能,所以当需要赠送的时候可以一直重试到返回 0 或者返回 268490004重复操作为止
func (s *VirtualPayment) PresentCurrency(ctx context.Context, in *PresentCurrencyRequest) (out *PresentCurrencyResponse, err error) { func (s *VirtualPayment) PresentCurrency(ctx context.Context, in *PresentCurrencyRequest) (out PresentCurrencyResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -203,12 +203,12 @@ func (s *VirtualPayment) PresentCurrency(ctx context.Context, in *PresentCurrenc
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "PresentCurrency") err = util.DecodeWithError(response, &out, "PresentCurrency")
return return
} }
// DownloadBill 下载订单交易账单 // DownloadBill 下载订单交易账单
func (s *VirtualPayment) DownloadBill(ctx context.Context, in *DownloadBillRequest) (out *DownloadBillResponse, err error) { func (s *VirtualPayment) DownloadBill(ctx context.Context, in *DownloadBillRequest) (out DownloadBillResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -232,12 +232,12 @@ func (s *VirtualPayment) DownloadBill(ctx context.Context, in *DownloadBillReque
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "DownloadBill") err = util.DecodeWithError(response, &out, "DownloadBill")
return return
} }
// RefundOrder 退款 对使用 jsapi 接口下的单进行退款 // RefundOrder 退款 对使用 jsapi 接口下的单进行退款
func (s *VirtualPayment) RefundOrder(ctx context.Context, in *RefundOrderRequest) (out *RefundOrderResponse, err error) { func (s *VirtualPayment) RefundOrder(ctx context.Context, in *RefundOrderRequest) (out RefundOrderResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -261,12 +261,12 @@ func (s *VirtualPayment) RefundOrder(ctx context.Context, in *RefundOrderRequest
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "RefundOrder") err = util.DecodeWithError(response, &out, "RefundOrder")
return return
} }
// CreateWithdrawOrder 创建提现单 // CreateWithdrawOrder 创建提现单
func (s *VirtualPayment) CreateWithdrawOrder(ctx context.Context, in *CreateWithdrawOrderRequest) (out *CreateWithdrawOrderResponse, err error) { func (s *VirtualPayment) CreateWithdrawOrder(ctx context.Context, in *CreateWithdrawOrderRequest) (out CreateWithdrawOrderResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -290,12 +290,12 @@ func (s *VirtualPayment) CreateWithdrawOrder(ctx context.Context, in *CreateWith
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "CreateWithdrawOrder") err = util.DecodeWithError(response, &out, "CreateWithdrawOrder")
return return
} }
// QueryWithdrawOrder 查询提现单 // QueryWithdrawOrder 查询提现单
func (s *VirtualPayment) QueryWithdrawOrder(ctx context.Context, in *QueryWithdrawOrderRequest) (out *QueryWithdrawOrderResponse, err error) { func (s *VirtualPayment) QueryWithdrawOrder(ctx context.Context, in *QueryWithdrawOrderRequest) (out QueryWithdrawOrderResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -319,12 +319,12 @@ func (s *VirtualPayment) QueryWithdrawOrder(ctx context.Context, in *QueryWithdr
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "QueryWithdrawOrder") err = util.DecodeWithError(response, &out, "QueryWithdrawOrder")
return return
} }
// StartUploadGoods 开始上传商品 // StartUploadGoods 开始上传商品
func (s *VirtualPayment) StartUploadGoods(ctx context.Context, in *StartUploadGoodsRequest) (out *StartUploadGoodsResponse, err error) { func (s *VirtualPayment) StartUploadGoods(ctx context.Context, in *StartUploadGoodsRequest) (out StartUploadGoodsResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -348,12 +348,12 @@ func (s *VirtualPayment) StartUploadGoods(ctx context.Context, in *StartUploadGo
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "StartUploadGoods") err = util.DecodeWithError(response, &out, "StartUploadGoods")
return return
} }
// QueryUploadGoods 查询上传商品 // QueryUploadGoods 查询上传商品
func (s *VirtualPayment) QueryUploadGoods(ctx context.Context, in *QueryUploadGoodsRequest) (out *QueryUploadGoodsResponse, err error) { func (s *VirtualPayment) QueryUploadGoods(ctx context.Context, in *QueryUploadGoodsRequest) (out QueryUploadGoodsResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -377,12 +377,12 @@ func (s *VirtualPayment) QueryUploadGoods(ctx context.Context, in *QueryUploadGo
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "QueryUploadGoods") err = util.DecodeWithError(response, &out, "QueryUploadGoods")
return return
} }
// StartPublishGoods 开始发布商品 // StartPublishGoods 开始发布商品
func (s *VirtualPayment) StartPublishGoods(ctx context.Context, in *StartPublishGoodsRequest) (out *StartPublishGoodsResponse, err error) { func (s *VirtualPayment) StartPublishGoods(ctx context.Context, in *StartPublishGoodsRequest) (out StartPublishGoodsResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -406,12 +406,12 @@ func (s *VirtualPayment) StartPublishGoods(ctx context.Context, in *StartPublish
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "StartPublishGoods") err = util.DecodeWithError(response, &out, "StartPublishGoods")
return return
} }
// QueryPublishGoods 查询发布商品 // QueryPublishGoods 查询发布商品
func (s *VirtualPayment) QueryPublishGoods(ctx context.Context, in *QueryPublishGoodsRequest) (out *QueryPublishGoodsResponse, err error) { func (s *VirtualPayment) QueryPublishGoods(ctx context.Context, in *QueryPublishGoodsRequest) (out QueryPublishGoodsResponse, err error) {
var jsonByte []byte var jsonByte []byte
if jsonByte, err = json.Marshal(in); err != nil { if jsonByte, err = json.Marshal(in); err != nil {
return return
@@ -435,7 +435,7 @@ func (s *VirtualPayment) QueryPublishGoods(ctx context.Context, in *QueryPublish
} }
// 使用通用方法返回错误 // 使用通用方法返回错误
err = util.DecodeWithError(response, out, "QueryPublishGoods") err = util.DecodeWithError(response, &out, "QueryPublishGoods")
return return
} }

View File

@@ -4,6 +4,7 @@ import (
"github.com/silenceper/wechat/v2/pay/config" "github.com/silenceper/wechat/v2/pay/config"
"github.com/silenceper/wechat/v2/pay/notify" "github.com/silenceper/wechat/v2/pay/notify"
"github.com/silenceper/wechat/v2/pay/order" "github.com/silenceper/wechat/v2/pay/order"
"github.com/silenceper/wechat/v2/pay/redpacket"
"github.com/silenceper/wechat/v2/pay/refund" "github.com/silenceper/wechat/v2/pay/refund"
"github.com/silenceper/wechat/v2/pay/transfer" "github.com/silenceper/wechat/v2/pay/transfer"
) )
@@ -37,3 +38,8 @@ func (pay *Pay) GetRefund() *refund.Refund {
func (pay *Pay) GetTransfer() *transfer.Transfer { func (pay *Pay) GetTransfer() *transfer.Transfer {
return transfer.NewTransfer(pay.cfg) return transfer.NewTransfer(pay.cfg)
} }
// GetRedpacket 红包
func (pay *Pay) GetRedpacket() *redpacket.Redpacket {
return redpacket.NewRedpacket(pay.cfg)
}

131
pay/redpacket/redpacket.go Normal file
View File

@@ -0,0 +1,131 @@
package redpacket
import (
"encoding/xml"
"fmt"
"strconv"
"github.com/silenceper/wechat/v2/pay/config"
"github.com/silenceper/wechat/v2/util"
)
// redpacketGateway 发放红包接口
// https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=13_4&index=3
var redpacketGateway = "https://api.mch.weixin.qq.com/mmpaymkttransfers/sendredpack"
// Redpacket struct extends context
type Redpacket struct {
*config.Config
}
// NewRedpacket return an instance of Redpacket package
func NewRedpacket(cfg *config.Config) *Redpacket {
return &Redpacket{cfg}
}
// Params 调用参数
type Params struct {
MchBillno string // 商户订单号
SendName string // 商户名称
ReOpenID string
TotalAmount int
TotalNum int
Wishing string
ClientIP string
ActName string
Remark string
RootCa string // ca证书
}
// request 接口请求参数
type request struct {
NonceStr string `xml:"nonce_str"`
Sign string `xml:"sign"`
MchID string `xml:"mch_id"`
MchBillno string `xml:"mch_billno"`
Wxappid string `xml:"wxappid"`
SendName string `xml:"send_name"`
ReOpenID string `xml:"re_openid"`
TotalAmount int `xml:"total_amount"`
TotalNum int `xml:"total_num"`
Wishing string `xml:"wishing"`
ClientIP string `xml:"client_ip"`
ActName string `xml:"act_name"`
Remark string `xml:"remark"`
}
// Response 接口返回
type Response struct {
ReturnCode string `xml:"return_code"`
ReturnMsg string `xml:"return_msg"`
ResultCode string `xml:"result_code,omitempty"`
ErrCode string `xml:"err_code,omitempty"`
ErrCodeDes string `xml:"err_code_des,omitempty"`
MchBillno string `xml:"mch_billno,omitempty"`
MchID string `xml:"mch_id,omitempty"`
Wxappid string `xml:"wxappid"`
ReOpenID string `xml:"re_openid"`
TotalAmount int `xml:"total_amount"`
SendListid string `xml:"send_listid"`
}
// SendRedpacket 发放红包
func (redpacket *Redpacket) SendRedpacket(p *Params) (rsp *Response, err error) {
nonceStr := util.RandomStr(32)
param := make(map[string]string)
param["nonce_str"] = nonceStr
param["mch_id"] = redpacket.MchID
param["wxappid"] = redpacket.AppID
param["mch_billno"] = p.MchBillno
param["send_name"] = p.SendName
param["re_openid"] = p.ReOpenID
param["total_amount"] = strconv.Itoa(p.TotalAmount)
param["total_num"] = strconv.Itoa(p.TotalNum)
param["wishing"] = p.Wishing
param["client_ip"] = p.ClientIP
param["act_name"] = p.ActName
param["remark"] = p.Remark
//param["scene_id"] = "PRODUCT_2"
sign, err := util.ParamSign(param, redpacket.Key)
if err != nil {
return
}
req := request{
NonceStr: nonceStr,
Sign: sign,
MchID: redpacket.MchID,
Wxappid: redpacket.AppID,
MchBillno: p.MchBillno,
SendName: p.SendName,
ReOpenID: p.ReOpenID,
TotalAmount: p.TotalAmount,
TotalNum: p.TotalNum,
Wishing: p.Wishing,
ClientIP: p.ClientIP,
ActName: p.ActName,
Remark: p.Remark,
}
rawRet, err := util.PostXMLWithTLS(redpacketGateway, req, p.RootCa, redpacket.MchID)
if err != nil {
return
}
err = xml.Unmarshal(rawRet, &rsp)
if err != nil {
return
}
if rsp.ReturnCode == "SUCCESS" {
if rsp.ResultCode == "SUCCESS" {
err = nil
return
}
err = fmt.Errorf("send redpacket error, errcode=%s,errmsg=%s", rsp.ErrCode, rsp.ErrCodeDes)
return
}
err = fmt.Errorf("[msg : xmlUnmarshalError] [rawReturn : %s] [sign : %s]", string(rawRet), sign)
return
}

View File

@@ -13,6 +13,8 @@ const (
departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d" departmentSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/simplelist?access_token=%s&id=%d"
// departmentListURL 获取部门列表 // departmentListURL 获取部门列表
departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s" departmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token=%s"
// departmentGetURL 获取单个部门详情 https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=ACCESS_TOKEN&id=ID
departmentGetURL = "https://qyapi.weixin.qq.com/cgi-bin/department/get?access_token=%s&id=%d"
) )
type ( type (
@@ -56,6 +58,11 @@ type (
ParentID int `json:"parentid"` // 父部门id。根部门为1 ParentID int `json:"parentid"` // 父部门id。根部门为1
Order int `json:"order"` // 在父部门中的次序值。order值大的排序靠前 Order int `json:"order"` // 在父部门中的次序值。order值大的排序靠前
} }
// DepartmentGetResponse 获取单个部门详情
DepartmentGetResponse struct {
util.CommonError
Department Department `json:"department"`
}
) )
// DepartmentCreate 创建部门 // DepartmentCreate 创建部门
@@ -121,3 +128,24 @@ func (r *Client) DepartmentList() ([]*Department, error) {
// 返回数据 // 返回数据
return result.Department, err return result.Department, err
} }
// DepartmentGet 获取单个部门详情
// see https://developer.work.weixin.qq.com/document/path/95351
func (r *Client) DepartmentGet(departmentID int) (*Department, error) {
var (
accessToken string
err error
)
if accessToken, err = r.GetAccessToken(); err != nil {
return nil, err
}
var response []byte
if response, err = util.HTTPGet(fmt.Sprintf(departmentGetURL, accessToken, departmentID)); err != nil {
return nil, err
}
result := &DepartmentGetResponse{}
if err = util.DecodeWithError(response, result, "DepartmentGet"); err != nil {
return nil, err
}
return &result.Department, nil
}

View File

@@ -221,7 +221,7 @@ type UserGetResponse struct {
} `json:"external_profile"` // 成员对外属性,字段详情见对外属性;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段 } `json:"external_profile"` // 成员对外属性,字段详情见对外属性;代开发自建应用需要管理员授权才返回;第三方仅通讯录应用可获取;对于非第三方创建的成员,第三方通讯录应用也不可获取;上游企业不可获取下游企业成员该字段
} }
// UserGet 获取部门成员 // UserGet 读取成员
// @see https://developer.work.weixin.qq.com/document/path/90196 // @see https://developer.work.weixin.qq.com/document/path/90196
func (r *Client) UserGet(UserID string) (*UserGetResponse, error) { func (r *Client) UserGet(UserID string) (*UserGetResponse, error) {
var ( var (
@@ -238,7 +238,7 @@ func (r *Client) UserGet(UserID string) (*UserGetResponse, error) {
userGetURL, userGetURL,
util.Query(map[string]interface{}{ util.Query(map[string]interface{}{
"access_token": accessToken, "access_token": accessToken,
"department_id": UserID, "userid": UserID,
}), }),
}, "?")); err != nil { }, "?")); err != nil {
return nil, err return nil, err

69
work/checkin/checkin.go Normal file
View File

@@ -0,0 +1,69 @@
package checkin
import (
"fmt"
"github.com/silenceper/wechat/v2/util"
)
const (
// getCheckinDataURL 获取打卡记录数据
getCheckinDataURL = "https://qyapi.weixin.qq.com/cgi-bin/checkin/getcheckindata?access_token=%s"
)
type (
// GetCheckinDataRequest 获取打卡记录数据请求
GetCheckinDataRequest struct {
OpenCheckinDataType int64 `json:"opencheckindatatype"`
StartTime int64 `json:"starttime"`
EndTime int64 `json:"endtime"`
UserIDList []string `json:"useridlist"`
}
// GetCheckinDataResponse 获取打卡记录数据响应
GetCheckinDataResponse struct {
util.CommonError
CheckinData []*GetCheckinDataItem `json:"checkindata"`
}
// GetCheckinDataItem 打卡记录数据
GetCheckinDataItem struct {
UserID string `json:"userid"`
GroupName string `json:"groupname"`
CheckinType string `json:"checkin_type"`
ExceptionType string `json:"exception_type"`
CheckinTime int64 `json:"checkin_time"`
LocationTitle string `json:"location_title"`
LocationDetail string `json:"location_detail"`
WifiName string `json:"wifiname"`
Notes string `json:"notes"`
WifiMac string `json:"wifimac"`
MediaIDs []string `json:"mediaids"`
SchCheckinTime int64 `json:"sch_checkin_time"`
GroupID int64 `json:"groupid"`
ScheduleID int64 `json:"schedule_id"`
TimelineID int64 `json:"timeline_id"`
Lat int64 `json:"lat,omitempty"`
Lng int64 `json:"lng,omitempty"`
DeviceID string `json:"deviceid,omitempty"`
}
)
// GetCheckinData 获取打卡记录数据
// @see https://developer.work.weixin.qq.com/document/path/90262
func (r *Client) GetCheckinData(req *GetCheckinDataRequest) (*GetCheckinDataResponse, error) {
var (
accessToken string
err error
)
if accessToken, err = r.GetAccessToken(); err != nil {
return nil, err
}
var response []byte
if response, err = util.PostJSON(fmt.Sprintf(getCheckinDataURL, accessToken), req); err != nil {
return nil, err
}
result := &GetCheckinDataResponse{}
if err = util.DecodeWithError(response, result, "GetCheckinData"); err != nil {
return nil, err
}
return result, nil
}

17
work/checkin/client.go Normal file
View File

@@ -0,0 +1,17 @@
package checkin
import (
"github.com/silenceper/wechat/v2/work/context"
)
// Client 打卡接口实例
type Client struct {
*context.Context
}
// NewClient 初始化实例
func NewClient(ctx *context.Context) *Client {
return &Client{
ctx,
}
}

View File

@@ -104,7 +104,7 @@ type Tag struct {
// WechatChannel 视频号添加的场景 // WechatChannel 视频号添加的场景
type WechatChannel struct { type WechatChannel struct {
NickName string `json:"nickname"` NickName string `json:"nickname"`
Source string `json:"source"` Source int `json:"source"`
} }
// GetExternalUserDetail 获取外部联系人详情 // GetExternalUserDetail 获取外部联系人详情

View File

@@ -70,6 +70,7 @@ type (
GroupNickname string `json:"group_nickname"` //在群里的昵称 GroupNickname string `json:"group_nickname"` //在群里的昵称
Name string `json:"name"` //名字。仅当 need_name = 1 时返回 如果是微信用户,则返回其在微信中设置的名字 如果是企业微信联系人,则返回其设置对外展示的别名或实名 Name string `json:"name"` //名字。仅当 need_name = 1 时返回 如果是微信用户,则返回其在微信中设置的名字 如果是企业微信联系人,则返回其设置对外展示的别名或实名
UnionID string `json:"unionid,omitempty"` //外部联系人在微信开放平台的唯一身份标识微信unionid通过此字段企业可将外部联系人与公众号/小程序用户关联起来。仅当群成员类型是微信用户包括企业成员未添加好友且企业绑定了微信开发者ID有此字段查看绑定方法。第三方不可获取上游企业不可获取下游企业客户的unionid字段 UnionID string `json:"unionid,omitempty"` //外部联系人在微信开放平台的唯一身份标识微信unionid通过此字段企业可将外部联系人与公众号/小程序用户关联起来。仅当群成员类型是微信用户包括企业成员未添加好友且企业绑定了微信开发者ID有此字段查看绑定方法。第三方不可获取上游企业不可获取下游企业客户的unionid字段
State string `json:"state,omitempty"` //如果在配置入群方式时配置了state参数那么在获取客户群详情时通过该方式入群的成员会额外获取到相应的state参数
} }
//GroupChatAdmin 群管理员 //GroupChatAdmin 群管理员
GroupChatAdmin struct { GroupChatAdmin struct {

View File

@@ -11,6 +11,8 @@ const (
uploadImgURL = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s" uploadImgURL = "https://qyapi.weixin.qq.com/cgi-bin/media/uploadimg?access_token=%s"
// uploadTempFile 上传临时素材 // uploadTempFile 上传临时素材
uploadTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s" uploadTempFile = "https://qyapi.weixin.qq.com/cgi-bin/media/upload?access_token=%s&type=%s"
// uploadAttachment 上传附件资源
uploadAttachment = "https://qyapi.weixin.qq.com/cgi-bin/media/upload_attachment?access_token=%s&media_type=%s&attachment_type=%d"
) )
// UploadImgResponse 上传图片响应 // UploadImgResponse 上传图片响应
@@ -27,6 +29,14 @@ type UploadTempFileResponse struct {
Type string `json:"type"` Type string `json:"type"`
} }
// UploadAttachmentResponse 上传资源附件响应
type UploadAttachmentResponse struct {
util.CommonError
MediaID string `json:"media_id"`
CreateAt int64 `json:"created_at"`
Type string `json:"type"`
}
// UploadImg 上传图片 // UploadImg 上传图片
// @see https://developer.work.weixin.qq.com/document/path/90256 // @see https://developer.work.weixin.qq.com/document/path/90256
func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) { func (r *Client) UploadImg(filename string) (*UploadImgResponse, error) {
@@ -69,3 +79,26 @@ func (r *Client) UploadTempFile(filename string, mediaType string) (*UploadTempF
} }
return result, nil return result, nil
} }
// UploadAttachment 上传附件资源
// @see https://developer.work.weixin.qq.com/document/path/95098
// @mediaType 媒体文件类型分别有图片image、视频video、普通文件file
// @attachment_type 附件类型不同的附件类型用于不同的场景。1朋友圈2:商品图册
func (r *Client) UploadAttachment(filename string, mediaType string, attachmentType int) (*UploadAttachmentResponse, error) {
var (
accessToken string
err error
)
if accessToken, err = r.GetAccessToken(); err != nil {
return nil, err
}
var response []byte
if response, err = util.PostFile("media", filename, fmt.Sprintf(uploadAttachment, accessToken, mediaType, attachmentType)); err != nil {
return nil, err
}
result := &UploadAttachmentResponse{}
if err = util.DecodeWithError(response, result, "UploadAttachment"); err != nil {
return nil, err
}
return result, nil
}

View File

@@ -4,6 +4,7 @@ import (
"github.com/silenceper/wechat/v2/credential" "github.com/silenceper/wechat/v2/credential"
"github.com/silenceper/wechat/v2/work/addresslist" "github.com/silenceper/wechat/v2/work/addresslist"
"github.com/silenceper/wechat/v2/work/appchat" "github.com/silenceper/wechat/v2/work/appchat"
"github.com/silenceper/wechat/v2/work/checkin"
"github.com/silenceper/wechat/v2/work/config" "github.com/silenceper/wechat/v2/work/config"
"github.com/silenceper/wechat/v2/work/context" "github.com/silenceper/wechat/v2/work/context"
"github.com/silenceper/wechat/v2/work/externalcontact" "github.com/silenceper/wechat/v2/work/externalcontact"
@@ -85,3 +86,8 @@ func (wk *Work) GetAppChat() *appchat.Client {
func (wk *Work) GetInvoice() *invoice.Client { func (wk *Work) GetInvoice() *invoice.Client {
return invoice.NewClient(wk.ctx) return invoice.NewClient(wk.ctx)
} }
// GetCheckin 获取打卡接口实例
func (wk *Work) GetCheckin() *checkin.Client {
return checkin.NewClient(wk.ctx)
}