mirror of
https://github.com/xxjwxc/public.git
synced 2025-09-26 20:01:19 +08:00
2
This commit is contained in:
1
go.sum
1
go.sum
@@ -287,6 +287,7 @@ golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGm
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135 h1:5Beo0mZN8dRzgrMMkDp0jc8YXQKx9DiJ2k1dkvGsn5A=
|
||||
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
@@ -108,4 +108,6 @@ const ( //消息id定义
|
||||
OpTimeError ErrCode = 1094 // 请不要平凡操作
|
||||
EmptyError ErrCode = 1095 // 数据为空
|
||||
Unfollow ErrCode = 1096 // 用户已取消关注
|
||||
HaveLink ErrCode = 1097 // 存在关联
|
||||
StateError ErrCode = 1098 // 状态错误
|
||||
)
|
||||
|
@@ -109,6 +109,8 @@ func _() {
|
||||
_ = x[OpTimeError-1094]
|
||||
_ = x[EmptyError-1095]
|
||||
_ = x[Unfollow-1096]
|
||||
_ = x[HaveLink-1097]
|
||||
_ = x[StateError-1098]
|
||||
}
|
||||
|
||||
const (
|
||||
@@ -118,7 +120,7 @@ const (
|
||||
_ErrCode_name_3 = "禁止访问"
|
||||
_ErrCode_name_4 = "参数无效appid参数无效密文校验失败,aa用户名不存在或密码错误键值对重复未找到无效操作授权码错误已被使用已被激活激活码被禁止使用用户已存在验证码请求过于频繁邮箱发送失败手机发送失败手机号格式有问题验证码错误用户不存在topic已经存在topic不存在bundle_id不存在topic开启处理失败topic处理类型不存在topic不能为空设备不存在"
|
||||
_ErrCode_name_5 = "状态已存在上级菜单不存在菜单不存在用户权限不存在设备ID不存在商品处理类型不存在商品不存在商品正在打折商品可支付类型不存在商品已存在"
|
||||
_ErrCode_name_6 = "订单不存在商品未打折会话不匹配商品已恢复原价邀请用户不存在邀请用户级数已满用户未授权申请人已存在申请人不存在订单无效微信零钱重复提现提现金额错误微信提现失败重复提交bundle已存在权限已存在权限不存在房型不存在房型已存在房间不存在房间已存在房价代码或房价名称已存在房价代码不存在文件不存在房间未启用班次已存在班次不存在系统时间与营业时间不匹配当前班次已交班支付金额错误存量不足数据存储错误数据添加错误数据更新错误数据删除错误时间错误预定信息错误不允许已过期超过最大值低于最小值已存在未绑定绑定失败计算错误token校验失败应用id未找到已经处理解析文件错误缓存异常模板执行错误请不要平凡操作数据为空用户已取消关注"
|
||||
_ErrCode_name_6 = "订单不存在商品未打折会话不匹配商品已恢复原价邀请用户不存在邀请用户级数已满用户未授权申请人已存在申请人不存在订单无效微信零钱重复提现提现金额错误微信提现失败重复提交bundle已存在权限已存在权限不存在房型不存在房型已存在房间不存在房间已存在房价代码或房价名称已存在房价代码不存在文件不存在房间未启用班次已存在班次不存在系统时间与营业时间不匹配当前班次已交班支付金额错误存量不足数据存储错误数据添加错误数据更新错误数据删除错误时间错误预定信息错误不允许已过期超过最大值低于最小值已存在未绑定绑定失败计算错误token校验失败应用id未找到已经处理解析文件错误缓存异常模板执行错误请不要平凡操作数据为空用户已取消关注存在关联状态错误"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -127,7 +129,7 @@ var (
|
||||
_ErrCode_index_2 = [...]uint8{0, 6, 15, 21}
|
||||
_ErrCode_index_4 = [...]uint16{0, 12, 29, 50, 83, 98, 107, 119, 134, 146, 158, 182, 197, 224, 242, 260, 284, 299, 314, 331, 345, 363, 386, 412, 429, 444}
|
||||
_ErrCode_index_5 = [...]uint8{0, 15, 36, 51, 72, 89, 116, 131, 149, 179, 194}
|
||||
_ErrCode_index_6 = [...]uint16{0, 15, 30, 45, 66, 87, 111, 126, 144, 162, 174, 198, 216, 234, 246, 261, 276, 291, 306, 321, 336, 351, 387, 408, 423, 438, 453, 468, 504, 525, 543, 555, 573, 591, 609, 627, 639, 657, 666, 675, 690, 705, 714, 723, 735, 747, 764, 781, 793, 811, 823, 841, 862, 874, 895}
|
||||
_ErrCode_index_6 = [...]uint16{0, 15, 30, 45, 66, 87, 111, 126, 144, 162, 174, 198, 216, 234, 246, 261, 276, 291, 306, 321, 336, 351, 387, 408, 423, 438, 453, 468, 504, 525, 543, 555, 573, 591, 609, 627, 639, 657, 666, 675, 690, 705, 714, 723, 735, 747, 764, 781, 793, 811, 823, 841, 862, 874, 895, 907, 919}
|
||||
)
|
||||
|
||||
func (i ErrCode) String() string {
|
||||
@@ -149,7 +151,7 @@ func (i ErrCode) String() string {
|
||||
case 1027 <= i && i <= 1036:
|
||||
i -= 1027
|
||||
return _ErrCode_name_5[_ErrCode_index_5[i]:_ErrCode_index_5[i+1]]
|
||||
case 1043 <= i && i <= 1096:
|
||||
case 1043 <= i && i <= 1098:
|
||||
i -= 1043
|
||||
return _ErrCode_name_6[_ErrCode_index_6[i]:_ErrCode_index_6[i+1]]
|
||||
default:
|
||||
|
101
weixin/base.go
101
weixin/base.go
@@ -19,17 +19,19 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
_getTicket = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card&access_token="
|
||||
_getJsurl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token="
|
||||
_getToken = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
|
||||
_getSubscribe = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="
|
||||
_getTempMsg = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
|
||||
_createMenu = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="
|
||||
_deleteMenu = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token="
|
||||
_sendCustom = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="
|
||||
_setGuideConfig = "https://api.weixin.qq.com/cgi-bin/guide/setguideconfig?access_token="
|
||||
_cacheToken = "wx_access_token"
|
||||
_cacheTicket = "weixin_card_ticket"
|
||||
_getTicket = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=wx_card&access_token="
|
||||
_getJsurl = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?type=jsapi&access_token="
|
||||
_getToken = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="
|
||||
_getSubscribe = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token="
|
||||
_getTempMsg = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="
|
||||
_createMenu = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token="
|
||||
_deleteMenu = "https://api.weixin.qq.com/cgi-bin/menu/delete?access_token="
|
||||
_sendCustom = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token="
|
||||
_sendFreepublish = "https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token="
|
||||
_setGuideConfig = "https://api.weixin.qq.com/cgi-bin/guide/setguideconfig?access_token="
|
||||
_getUser = "https://api.weixin.qq.com/cgi-bin/user/get?access_token="
|
||||
_cacheToken = "wx_access_token"
|
||||
_cacheTicket = "weixin_card_ticket"
|
||||
)
|
||||
|
||||
// GetAccessToken 获取微信accesstoken
|
||||
@@ -302,3 +304,80 @@ func (_wx *wxTools) GetJsSign(url string) (*WxJsSign, error) {
|
||||
jsSign.Signature = fmt.Sprintf("%x", h.Sum(nil))
|
||||
return jsSign, nil
|
||||
}
|
||||
|
||||
// GetAllOpenId 获取用户列表
|
||||
func (_wx *wxTools) GetAllOpenId() ([]string, error) {
|
||||
accessToken, err := _wx.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
nextOpenid := ""
|
||||
var out []string
|
||||
|
||||
for {
|
||||
url := _getUser + accessToken
|
||||
if len(nextOpenid) > 0 {
|
||||
url += fmt.Sprintf("&next_openid=%v", nextOpenid)
|
||||
}
|
||||
var tmp WxGetUser
|
||||
b := myhttp.SendGet(url, "", &tmp)
|
||||
if !b {
|
||||
return nil, fmt.Errorf("GetAllOpenId error: res:%v", b)
|
||||
}
|
||||
out = append(out, tmp.Data.Openid...)
|
||||
nextOpenid = tmp.Data.NextOpenid
|
||||
if len(nextOpenid) == 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// GetFreepublish 获取用户列表
|
||||
func (_wx *wxTools) GetFreepublish(max int64) (out []FreepublishiInfo, err error) {
|
||||
accessToken, err := _wx.GetAccessToken()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req := FreepublishiInfoReq{
|
||||
Offset: 0,
|
||||
Count: 20,
|
||||
NoContent: 1,
|
||||
}
|
||||
if req.Count > max {
|
||||
req.Count = max
|
||||
}
|
||||
for {
|
||||
bo, _ := json.Marshal(req)
|
||||
resb, _ := myhttp.OnPostJSON(_sendFreepublish+accessToken, string(bo))
|
||||
var res FreepublishiInfoResp
|
||||
json.Unmarshal(resb, &res)
|
||||
if res.ItemCount == 0 {
|
||||
break
|
||||
}
|
||||
|
||||
for _, v := range res.Item {
|
||||
var item FreepublishiInfo
|
||||
item.ArticleId = v.ArticleId
|
||||
item.UpdateTime = v.UpdateTime
|
||||
for _, v := range v.Content.NewsItem {
|
||||
item.Title = v.Title
|
||||
item.Author = v.Author
|
||||
item.Digest = v.Digest
|
||||
item.ContentSourceUrl = v.ContentSourceUrl
|
||||
item.Url = v.Url
|
||||
item.IsDeleted = v.IsDeleted
|
||||
out = append(out, item)
|
||||
}
|
||||
}
|
||||
if len(out) >= int(max) {
|
||||
break
|
||||
}
|
||||
req.Offset = req.Count
|
||||
req.Count += 20
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
@@ -171,3 +171,56 @@ type WxJsSign struct {
|
||||
Url string `json:"url"`
|
||||
Signature string `json:"signature"`
|
||||
}
|
||||
|
||||
type WxGetUser struct {
|
||||
Total int64 `json:"total"`
|
||||
Count int64 `json:"count"`
|
||||
Data WxGetUserData `json:"data"`
|
||||
}
|
||||
|
||||
type WxGetUserData struct {
|
||||
Openid []string `json:"openid"`
|
||||
NextOpenid string `json:"next_openid"`
|
||||
}
|
||||
|
||||
type FreepublishiInfo struct { // 公众号文章
|
||||
ArticleId string `json:"article_id"` // 成功发布的图文消息id
|
||||
Title string `json:"title"` // 文章标题
|
||||
Author string `json:"author"` // 作者
|
||||
Digest string `json:"digest"` // 摘要
|
||||
ContentSourceUrl string `json:"content_source_url"` // 图文消息的原文地址,即点击“阅读原文”后的URL
|
||||
Url string `json:"url"` // 图文消息的URL
|
||||
IsDeleted bool `json:"is_deleted"` // 该图文是否被删除
|
||||
UpdateTime int64 `json:"update_time"` // 更新时间
|
||||
}
|
||||
|
||||
type FreepublishiInfoReq struct {
|
||||
Offset int64 `json:"offset"`
|
||||
Count int64 `json:"count"`
|
||||
NoContent int64 `json:"no_content"`
|
||||
}
|
||||
|
||||
type FreepublishiInfoResp struct {
|
||||
TotalCount int `json:"total_count"`
|
||||
ItemCount int `json:"item_count"`
|
||||
Item []FreepublishiInfoItem `json:"item"`
|
||||
}
|
||||
|
||||
type FreepublishiInfoItem struct {
|
||||
ArticleId string `json:"article_id"` // 成功发布的图文消息id
|
||||
UpdateTime int64 `json:"update_time"` // 更新时间
|
||||
Content FreepublishiInfoContent `json:"content"`
|
||||
}
|
||||
|
||||
type FreepublishiInfoContent struct {
|
||||
NewsItem []FreepublishiInfoNewItem `json:"news_item"` // 成功发布的图文消息id
|
||||
}
|
||||
|
||||
type FreepublishiInfoNewItem struct {
|
||||
Title string `json:"title"` // 文章标题
|
||||
Author string `json:"author"` // 作者
|
||||
Digest string `json:"digest"` // 再要
|
||||
ContentSourceUrl string `json:"content_source_url"` // 图文消息的原文地址,即点击“阅读原文”后的URL
|
||||
Url string `json:"url"` // 图文消息的URL
|
||||
IsDeleted bool `json:"is_deleted"` // 该图文是否被删除
|
||||
}
|
||||
|
@@ -33,7 +33,8 @@ type WxTools interface {
|
||||
WxEnterprisePay(openID, tradeNO, desc, ipAddr string, amount int) bool // 企业付款
|
||||
GetShareQrcode(path string, scene, page string) (ret QrcodeRet) // 获取小程序码
|
||||
GetWxQrcode(path, page string, width int) (ret QrcodeRet) // 获取小程序二维码 (有限个)
|
||||
|
||||
GetAllOpenId() ([]string, error) // 获取所有用户id
|
||||
GetFreepublish(max int64) ([]FreepublishiInfo, error) // 获取成功发布列表,最大条数
|
||||
// --------------------h5------------------------------
|
||||
GetWebOauth(code string) (*AccessToken, error) // 授权
|
||||
GetWebUserinfo(openid, accessToken string) (*WxUserinfo, error) // 获取用户信息
|
||||
|
Reference in New Issue
Block a user