使用golang每天給女朋友發送微信信息


使用golang每天給女朋友發送微信信息

我們使用github.com/eatMoreApple/openwechat就可以使用golang操作微信發送消息了

package main

import (
	"fmt"
	"github.com/eatMoreApple/openwechat"
	"time"
)

func sendMessageToGirlFriend(gf *openwechat.Friend) {
	for {
		now := time.Now()
		t := time.Date(now.Year(), now.Month(), now.Day(), 6, 20, 0, 0, now.Location())
		timer := time.NewTimer(now.Sub(t))
		<-timer.C
		gf.SendText("早安~")
		break
	}
}

func main() {
	bot := openwechat.DefaultBot()

	// 注冊消息處理函數
	bot.MessageHandler = func(msg *openwechat.Message) {
		if msg.IsText() && msg.Content == "ping" {
			msg.ReplyText("pong")
		}
	}
	// 注冊登陸二維碼回調
	bot.UUIDCallback = openwechat.PrintlnQrcodeUrl

	// 登陸
	if err := bot.Login(); err != nil {
		fmt.Println(err)
		return
	}

	// 獲取登陸的用戶
	self, err := bot.GetCurrentUser()
	if err != nil {
		fmt.Println(err)
		return
	}

	// 獲取所有的好友
	friends, err := self.Friends()

	if err != nil {
		fmt.Println(err)
		return
	}

	girlFriend := friends.SearchByRemarkName(1, "二愣子")

	if girlFriend.Count() > 0 {
		go sendMessageToGirlFriend(girlFriend.First())
	}
	bot.Block()
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM