mirror of
https://github.com/silenceper/wechat.git
synced 2026-03-01 00:35:26 +08:00
Compare commits
1 Commits
b12825f83b
...
revert-685
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
42b0966049 |
24
.github/workflows/go.yml
vendored
24
.github/workflows/go.yml
vendored
@@ -10,21 +10,17 @@ jobs:
|
|||||||
golangci:
|
golangci:
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go-version: [ '1.16','1.17','1.18','1.19','1.20' ]
|
go-version: [1.16.x,1.17.x,1.18.x]
|
||||||
name: golangci-lint
|
name: golangci-lint
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Setup Golang ${{ matrix.go-version }}
|
- uses: actions/setup-go@v3
|
||||||
uses: actions/setup-go@v4
|
- uses: actions/checkout@v3
|
||||||
with:
|
|
||||||
go-version: ${{ matrix.go-version }}
|
|
||||||
- name: Checkout
|
|
||||||
uses: actions/checkout@v3
|
|
||||||
- name: golangci-lint
|
- name: golangci-lint
|
||||||
uses: golangci/golangci-lint-action@v3
|
uses: golangci/golangci-lint-action@v3.2.0
|
||||||
with:
|
with:
|
||||||
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
|
||||||
version: v1.52.2
|
version: latest
|
||||||
build:
|
build:
|
||||||
name: Test
|
name: Test
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
@@ -32,7 +28,7 @@ jobs:
|
|||||||
redis:
|
redis:
|
||||||
image: redis
|
image: redis
|
||||||
ports:
|
ports:
|
||||||
- 6379:6379
|
- 6379:6379
|
||||||
options: --entrypoint redis-server
|
options: --entrypoint redis-server
|
||||||
memcached:
|
memcached:
|
||||||
image: memcached
|
image: memcached
|
||||||
@@ -42,14 +38,14 @@ jobs:
|
|||||||
# strategy set
|
# strategy set
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
go: [ '1.16','1.17','1.18','1.19','1.20' ]
|
go: ["1.16", "1.17", "1.18"]
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v2
|
||||||
- name: Set up Go 1.x
|
- name: Set up Go 1.x
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: ${{ matrix.go }}
|
go-version: ${{ matrix.go }}
|
||||||
id: go
|
id: go
|
||||||
- name: Test
|
- name: Test
|
||||||
run: go test -v -race ./...
|
run: go test -v -race ./...
|
||||||
|
|||||||
8
.github/workflows/release.yml
vendored
8
.github/workflows/release.yml
vendored
@@ -11,17 +11,17 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
-
|
-
|
||||||
name: Checkout
|
name: Checkout
|
||||||
uses: actions/checkout@v3
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
-
|
-
|
||||||
name: Set up Go
|
name: Set up Go
|
||||||
uses: actions/setup-go@v4
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.16
|
go-version: 1.15
|
||||||
-
|
-
|
||||||
name: Run GoReleaser
|
name: Run GoReleaser
|
||||||
uses: goreleaser/goreleaser-action@v4
|
uses: goreleaser/goreleaser-action@v2
|
||||||
with:
|
with:
|
||||||
version: latest
|
version: latest
|
||||||
args: release --rm-dist
|
args: release --rm-dist
|
||||||
|
|||||||
@@ -1,36 +0,0 @@
|
|||||||
package openapi
|
|
||||||
|
|
||||||
import "github.com/silenceper/wechat/v2/util"
|
|
||||||
|
|
||||||
// GetAPIQuotaParams 查询API调用额度参数
|
|
||||||
type GetAPIQuotaParams struct {
|
|
||||||
CgiPath string `json:"cgi_path"` // api的请求地址,例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ,也不要漏了"/",否则都会76003的报错
|
|
||||||
}
|
|
||||||
|
|
||||||
// APIQuota API调用额度
|
|
||||||
type APIQuota struct {
|
|
||||||
util.CommonError
|
|
||||||
Quota struct {
|
|
||||||
DailyLimit int64 `json:"daily_limit"` // 当天该账号可调用该接口的次数
|
|
||||||
Used int64 `json:"used"` // 当天已经调用的次数
|
|
||||||
Remain int64 `json:"remain"` // 当天剩余调用次数
|
|
||||||
} `json:"quota"` // 详情
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRidInfoParams 查询rid信息参数
|
|
||||||
type GetRidInfoParams struct {
|
|
||||||
Rid string `json:"rid"` // 调用接口报错返回的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请求的请求参数
|
|
||||||
ResponseBody string `json:"response_body"` // 接口请求返回参数
|
|
||||||
ClientIP string `json:"client_ip"` // 接口请求的客户端ip
|
|
||||||
} `json:"request"` // 该rid对应的请求详情
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package openapi
|
|
||||||
|
|
||||||
import (
|
|
||||||
"errors"
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/domain/openapi"
|
|
||||||
mpContext "github.com/silenceper/wechat/v2/miniprogram/context"
|
|
||||||
ocContext "github.com/silenceper/wechat/v2/officialaccount/context"
|
|
||||||
"github.com/silenceper/wechat/v2/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
clearQuotaURL = "https://api.weixin.qq.com/cgi-bin/clear_quota" // 重置API调用次数
|
|
||||||
getAPIQuotaURL = "https://api.weixin.qq.com/cgi-bin/openapi/quota/get" // 查询API调用额度
|
|
||||||
getRidInfoURL = "https://api.weixin.qq.com/cgi-bin/openapi/rid/get" // 查询rid信息
|
|
||||||
clearQuotaByAppSecretURL = "https://api.weixin.qq.com/cgi-bin/clear_quota/v2" // 使用AppSecret重置 API 调用次数
|
|
||||||
)
|
|
||||||
|
|
||||||
// OpenAPI openApi管理
|
|
||||||
type OpenAPI struct {
|
|
||||||
ctx interface{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewOpenAPI 实例化
|
|
||||||
func NewOpenAPI(ctx interface{}) *OpenAPI {
|
|
||||||
return &OpenAPI{ctx: ctx}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearQuota 重置API调用次数
|
|
||||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/clearQuota.html
|
|
||||||
func (o *OpenAPI) ClearQuota() error {
|
|
||||||
appID, _, err := o.getAppIDAndSecret()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
var payload = struct {
|
|
||||||
AppID string `json:"appid"`
|
|
||||||
}{
|
|
||||||
AppID: appID,
|
|
||||||
}
|
|
||||||
res, err := o.doPostRequest(clearQuotaURL, payload)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return util.DecodeWithCommonError(res, "ClearQuota")
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetAPIQuota 查询API调用额度
|
|
||||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getApiQuota.html
|
|
||||||
func (o *OpenAPI) GetAPIQuota(params openapi.GetAPIQuotaParams) (quota openapi.APIQuota, err error) {
|
|
||||||
res, err := o.doPostRequest(getAPIQuotaURL, params)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = util.DecodeWithError(res, "a, "GetAPIQuota")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetRidInfo 查询rid信息
|
|
||||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getRidInfo.html
|
|
||||||
func (o *OpenAPI) GetRidInfo(params openapi.GetRidInfoParams) (r openapi.RidInfo, err error) {
|
|
||||||
res, err := o.doPostRequest(getRidInfoURL, params)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
err = util.DecodeWithError(res, &r, "GetRidInfo")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// ClearQuotaByAppSecret 使用AppSecret重置 API 调用次数
|
|
||||||
// https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/clearQuotaByAppSecret.html
|
|
||||||
func (o *OpenAPI) ClearQuotaByAppSecret() error {
|
|
||||||
id, secret, err := o.getAppIDAndSecret()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
uri := fmt.Sprintf("%s?appid=%s&appsecret=%s", clearQuotaByAppSecretURL, id, secret)
|
|
||||||
res, err := util.HTTPPost(uri, "")
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
return util.DecodeWithCommonError(res, "ClearQuotaByAppSecret")
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取 AppID 和 AppSecret
|
|
||||||
func (o *OpenAPI) getAppIDAndSecret() (string, string, error) {
|
|
||||||
switch o.ctx.(type) {
|
|
||||||
case *mpContext.Context:
|
|
||||||
c := o.ctx.(*mpContext.Context)
|
|
||||||
return c.AppID, c.AppSecret, nil
|
|
||||||
case *ocContext.Context:
|
|
||||||
c := o.ctx.(*ocContext.Context)
|
|
||||||
return c.AppID, c.AppSecret, nil
|
|
||||||
default:
|
|
||||||
return "", "", errors.New("invalid context type")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取 AccessToken
|
|
||||||
func (o *OpenAPI) getAccessToken() (string, error) {
|
|
||||||
switch o.ctx.(type) {
|
|
||||||
case *mpContext.Context:
|
|
||||||
return o.ctx.(*mpContext.Context).GetAccessToken()
|
|
||||||
case *ocContext.Context:
|
|
||||||
return o.ctx.(*ocContext.Context).GetAccessToken()
|
|
||||||
default:
|
|
||||||
return "", errors.New("invalid context type")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 创建 POST 请求
|
|
||||||
func (o *OpenAPI) doPostRequest(uri string, payload interface{}) ([]byte, error) {
|
|
||||||
ak, err := o.getAccessToken()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
uri = fmt.Sprintf("%s?access_token=%s", uri, ak)
|
|
||||||
return util.PostJSON(uri, payload)
|
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package miniprogram
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/silenceper/wechat/v2/credential"
|
"github.com/silenceper/wechat/v2/credential"
|
||||||
"github.com/silenceper/wechat/v2/internal/openapi"
|
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/analysis"
|
"github.com/silenceper/wechat/v2/miniprogram/analysis"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/auth"
|
"github.com/silenceper/wechat/v2/miniprogram/auth"
|
||||||
"github.com/silenceper/wechat/v2/miniprogram/business"
|
"github.com/silenceper/wechat/v2/miniprogram/business"
|
||||||
@@ -127,8 +126,3 @@ func (miniProgram *MiniProgram) GetShortLink() *shortlink.ShortLink {
|
|||||||
func (miniProgram *MiniProgram) GetSURLScheme() *urlscheme.URLScheme {
|
func (miniProgram *MiniProgram) GetSURLScheme() *urlscheme.URLScheme {
|
||||||
return urlscheme.NewURLScheme(miniProgram.ctx)
|
return urlscheme.NewURLScheme(miniProgram.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOpenAPI openApi管理接口
|
|
||||||
func (miniProgram *MiniProgram) GetOpenAPI() *openapi.OpenAPI {
|
|
||||||
return openapi.NewOpenAPI(miniProgram.ctx)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -123,7 +123,6 @@ type MixMessage struct {
|
|||||||
Title string `xml:"Title"`
|
Title string `xml:"Title"`
|
||||||
Description string `xml:"Description"`
|
Description string `xml:"Description"`
|
||||||
URL string `xml:"Url"`
|
URL string `xml:"Url"`
|
||||||
BizMsgMenuID int64 `xml:"bizmsgmenuid"`
|
|
||||||
|
|
||||||
// 事件相关
|
// 事件相关
|
||||||
Event EventType `xml:"Event" json:"Event"`
|
Event EventType `xml:"Event" json:"Event"`
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import (
|
|||||||
stdcontext "context"
|
stdcontext "context"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/internal/openapi"
|
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/draft"
|
"github.com/silenceper/wechat/v2/officialaccount/draft"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/freepublish"
|
"github.com/silenceper/wechat/v2/officialaccount/freepublish"
|
||||||
"github.com/silenceper/wechat/v2/officialaccount/ocr"
|
"github.com/silenceper/wechat/v2/officialaccount/ocr"
|
||||||
@@ -213,8 +212,3 @@ func (officialAccount *OfficialAccount) GetSubscribe() *message.Subscribe {
|
|||||||
func (officialAccount *OfficialAccount) GetCustomerServiceManager() *customerservice.Manager {
|
func (officialAccount *OfficialAccount) GetCustomerServiceManager() *customerservice.Manager {
|
||||||
return customerservice.NewCustomerServiceManager(officialAccount.ctx)
|
return customerservice.NewCustomerServiceManager(officialAccount.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetOpenAPI openApi管理接口
|
|
||||||
func (officialAccount *OfficialAccount) GetOpenAPI() *openapi.OpenAPI {
|
|
||||||
return openapi.NewOpenAPI(officialAccount.ctx)
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,230 +0,0 @@
|
|||||||
package addresslist
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// getPermListURL 获取应用的可见范围
|
|
||||||
getPermListURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/agent/get_perm_list?access_token=%s"
|
|
||||||
// getLinkedCorpUserURL 获取互联企业成员详细信息
|
|
||||||
getLinkedCorpUserURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/user/get?access_token=%s"
|
|
||||||
// linkedCorpSimpleListURL 获取互联企业部门成员
|
|
||||||
linkedCorpSimpleListURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/user/simplelist?access_token=%s"
|
|
||||||
// linkedCorpUserListURL 获取互联企业部门成员详情
|
|
||||||
linkedCorpUserListURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/user/list?access_token=%s"
|
|
||||||
// linkedCorpDepartmentListURL 获取互联企业部门列表
|
|
||||||
linkedCorpDepartmentListURL = "https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/department/list?access_token=%s"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetPermListResponse 获取应用的可见范围响应
|
|
||||||
type GetPermListResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
UserIDs []string `json:"userids"`
|
|
||||||
DepartmentIDs []string `json:"department_ids"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetPermList 获取应用的可见范围
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/93172
|
|
||||||
func (r *Client) GetPermList() (*GetPermListResponse, error) {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.HTTPPost(fmt.Sprintf(getPermListURL, accessToken), ""); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &GetPermListResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "GetPermList"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLinkedCorpUserRequest 获取互联企业成员详细信息请求
|
|
||||||
type GetLinkedCorpUserRequest struct {
|
|
||||||
UserID string `json:"userid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLinkedCorpUserResponse 获取互联企业成员详细信息响应
|
|
||||||
type GetLinkedCorpUserResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
UserInfo LinkedCorpUserInfo `json:"user_info"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpUserInfo 互联企业成员详细信息
|
|
||||||
type LinkedCorpUserInfo struct {
|
|
||||||
UserID string `json:"userid"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Department []string `json:"department"`
|
|
||||||
Mobile string `json:"mobile"`
|
|
||||||
Telephone string `json:"telephone"`
|
|
||||||
Email string `json:"email"`
|
|
||||||
Position string `json:"position"`
|
|
||||||
CorpID string `json:"corpid"`
|
|
||||||
Extattr Extattr `json:"extattr"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Extattr 互联企业成员详细信息扩展属性
|
|
||||||
type Extattr struct {
|
|
||||||
Attrs []ExtattrItem `json:"attrs"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExtattrItem 互联企业成员详细信息扩展属性条目
|
|
||||||
type ExtattrItem struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Value string `json:"value,omitempty"`
|
|
||||||
Type int `json:"type"`
|
|
||||||
Text ExtattrItemText `json:"text,omitempty"`
|
|
||||||
Web ExtattrItemWeb `json:"web,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExtattrItemText 互联企业成员详细信息自定义属性(文本)
|
|
||||||
type ExtattrItemText struct {
|
|
||||||
Value string `json:"value"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExtattrItemWeb 互联企业成员详细信息自定义属性(网页)
|
|
||||||
type ExtattrItemWeb struct {
|
|
||||||
URL string `json:"url"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetLinkedCorpUser 获取互联企业成员详细信息
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/93171
|
|
||||||
func (r *Client) GetLinkedCorpUser(req *GetLinkedCorpUserRequest) (*GetLinkedCorpUserResponse, 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(getLinkedCorpUserURL, accessToken), req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &GetLinkedCorpUserResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "GetLinkedCorpUser"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpSimpleListRequest 获取互联企业部门成员请求
|
|
||||||
type LinkedCorpSimpleListRequest struct {
|
|
||||||
DepartmentID string `json:"department_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpSimpleListResponse 获取互联企业部门成员响应
|
|
||||||
type LinkedCorpSimpleListResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
Userlist []LinkedCorpUser `json:"userlist"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpUser 企业部门成员
|
|
||||||
type LinkedCorpUser struct {
|
|
||||||
UserID string `json:"userid"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Department []string `json:"department"`
|
|
||||||
CorpID string `json:"corpid"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpSimpleList 获取互联企业部门成员
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/93168
|
|
||||||
func (r *Client) LinkedCorpSimpleList(req *LinkedCorpSimpleListRequest) (*LinkedCorpSimpleListResponse, 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(linkedCorpSimpleListURL, accessToken), req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &LinkedCorpSimpleListResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "LinkedCorpSimpleList"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpUserListRequest 获取互联企业部门成员详情请求
|
|
||||||
type LinkedCorpUserListRequest struct {
|
|
||||||
DepartmentID string `json:"department_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpUserListResponse 获取互联企业部门成员详情响应
|
|
||||||
type LinkedCorpUserListResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
UserList []LinkedCorpUserInfo `json:"userlist"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpUserList 获取互联企业部门成员详情
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/93169
|
|
||||||
func (r *Client) LinkedCorpUserList(req *LinkedCorpUserListRequest) (*LinkedCorpUserListResponse, 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(linkedCorpUserListURL, accessToken), req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &LinkedCorpUserListResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "LinkedCorpUserList"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpDepartmentListRequest 获取互联企业部门列表请求
|
|
||||||
type LinkedCorpDepartmentListRequest struct {
|
|
||||||
DepartmentID string `json:"department_id"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpDepartmentListResponse 获取互联企业部门列表响应
|
|
||||||
type LinkedCorpDepartmentListResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
DepartmentList []LinkedCorpDepartment `json:"department_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpDepartment 互联企业部门
|
|
||||||
type LinkedCorpDepartment struct {
|
|
||||||
DepartmentID string `json:"department_id"`
|
|
||||||
DepartmentName string `json:"department_name"`
|
|
||||||
ParentID string `json:"parentid"`
|
|
||||||
Order int `json:"order"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// LinkedCorpDepartmentList 获取互联企业部门列表
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/93170
|
|
||||||
func (r *Client) LinkedCorpDepartmentList(req *LinkedCorpDepartmentListRequest) (*LinkedCorpDepartmentListResponse, 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(linkedCorpDepartmentListURL, accessToken), req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &LinkedCorpDepartmentListResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "LinkedCorpDepartmentList"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
package invoice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"github.com/silenceper/wechat/v2/work/context"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Client 电子发票接口实例
|
|
||||||
type Client struct {
|
|
||||||
*context.Context
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewClient 初始化实例
|
|
||||||
func NewClient(ctx *context.Context) *Client {
|
|
||||||
return &Client{
|
|
||||||
ctx,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,191 +0,0 @@
|
|||||||
package invoice
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/silenceper/wechat/v2/util"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
|
||||||
// getInvoiceInfoURL 查询电子发票
|
|
||||||
getInvoiceInfoURL = "https://qyapi.weixin.qq.com/cgi-bin/card/invoice/reimburse/getinvoiceinfo?access_token=%s"
|
|
||||||
// updateInvoiceStatusURL 更新发票状态
|
|
||||||
updateInvoiceStatusURL = "https://qyapi.weixin.qq.com/cgi-bin/card/invoice/reimburse/updateinvoicestatus?access_token=%s"
|
|
||||||
// updateStatusBatchURL 批量更新发票状态
|
|
||||||
updateStatusBatchURL = "https://qyapi.weixin.qq.com/cgi-bin/card/invoice/reimburse/updatestatusbatch?access_token=%s"
|
|
||||||
// getInvoiceInfoBatchURL 批量查询电子发票
|
|
||||||
getInvoiceInfoBatchURL = "https://qyapi.weixin.qq.com/cgi-bin/card/invoice/reimburse/getinvoiceinfobatch?access_token=%s"
|
|
||||||
)
|
|
||||||
|
|
||||||
// GetInvoiceInfoRequest 查询电子发票请求
|
|
||||||
type GetInvoiceInfoRequest struct {
|
|
||||||
CardID string `json:"card_id"`
|
|
||||||
EncryptCode string `json:"encrypt_code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInvoiceInfoResponse 查询电子发票响应
|
|
||||||
type GetInvoiceInfoResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
CardID string `json:"card_id"`
|
|
||||||
BeginTime int64 `json:"begin_time"`
|
|
||||||
EndTime int64 `json:"end_time"`
|
|
||||||
OpenID string `json:"openid"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Payee string `json:"payee"`
|
|
||||||
Detail string `json:"detail"`
|
|
||||||
UserInfo UserInfo `json:"user_info"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserInfo 发票的用户信息
|
|
||||||
type UserInfo struct {
|
|
||||||
Fee int64 `json:"fee"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
BillingTime int64 `json:"billing_time"`
|
|
||||||
BillingNo string `json:"billing_no"`
|
|
||||||
BillingCode string `json:"billing_code"`
|
|
||||||
Info []Info `json:"info"`
|
|
||||||
FeeWithoutTax int64 `json:"fee_without_tax"`
|
|
||||||
Tax int64 `json:"tax"`
|
|
||||||
Detail string `json:"detail"`
|
|
||||||
PdfURL string `json:"pdf_url"`
|
|
||||||
TripPdfURL string `json:"trip_pdf_url"`
|
|
||||||
ReimburseStatus string `json:"reimburse_status"`
|
|
||||||
CheckCode string `json:"check_code"`
|
|
||||||
BuyerNumber string `json:"buyer_number"`
|
|
||||||
BuyerAddressAndPhone string `json:"buyer_address_and_phone"`
|
|
||||||
BuyerBankAccount string `json:"buyer_bank_account"`
|
|
||||||
SellerNumber string `json:"seller_number"`
|
|
||||||
SellerAddressAndPhone string `json:"seller_address_and_phone"`
|
|
||||||
SellerBankAccount string `json:"seller_bank_account"`
|
|
||||||
Remarks string `json:"remarks"`
|
|
||||||
Cashier string `json:"cashier"`
|
|
||||||
Maker string `json:"maker"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Info 商品信息结构
|
|
||||||
type Info struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Num int64 `json:"num"`
|
|
||||||
Unit string `json:"unit"`
|
|
||||||
Fee int64 `json:"fee"`
|
|
||||||
Price int64 `json:"price"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInvoiceInfo 查询电子发票
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/90284
|
|
||||||
func (r *Client) GetInvoiceInfo(req *GetInvoiceInfoRequest) (*GetInvoiceInfoResponse, 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(getInvoiceInfoURL, accessToken), req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &GetInvoiceInfoResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "GetInvoiceInfo"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateInvoiceStatusRequest 更新发票状态请求
|
|
||||||
type UpdateInvoiceStatusRequest struct {
|
|
||||||
CardID string `json:"card_id"`
|
|
||||||
EncryptCode string `json:"encrypt_code"`
|
|
||||||
ReimburseStatus string `json:"reimburse_status"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateInvoiceStatus 更新发票状态
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/90285
|
|
||||||
func (r *Client) UpdateInvoiceStatus(req *UpdateInvoiceStatusRequest) error {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.PostJSON(fmt.Sprintf(updateInvoiceStatusURL, accessToken), req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return util.DecodeWithCommonError(response, "UpdateInvoiceStatus")
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateStatusBatchRequest 批量更新发票状态
|
|
||||||
type UpdateStatusBatchRequest struct {
|
|
||||||
OpenID string `json:"openid"`
|
|
||||||
ReimburseStatus string `json:"reimburse_status"`
|
|
||||||
InvoiceList []Invoice `json:"invoice_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Invoice 发票卡券
|
|
||||||
type Invoice struct {
|
|
||||||
CardID string `json:"card_id"`
|
|
||||||
EncryptCode string `json:"encrypt_code"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// UpdateStatusBatch 批量更新发票状态
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/90286
|
|
||||||
func (r *Client) UpdateStatusBatch(req *UpdateStatusBatchRequest) error {
|
|
||||||
var (
|
|
||||||
accessToken string
|
|
||||||
err error
|
|
||||||
)
|
|
||||||
if accessToken, err = r.GetAccessToken(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var response []byte
|
|
||||||
if response, err = util.PostJSON(fmt.Sprintf(updateStatusBatchURL, accessToken), req); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return util.DecodeWithCommonError(response, "UpdateStatusBatch")
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInvoiceInfoBatchRequest 批量查询电子发票请求
|
|
||||||
type GetInvoiceInfoBatchRequest struct {
|
|
||||||
ItemList []Invoice `json:"item_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInvoiceInfoBatchResponse 批量查询电子发票响应
|
|
||||||
type GetInvoiceInfoBatchResponse struct {
|
|
||||||
util.CommonError
|
|
||||||
ItemList []Item `json:"item_list"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// Item 电子发票的结构化信息
|
|
||||||
type Item struct {
|
|
||||||
CardID string `json:"card_id"`
|
|
||||||
BeginTime int64 `json:"begin_time"`
|
|
||||||
EndTime int64 `json:"end_time"`
|
|
||||||
OpenID string `json:"openid"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Payee string `json:"payee"`
|
|
||||||
Detail string `json:"detail"`
|
|
||||||
UserInfo UserInfo `json:"user_info"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetInvoiceInfoBatch 批量查询电子发票
|
|
||||||
// see https://developer.work.weixin.qq.com/document/path/90287
|
|
||||||
func (r *Client) GetInvoiceInfoBatch(req *GetInvoiceInfoBatchRequest) (*GetInvoiceInfoBatchResponse, 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(getInvoiceInfoBatchURL, accessToken), req); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
result := &GetInvoiceInfoBatchResponse{}
|
|
||||||
if err = util.DecodeWithError(response, result, "GetInvoiceInfoBatch"); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return result, nil
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
"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"
|
||||||
"github.com/silenceper/wechat/v2/work/invoice"
|
|
||||||
"github.com/silenceper/wechat/v2/work/kf"
|
"github.com/silenceper/wechat/v2/work/kf"
|
||||||
"github.com/silenceper/wechat/v2/work/material"
|
"github.com/silenceper/wechat/v2/work/material"
|
||||||
"github.com/silenceper/wechat/v2/work/message"
|
"github.com/silenceper/wechat/v2/work/message"
|
||||||
@@ -80,8 +79,3 @@ func (wk *Work) GetMessage() *message.Client {
|
|||||||
func (wk *Work) GetAppChat() *appchat.Client {
|
func (wk *Work) GetAppChat() *appchat.Client {
|
||||||
return appchat.NewClient(wk.ctx)
|
return appchat.NewClient(wk.ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetInvoice get invoice
|
|
||||||
func (wk *Work) GetInvoice() *invoice.Client {
|
|
||||||
return invoice.NewClient(wk.ctx)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user