-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
185 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package openapi | ||
|
||
import ( | ||
"github.com/medivhzhan/weapp/v3/request" | ||
) | ||
|
||
const apiClearQuota = "/cgi-bin/clear_quota" | ||
|
||
type ClearQuotaRequest struct { | ||
// 必填 要被清空的账号的appid | ||
Appid string `json:"appid"` | ||
} | ||
|
||
type ClearQuotaResponse struct { | ||
request.CommonError | ||
} | ||
|
||
// 重置API调用次数 | ||
// doc: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/clearQuota.html | ||
func (cli *OpenApi) ClearQuota(req *ClearQuotaRequest) (*ClearQuotaResponse, error) { | ||
|
||
uri, err := cli.conbineURI(apiClearQuota, nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(ClearQuotaResponse) | ||
if err := cli.request.Post(uri, req, res); err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package openapi | ||
|
||
import ( | ||
"github.com/medivhzhan/weapp/v3/request" | ||
) | ||
|
||
const apiClearQuotaByAppSecret = "/cgi-bin/clear_quota/v2" | ||
|
||
type ClearQuotaByAppSecretRequest struct { | ||
// 必填 要被清空的账号的appid | ||
Appid string `query:"appid"` | ||
// 唯一凭证密钥,即 AppSecret,获取方式同 appid | ||
AppSecret string `query:"appsecret"` | ||
} | ||
|
||
type ClearQuotaByAppSecretResponse struct { | ||
request.CommonError | ||
} | ||
|
||
// 使用AppSecret重置 API 调用次数 | ||
// doc: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/clearQuotaByAppSecret.html | ||
func (cli *OpenApi) ClearQuotaByAppSecret(req *ClearQuotaByAppSecretRequest) (*ClearQuotaByAppSecretResponse, error) { | ||
|
||
uri, err := cli.conbineURI(apiClearQuotaByAppSecret, req, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(ClearQuotaByAppSecretResponse) | ||
if err := cli.request.Post(uri, nil, res); err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package openapi | ||
|
||
import ( | ||
"github.com/medivhzhan/weapp/v3/request" | ||
) | ||
|
||
const apiGetApiQuota = "/cgi-bin/openapi/quota/get" | ||
|
||
type GetApiQuotaRequest struct { | ||
// @必填 | ||
// api的请求地址,例如"/cgi-bin/message/custom/send";不要前缀“https://api.weixin.qq.com” ,也不要漏了"/",否则都会76003的报错 | ||
CgiPath string `json:"cgi_path"` | ||
} | ||
|
||
type GetApiQuotaResponse struct { | ||
request.CommonError | ||
Quota struct { | ||
DailyLimit int64 `json:"daily_limit"` // 当天该账号可调用该接口的次数 | ||
Used int64 `json:"used"` // 当天已经调用的次数 | ||
Remain int64 `json:"remain"` // 当天剩余调用次数 | ||
RateLimit struct { | ||
CallCount int64 `json:"call_count"` // 周期内可调用数量,单位 次 | ||
RefreshSecond int64 `json:"refresh_second"` // 更新周期,单位 秒 | ||
} `json:"rate_limit"` // 普通调用频率限制 | ||
ComponentRateLimit struct { | ||
CallCount int64 `json:"call_count"` // 周期内可调用数量,单位 次 | ||
RefreshSecond int64 `json:"refresh_second"` // 更新周期,单位 秒 | ||
} `json:"component_rate_limit"` // 代调用频率限制 | ||
} `json:"quota"` // quota详情 | ||
} | ||
|
||
// 查询API调用额度 | ||
// doc: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getApiQuota.html | ||
func (cli *OpenApi) GetApiQuota(req *GetApiQuotaRequest) (*GetApiQuotaResponse, error) { | ||
|
||
uri, err := cli.conbineURI(apiGetApiQuota, nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(GetApiQuotaResponse) | ||
if err := cli.request.Post(uri, req, res); err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package openapi | ||
|
||
import ( | ||
"github.com/medivhzhan/weapp/v3/request" | ||
) | ||
|
||
const apiGetRidInfo = "/cgi-bin/openapi/rid/get" | ||
|
||
type GetRidInfoRequest struct { | ||
// @必填 | ||
// 调用接口报错返回的rid | ||
Rid string `json:"rid"` | ||
} | ||
|
||
type GetRidInfoResponse struct { | ||
request.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对应的请求详情 | ||
} | ||
|
||
// 查询rid信息 | ||
// doc: https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/openApi-mgnt/getRidInfo.html | ||
func (cli *OpenApi) GetRidInfo(req *GetRidInfoRequest) (*GetRidInfoResponse, error) { | ||
|
||
uri, err := cli.conbineURI(apiGetRidInfo, nil, true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
res := new(GetRidInfoResponse) | ||
if err := cli.request.Post(uri, req, res); err != nil { | ||
return nil, err | ||
} | ||
|
||
return res, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package openapi | ||
|
||
import ( | ||
"github.com/medivhzhan/weapp/v3/request" | ||
) | ||
|
||
type OpenApi struct { | ||
request *request.Request | ||
// 组成完整的 URL 地址 | ||
// 默认包含 AccessToken | ||
conbineURI func(url string, req interface{}, withToken bool) (string, error) | ||
} | ||
|
||
func NewOpenApi(request *request.Request, conbineURI func(url string, req interface{}, withToken bool) (string, error)) *OpenApi { | ||
sm := OpenApi{ | ||
request: request, | ||
conbineURI: conbineURI, | ||
} | ||
|
||
return &sm | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters