diff --git a/sample_data/samplemenu.json b/sample_data/samplemenu.json new file mode 100644 index 0000000..8d58a67 --- /dev/null +++ b/sample_data/samplemenu.json @@ -0,0 +1,94 @@ +{ + "button": [ + { + "name": "会员信息", + "sub_button": [ + { + "type": "click", + "name": "我的会员资料", + "key": "MEMBER_MYPROFILE" + }, + { + "type": "click", + "name": "积分和账单", + "key": "MEMBER_CREDITS" + }, + { + "type": "click", + "name": "搜索其他会员信息", + "key": "MEMBER_SEARCH" + }, + { + "type": "click", + "name": "广播给所有会员", + "key": "MEMBER_BROADCAST" + }, + { + "type": "VIEW", + "name": "校友会主页", + "url": "https://www.hitxy.org.au/" + } + ] + }, + { + "name": "组织活动", + "sub_button": [ + { + "type": "click", + "name": "我来发起一次活动", + "key": "EVENT_STARTONE" + }, + { + "type": "click", + "name": "参与直播活动", + "key": "EVENT_CONTRIBUTEPHOTO" + }, + { + "type": "click", + "name": "签到当前活动", + "key": "EVENT_CHECKIN" + }, + { + "type": "click", + "name": "参与幸运抽奖", + "key": "EVENT_LUCKYDRAW" + }, + { + "type": "click", + "name": "即将举办的活动", + "key": "EVENTS_UPCOMING" + } + ] + }, + { + "name": "职业发展", + "sub_button": [ + { + "type": "click", + "name": "澳洲工作机会", + "key": "CAREERDEV_JOBS" + }, + { + "type": "click", + "name": "融入澳洲社区", + "key": "CARDEV_INDUSTRY" + }, + { + "type": "click", + "name": "OutReach Program", + "key": "CARDEV_OUTREACH" + }, + { + "type": "click", + "name": "母校发展机会", + "key": "CARDEV_HIT" + }, + { + "type": "click", + "name": "全球发展机会", + "key": "CARDEV_GLOBAL" + } + ] + } + ] +} \ No newline at end of file diff --git a/serveCommand.go b/serveCommand.go index 5961b56..f8df67c 100644 --- a/serveCommand.go +++ b/serveCommand.go @@ -3,6 +3,7 @@ package main import ( "fmt" "log" + "os" ) func serveCommand(openID string, in InWechatMsg) (state chatState, processed bool) { @@ -34,15 +35,19 @@ func echoCommand(openID string, in InWechatMsg) (state chatState, processed bool str = buildVideoMsg(openID, "e2iNEiSxCX5TV1WbFd0TQMn5lilY3bylh1--lDBwi7I", "航拍春日哈工大", m.MediaId) case 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: - 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: str, err = BuildTextMsg(openID, "text message") } @@ -58,3 +63,39 @@ func echoCommand(openID string, in InWechatMsg) (state chatState, processed bool //state is any state that 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 +}