zoukankan      html  css  js  c++  java
  • 使用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()
    }
    
    
  • 相关阅读:
    passenger中的设置ssl
    memcached在rails中的使用介绍
    redis相关
    复制linode镜像
    memcached启动 安装
    A Short History of Character Sets
    du h df h 磁盘空间满处理办法
    硬盘2T 现在也才不到1000了,变得感觉太便宜了
    最近爬虫心得
    20110205网站更新部署过程记录
  • 原文地址:https://www.cnblogs.com/ivy-blogs/p/14873494.html
Copyright © 2011-2022 走看看