Browse Source

no message

zhangchuanxing 3 tháng trước cách đây
mục cha
commit
bf3cdccec4
3 tập tin đã thay đổi với 142 bổ sung0 xóa
  1. 127 0
      controllers/wechat.go
  2. 7 0
      models/user.go
  3. 8 0
      models/user_record.go

+ 127 - 0
controllers/wechat.go

@@ -529,3 +529,130 @@ func (this *WechatCommonController) Notify() {
 		this.Ctx.WriteString(echostr)
 	}
 }
+
+//type DataOpenidArr struct {
+//	Data OpenidArr `json:"data"`
+//}
+//
+//type OpenidArr struct {
+//	Openid []string `json:"openid"`
+//}
+//
+//func init() {
+//	access_token := "87_vfOIH2qwWI6cYG584J-SQklN5r5_HelQeLToq-ZNbb4LOl3SnxKSIH6qMfbljvOI9tTWTv0e9t2Gq41-u_WJhYyFzm7rH7bhRYaMhqaU713Wx9qhPfpbTb506GYXMLcAFAODC"
+//	url := "https://api.weixin.qq.com/cgi-bin/user/get?access_token=" + access_token
+//	method := "GET"
+//	client := &http.Client{}
+//	req, err := http.NewRequest(method, url, nil)
+//
+//	if err != nil {
+//		fmt.Println(err)
+//		return
+//	}
+//	res, err := client.Do(req)
+//	if err != nil {
+//		fmt.Println(err)
+//		return
+//	}
+//	defer res.Body.Close()
+//
+//	body, err := ioutil.ReadAll(res.Body)
+//	if err != nil {
+//		fmt.Println(err)
+//		return
+//	}
+//	item := new(DataOpenidArr)
+//	err = json.Unmarshal(body, &item)
+//	fmt.Println(len(item.Data.Openid))
+//
+//	//var condition string
+//	//var pars []interface{}
+//	//
+//	//condition = ` AND open_id IN (` + utils.GetOrmInReplace(len(item.Data.Openid)) + `)     `
+//	//pars = append(pars, item.Data.Openid)
+//	//
+//	//listUserRecord, err := models.GetUserRecordList(condition, pars)
+//	//if err != nil {
+//	//	fmt.Println(err)
+//	//	return
+//	//}
+//	accessToken, err := services.GetWxAccessTokenByGzh()
+//	for k, v := range item.Data.Openid {
+//		//if k > 1 {
+//		//	return
+//		//}
+//
+//		fmt.Println(k, "___", v)
+//		openId := v
+//
+//		wxUserInfo, err := services.WxGetUserInfo(openId, accessToken)
+//		if err != nil {
+//			utils.FileLog.Info("accessToken:" + err.Error())
+//			return
+//		}
+//		SubscribeTime := time.Unix(int64(wxUserInfo.SubscribeTime), 0).Format(utils.FormatDateTime)
+//		fmt.Println(SubscribeTime)
+//		if wxUserInfo.Errcode != 0 {
+//			userInfoJson, _ := json.Marshal(wxUserInfo)
+//			fmt.Println("获取用户信息失败,err:" + string(userInfoJson))
+//		}
+//		unionId := wxUserInfo.Unionid
+//		wxUser, err := models.GetUserRecordByUnionId(unionId)
+//		if err != nil {
+//			utils.FileLog.Info("GetUserDetailBuOpenid:" + err.Error())
+//		}
+//		if wxUser == nil {
+//			continue
+//		}
+//		if wxUser.UserId == 0 {
+//			continue
+//		}
+//
+//		items := new(models.CygxMfyxGzhUserRecord)
+//		items.OpenId = openId
+//		items.UnionId = unionId
+//		items.NickName = wxUserInfo.Nickname
+//		items.Sex = wxUserInfo.Sex
+//		items.Province = wxUserInfo.Province
+//		items.City = wxUserInfo.City
+//		items.Country = wxUserInfo.Country
+//		items.Headimgurl = wxUserInfo.Headimgurl
+//		items.CreateTime = time.Now()
+//		items.Subscribe = 1
+//		items.SubscribeTime = time.Unix(int64(wxUserInfo.SubscribeTime), 0)
+//		items.CygxUserId = wxUser.UserId
+//		items.CygxBindAccount = wxUser.BindAccount
+//
+//		total, err := models.GetCygxUserRecordCount(openId)
+//		if total == 0 {
+//			_, err = models.AddMfyxGzhUserRecord(items)
+//		}
+//
+//		userRecord := &models.UserRecord{
+//			OpenId:         openId,  //用户open_id
+//			UnionId:        unionId, //用户union_id
+//			Subscribe:      1,
+//			NickName:       wxUserInfo.Nickname,   //用户昵称,最大长度:32
+//			RealName:       "",                    //用户实际名称,最大长度:32
+//			Sex:            wxUserInfo.Sex,        //普通用户性别,1为男性,2为女性
+//			Province:       wxUserInfo.Province,   //普通用户个人资料填写的省份,最大长度:30
+//			City:           wxUserInfo.City,       //普通用户个人资料填写的城市,最大长度:30
+//			Country:        wxUserInfo.Country,    //国家,如中国为CN,最大长度:30
+//			Headimgurl:     wxUserInfo.Headimgurl, //用户第三方(微信)头像,最大长度:512
+//			CreateTime:     time.Now(),            //创建时间,关系添加时间、用户授权时间
+//			CreatePlatform: 12,                    //注册平台,1:日度点评公众号,2:管理后台,3:pc端网站,4:查研观向小程序;默认:1
+//			SessionKey:     wxUserInfo.SessionKey, //微信小程序会话密钥,最大长度:255
+//		}
+//		userRecord.UserId = wxUser.UserId
+//		totalUserRecord, err := models.GetUserRecordCount(openId)
+//		if totalUserRecord == 0 {
+//			_, err = models.AddUserRecord(userRecord)
+//		}
+//
+//		fmt.Println("关注")
+//		models.UserSubscribeInit(1, wxUser.UserId, SubscribeTime)
+//		//go models.CygxUserSubscribe(1, unionId)
+//	}
+//
+//	fmt.Println("end")
+//}

+ 7 - 0
models/user.go

@@ -129,6 +129,13 @@ func UserSubscribe(subscribeType, userId int) (err error) {
 	return
 }
 
+func UserSubscribeInit(subscribeType, userId int, mfyx_subscribe_time string) (err error) {
+	o := orm.NewOrmUsingDB("weekly_report")
+	sql := `UPDATE wx_user SET mfyx_subscribe=?,mfyx_subscribe_time=? WHERE user_id = ? `
+	_, err = o.Raw(sql, subscribeType, mfyx_subscribe_time, userId).Exec()
+	return
+}
+
 func CygxUserSubscribe(subscribeType int, unionid string) (err error) {
 	o := orm.NewOrm()
 	sql := `UPDATE cygx_mfyx_gzh_user_record SET subscribe=?,subscribe_time=NOW() WHERE union_id = ? `

+ 8 - 0
models/user_record.go

@@ -40,6 +40,14 @@ func GetUserRecordByUnionId(unionId string) (item *UserRecord, err error) {
 	return
 }
 
+// 获取数量
+func GetUserRecordCount(openId string) (count int, err error) {
+	o := orm.NewOrmUsingDB("weekly_report")
+	sqlCount := ` SELECT COUNT(1) AS count  FROM user_record WHERE open_id=? `
+	err = o.Raw(sqlCount, openId).QueryRow(&count)
+	return
+}
+
 // 根据用户id和平台id获取用户关系
 func GetUserRecordByUserOpenId(open_id string) (item *UserRecord, err error) {
 	o := orm.NewOrmUsingDB("weekly_report")