123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- package services
- import (
- "encoding/json"
- "errors"
- "fmt"
- "github.com/rdlucklib/rdluck_tools/http"
- "hongze/hongze_mfyx_gzh/models"
- "hongze/hongze_mfyx_gzh/utils"
- )
- type WxUsers struct {
- WxBase
- Total int
- Count int
- Data struct {
- Openid []string
- }
- NextOpenid string `json:"next_openid"`
- }
- // 微信接口基础返回数据
- type WxBase struct {
- Errcode int
- Errmsg string
- }
- func WxUsersGetV1() (openIdList []string) {
- accessToken := "68_Vybgr0jXdiqCJW7NjEROyrSAGT-txiflR9QSKn-9BRo-dAWsuDwwh-Adn2MUqRgrWDwusQx4F_IdB5aWCtFKAvJ6roWrSbP0F98PIMX1drK0Dv9xpSbKsS3PCkUMGNcAIABVC"
- //关注的openid切片
- openIdList = make([]string, 0)
- //下一个openid
- nextOpenid := ""
- QUERY_WX:
- url := "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken + "&next_openid=" + nextOpenid
- result, err := http.Get(url)
- if err != nil {
- utils.FileLog.Info("GetUser Err:", err.Error())
- return
- }
- item := new(WxUsers)
- err = json.Unmarshal(result, &item)
- if err != nil {
- fmt.Println("Unmarshal Err:", err.Error())
- return
- }
- if item.Errcode != 0 {
- utils.FileLog.Info("微信接口返回异常 Err:", item.Errmsg)
- return
- }
- err = errors.New(item.Errmsg)
- openIdList = append(openIdList, item.Data.Openid...)
- //如果数量大于10000条,同时下个openid不为空,那么继续查询
- if item.Count >= 10000 && item.NextOpenid != "" {
- nextOpenid = item.NextOpenid
- goto QUERY_WX
- }
- return openIdList
- }
- func init231() {
- list, err := models.GetCygxUserRecordyList()
- if err != nil {
- fmt.Println(err)
- return
- }
- var unionIds []string
- var condition string
- var pars []interface{}
- for _, v := range list {
- unionIds = append(unionIds, v.UnionId)
- }
- condition = ` AND union_id IN (` + utils.GetOrmInReplace(len(unionIds)) + `) AND create_platform = 4 `
- pars = append(pars, unionIds)
- listUserRecord, err := models.GetUserRecordList(condition, pars)
- if err != nil {
- fmt.Println(err)
- return
- }
- mapMobil := make(map[string]string)
- mapUserId := make(map[string]int)
- for _, v := range listUserRecord {
- mapMobil[v.UnionId] = v.BindAccount
- mapUserId[v.UnionId] = v.UserId
- }
- fmt.Println(len(list))
- fmt.Println(len(listUserRecord))
- for _, v := range listUserRecord {
- fmt.Println(mapUserId[v.UnionId], "————", mapMobil[v.UnionId])
- err = models.UpdateCygxUserRecordMobile(mapUserId[v.UnionId], mapMobil[v.UnionId], v.UnionId)
- if err != nil {
- fmt.Println(err)
- return
- }
- }
- }
|