天气返回 json

This commit is contained in:
youspectrum 2022-10-09 20:54:48 +08:00
parent fa40c5691d
commit 89ad3b1851
5 changed files with 66 additions and 0 deletions

28
controller/weather.go Normal file
View File

@ -0,0 +1,28 @@
package controller
import (
"fmt"
"github.com/eatmoreapple/openwechat"
"github.com/kirinlabs/HttpRequest"
)
type name struct {
weatherAPI string "https://dashboard.caiyunapp.com/"
}
func GetWeather(msg *openwechat.Message, self *openwechat.Self) {
get, err := HttpRequest.JSON().Get("https://api.caiyunapp.com/v2.6/y1BgC9gnutIzXlZF/126.62,45.62/realtime?alert=true")
if err != nil {
}
body, err := get.Body()
if err != nil {
}
groups, err := self.Groups()
name := groups.GetByNickName("叫啥好呢")
fmt.Printf(name.NickName, err)
self.SendTextToGroup(name, string(body))
}

1
go.mod
View File

@ -5,6 +5,7 @@ go 1.18
require ( require (
github.com/eatmoreapple/openwechat v1.1.11 github.com/eatmoreapple/openwechat v1.1.11
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
github.com/kirinlabs/HttpRequest v1.1.1
github.com/robfig/cron/v3 v3.0.0 github.com/robfig/cron/v3 v3.0.0
github.com/satori/go.uuid v1.2.0 github.com/satori/go.uuid v1.2.0
) )

2
go.sum
View File

@ -2,6 +2,8 @@ github.com/eatmoreapple/openwechat v1.1.11 h1:YJL8tUenK1NTflNPt5lWOl0KWcP0CTGjWN
github.com/eatmoreapple/openwechat v1.1.11/go.mod h1:61HOzTyvLobGdgWhL68jfGNwTJEv0mhQ1miCXQrvWU8= github.com/eatmoreapple/openwechat v1.1.11/go.mod h1:61HOzTyvLobGdgWhL68jfGNwTJEv0mhQ1miCXQrvWU8=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/kirinlabs/HttpRequest v1.1.1 h1:eBbFzpRd/Y7vQhRY30frHK3yAJiT1wDlB31Ryzyklc0=
github.com/kirinlabs/HttpRequest v1.1.1/go.mod h1:XV38fA4rXZox83tlEV9KIQ7Cdsut319x6NGzVLuRlB8=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI= github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=

26
gotest/weather_test.go Normal file
View File

@ -0,0 +1,26 @@
package gotest
import (
"fmt"
"github.com/kirinlabs/HttpRequest"
"testing"
)
type weather struct {
status string
result string
}
func Test_we(t *testing.T) {
get, err := HttpRequest.JSON().Get("https://api.caiyunapp.com/v2.6/y1BgC9gnutIzXlZF/126.62,45.62/realtime?alert=true")
if err != nil {
return
}
body, err := get.Body()
if err != nil {
return
}
s := string(body)
fmt.Println(s)
}

View File

@ -64,6 +64,10 @@ func main() {
controller.SignIn(msg, self) controller.SignIn(msg, self)
} }
if split[0] == "天气" {
controller.GetWeather(msg, self)
}
if split[0] == "school" && split[1] == "start" { if split[0] == "school" && split[1] == "start" {
controller.SchoolSignInBegin(msg, self) controller.SchoolSignInBegin(msg, self)
} }
@ -74,6 +78,11 @@ func main() {
if split[0] == "我的信息" { if split[0] == "我的信息" {
controller.GetUsers(msg, self) controller.GetUsers(msg, self)
} }
if split[0] == "all start" {
controller.SignInBegin(msg, self)
controller.SchoolSignInBegin(msg, self)
}
} }
} }