|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"fmt" |
|
|
"fmt" |
|
|
"log" |
|
|
"log" |
|
|
|
|
|
"os" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func serveCommand(openID string, in InWechatMsg) (state chatState, processed bool) { |
|
|
func serveCommand(openID string, in InWechatMsg) (state chatState, processed bool) { |
|
|
|
|
|
|
|
|
str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) |
|
|
str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) |
|
|
case LocationMsg: |
|
|
case LocationMsg: |
|
|
m := in.body.(LocationMsg) |
|
|
m := in.body.(LocationMsg) |
|
|
str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale)) |
|
|
|
|
|
|
|
|
mid := location2MediaID(m.Location_X, m.Location_Y) |
|
|
|
|
|
//str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scale=%d", m.Location_X, m.Location_Y, m.Scale)) |
|
|
|
|
|
// str = buildPicMsg(openID, mid) |
|
|
|
|
|
url := location2URL(m.Location_X, m.Location_Y) |
|
|
|
|
|
str, _ = BuildTextMsg(openID, mid+"\r\n"+url) |
|
|
|
|
|
kfSendTxt(openID, url) |
|
|
|
|
|
|
|
|
|
|
|
case LinkMsg: |
|
|
|
|
|
m := in.body.(LinkMsg) |
|
|
|
|
|
kfSendTxt(openID, m.Title+m.Description) |
|
|
|
|
|
str, _ = BuildTextMsg(openID, m.Url) |
|
|
case EventMsg: |
|
|
case EventMsg: |
|
|
m := in.body.(EventMsg) |
|
|
|
|
|
log.Println(m) |
|
|
|
|
|
url := fmt.Sprintf("https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&markers=color:red|label:S|%f,%f&zoom=12&size=414x736", m.Latitude, m.Longitude, m.Latitude, m.Longitude) |
|
|
|
|
|
log.Println(url) |
|
|
|
|
|
file, _, _ := saveURL(url) |
|
|
|
|
|
str = buildUploadPicMsg(openID, file) |
|
|
|
|
|
//str, _ = BuildTextMsg(openID, fmt.Sprintf("long=%f, lat=%f, scal =%f", m.Longitude, m.Latitude, m.Precision)) |
|
|
|
|
|
|
|
|
return echoEvents(openID, in) |
|
|
default: |
|
|
default: |
|
|
str, err = BuildTextMsg(openID, "text message") |
|
|
str, err = BuildTextMsg(openID, "text message") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//state is any state that |
|
|
//state is any state that |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func echoEvents(openID string, in InWechatMsg) (state chatState, processed bool) { |
|
|
|
|
|
processed = true |
|
|
|
|
|
str := "" |
|
|
|
|
|
m := in.body.(EventMsg) |
|
|
|
|
|
log.Println("Event = " + m.Event) |
|
|
|
|
|
switch m.Event { |
|
|
|
|
|
case "LOCATION": |
|
|
|
|
|
mid := location2MediaID(m.Latitude, m.Longitude) |
|
|
|
|
|
str = buildPicMsg(openID, mid) |
|
|
|
|
|
case "CLICK": |
|
|
|
|
|
str, _ = BuildTextMsg(openID, m.EventKey) |
|
|
|
|
|
case "subscribe": |
|
|
|
|
|
case "unsubscribe": |
|
|
|
|
|
case "SCAN": |
|
|
|
|
|
case "VIEW": |
|
|
|
|
|
default: |
|
|
|
|
|
str, _ = BuildTextMsg(openID, " unknown event :"+m.Event) |
|
|
|
|
|
} |
|
|
|
|
|
state.response = str |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func location2MediaID(lat, long float64) (mediaID string) { |
|
|
|
|
|
url := fmt.Sprintf("https://maps.googleapis.com/maps/api/staticmap?center=%f,%f&markers=color:red|label:S|%f,%f&zoom=17&size=1280x2014", lat, long, lat, long) |
|
|
|
|
|
file, _, _ := saveURL(url) |
|
|
|
|
|
mediaID = uploadImage(file) |
|
|
|
|
|
os.Remove(file) |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func location2URL(lat, long float64) (url string) { |
|
|
|
|
|
url = fmt.Sprintf("http://maps.google.com/maps?z=12&t=m&q=loc:%f+%f", lat, long) |
|
|
|
|
|
log.Println(url) |
|
|
|
|
|
return |
|
|
|
|
|
} |