github.com/fastwego/offiaccount@v1.0.1/apis/util/util.go (about) 1 // Copyright 2020 FastWeGo 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package util 开发辅助 16 package util 17 18 import ( 19 "bytes" 20 21 "github.com/fastwego/offiaccount" 22 ) 23 24 const ( 25 apiGetCallbackIp = "/cgi-bin/getcallbackip" 26 apiGetApiDomainIp = "/cgi-bin/get_api_domain_ip" 27 apiCallbackCheck = "/cgi-bin/callback/check" 28 apiClearQuota = "/cgi-bin/clear_quota" 29 ) 30 31 /* 32 获取微信服务器IP地址 33 34 如果公众号基于安全等考虑,需要获知微信服务器的IP地址列表,以便进行相关限制,可以通过该接口获得微信服务器IP地址列表或者IP网段信息 35 36 See: https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_the_WeChat_server_IP_address.html 37 38 GET https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN 39 */ 40 func GetCallbackIp(ctx *offiaccount.OffiAccount) (resp []byte, err error) { 41 return ctx.Client.HTTPGet(apiGetCallbackIp) 42 } 43 44 /* 45 获取微信API接口 IP地址 46 47 即api.weixin.qq.com的解析地址,由开发者调用微信侧的接入IP 48 49 See: https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_the_WeChat_server_IP_address.html 50 51 GET https://api.weixin.qq.com/cgi-bin/get_api_domain_ip?access_token=ACCESS_TOKEN 52 */ 53 func GetApiDomainIp(ctx *offiaccount.OffiAccount) (resp []byte, err error) { 54 return ctx.Client.HTTPGet(apiGetApiDomainIp) 55 } 56 57 /* 58 网络检测 59 60 为了帮助开发者排查回调连接失败的问题,提供这个网络检测的API。它可以对开发者URL做域名解析,然后对所有IP进行一次ping操作,得到丢包率和耗时 61 62 See: https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Network_Detection.html 63 64 POST https://api.weixin.qq.com/cgi-bin/callback/check?access_token=ACCESS_TOKEN 65 */ 66 func CallbackCheck(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 67 return ctx.Client.HTTPPost(apiCallbackCheck, bytes.NewReader(payload), "application/json;charset=utf-8") 68 } 69 70 /* 71 对公众号的所有api调用次数进行清零 72 73 74 75 See: https://developers.weixin.qq.com/doc/offiaccount/Message_Management/API_Call_Limits.html 76 77 POST https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN 78 */ 79 func ClearQuota(ctx *offiaccount.OffiAccount, payload []byte) (resp []byte, err error) { 80 return ctx.Client.HTTPPost(apiClearQuota, bytes.NewReader(payload), "application/json;charset=utf-8") 81 }