| }, | }, | ||||
| { | { | ||||
| "type":"click", | "type":"click", | ||||
| "name":"积分和账单", | |||||
| "name":"积分/余额", | |||||
| "key": "MEMBER_CREDITS" | "key": "MEMBER_CREDITS" | ||||
| }, | }, | ||||
| { | { |
| package main | package main | ||||
| func onClick(in* InWechatMsg) { | |||||
| import "time" | |||||
| func onClick(ss *openIDSessionData, in *InWechatMsg) { | |||||
| e := in.body.(EventMsg) | e := in.body.(EventMsg) | ||||
| openid := in.header.FromUserName | openid := in.header.FromUserName | ||||
| switch e.EventKey { | switch e.EventKey { | ||||
| case "MEMBER_MYPROFILE": | case "MEMBER_MYPROFILE": | ||||
| kfSendTxtAs(openid, "profile", "孙鹏") | |||||
| //kfSendTxtAs(openid, "profile", "孙鹏") | |||||
| startProc(AllProc["用户信息"], ss, in) | |||||
| case "MEMBER_CREDITS": | case "MEMBER_CREDITS": | ||||
| kfSendTxtAs(openid, "没有余额", "孙鹏") | |||||
| onMembeCredits(ss, in) | |||||
| case "MEMBER_SEARCH": | case "MEMBER_SEARCH": | ||||
| kfSendTxtAs(openid, "搜索", "孙鹏") | kfSendTxtAs(openid, "搜索", "孙鹏") | ||||
| case "MEMBER_FEEDBACK": | case "MEMBER_FEEDBACK": | ||||
| } | } | ||||
| } | } | ||||
| func onMembeCredits(ss *openIDSessionData, in *InWechatMsg) { | |||||
| msg := ` | |||||
| 积分是您对校友会的贡献记录,积分越高对校友会的贡献越大,也是对所有对校友会无私奉献的一种公开认可。 | |||||
| 积分可以通过校友会兑换成现金或纪念品。 | |||||
| 余额是您在校友会活动中的奖金余额,根据活动内容,以现金,卡,或者礼物的形式兑现。 | |||||
| ` | |||||
| kfSendTxtAs(ss.OpenID, msg, "孙鹏") | |||||
| info, found, err := crmFindLeadByOpenID(ss.OpenID) | |||||
| if found && err == nil { | |||||
| url := "" | |||||
| first := "截至" + time.Now().Format("2006-01-02 15:04:06 Mon MST -07") + " 您的积分,奖品,余额,如下\n\n" + | |||||
| "积分:无" | |||||
| name := info.LastName | |||||
| addr := info.EmailAddress | |||||
| card := info.ID | |||||
| balance := "澳币 $0 " | |||||
| remark := "奖品:无\n\n余额可联络财务兑现,奖品余额30过期" + "\n请确保您的姓名,地址信息正确" | |||||
| templateSendAccountBalance(ss.OpenID, url, first, remark, name, addr, card, balance) | |||||
| } | |||||
| } |
| //WechatTemplates Message templates and their ID | //WechatTemplates Message templates and their ID | ||||
| var WechatTemplates = map[string]templatesIDInfo{ | var WechatTemplates = map[string]templatesIDInfo{ | ||||
| "join_community": {"12", "成功加入社群提醒", "yNKEqc7n-h1Y1DytmjUT5-H4s1zBK4nBIrYb8_jc2gM"}, | |||||
| "checkin_success": {"03", "签到成功提醒", "8KZLIQnB5e0QJWTtEeSOxGKHoxMaB5T1_GA8iDSLiI4"}, | |||||
| "join_volunteer": {"01", "成功加入志愿者通知", "1xgZoxZgnebXAddQ_MXSThpZt3bJ_e4XonCf2F4EETY"}, | |||||
| "join_team": {"02", "团队加入成功通知", "3Jw3jdlbDOK9ggWFcDfmi2QkytSJP4YjYWrBByWT-0M"}, | |||||
| "meeting_reminder": {"04", "会议通知", "8goDRUgmfxGWZgZQQCmveXqSnnqeqymIf6Rm1Ywfxsk"}, | |||||
| "checking_reminder": {"05", "签到提醒", "RQ9hQLoz8DkVRowPg-RmUD3zw9pi9QsEuzDtgfHm8sc"}, | |||||
| "enroll_success": {"06", "活动报名成功提醒", "S1tLShojLb9hpofSdaUAF9HNADo9gcwuWkYqkLzWPP4"}, | |||||
| "memberfee_reminder": {"08", "会员缴费提醒", "i40L7lXUsUK_hSs8quTwDelbXAigOGAPxkSe23Fg8Hk"}, | |||||
| "payment_successful": {"09", "缴费成功通知", "ubMQT9db4HgUCZrYiei20lr25Be3oOYT3YziOFG_PdI"}, | |||||
| "checkin_failure": {"10", "签到失败提醒", "x0oZxM05A7DKKxQOt6x1AvgbKC0W1G7l2nwMy65rD0w"}, | |||||
| "form_fillup_done": {"07", "录入完整提醒", "X82K3kvOhbOLmMjtKJzAhKnLUi1C0xQFab2mqs30H1k"}, | |||||
| "inform_collection": {"11", "物品领取通知", "y4SUrN75QwWCmQfw2gLwgLzeTbhqrSxTm-GkxR16Pro"}, | |||||
| "account_balance": {"01", "账户余额提醒", "-ahcu4myuJyf2FKW-eq7jdgwEyOeXA8wP4VzixRnUtQ"}, | |||||
| "join_volunteer": {"02", "成功加入志愿者通知", "1xgZoxZgnebXAddQ_MXSThpZt3bJ_e4XonCf2F4EETY"}, | |||||
| "join_team": {"03", "团队加入成功通知", "3Jw3jdlbDOK9ggWFcDfmi2QkytSJP4YjYWrBByWT-0M"}, | |||||
| "checkin_success": {"04", "签到成功提醒", "8KZLIQnB5e0QJWTtEeSOxGKHoxMaB5T1_GA8iDSLiI4"}, | |||||
| "meeting_reminder": {"05", "会议通知", "8goDRUgmfxGWZgZQQCmveXqSnnqeqymIf6Rm1Ywfxsk"}, | |||||
| "checking_reminder": {"06", "签到提醒", "RQ9hQLoz8DkVRowPg-RmUD3zw9pi9QsEuzDtgfHm8sc"}, | |||||
| "enroll_success": {"07", "活动报名成功提醒", "S1tLShojLb9hpofSdaUAF9HNADo9gcwuWkYqkLzWPP4"}, | |||||
| "form_fillup_done": {"08", "录入完整提醒", "X82K3kvOhbOLmMjtKJzAhKnLUi1C0xQFab2mqs30H1k"}, | |||||
| "memberfee_reminder": {"09", "会员缴费提醒", "i40L7lXUsUK_hSs8quTwDelbXAigOGAPxkSe23Fg8Hk"}, | |||||
| "payment_successful": {"10", "缴费成功通知", "ubMQT9db4HgUCZrYiei20lr25Be3oOYT3YziOFG_PdI"}, | |||||
| "checkin_failure": {"11", "签到失败提醒", "x0oZxM05A7DKKxQOt6x1AvgbKC0W1G7l2nwMy65rD0w"}, | |||||
| "inform_collection": {"12", "物品领取通知", "y4SUrN75QwWCmQfw2gLwgLzeTbhqrSxTm-GkxR16Pro"}, | |||||
| "join_community": {"13", "成功加入社群提醒", "yNKEqc7n-h1Y1DytmjUT5-H4s1zBK4nBIrYb8_jc2gM"}, | |||||
| } | } | ||||
| func kfSendTemplateMsg(touser, templateid, url string, data map[string]templateMsgKeyword) (resp string, err error) { | func kfSendTemplateMsg(touser, templateid, url string, data map[string]templateMsgKeyword) (resp string, err error) { | ||||
| data["remark"] = templateMsgKeyword{remark, "#FF0000"} | data["remark"] = templateMsgKeyword{remark, "#FF0000"} | ||||
| return kfSendTemplateMsg(toUser, tid, url, data) | return kfSendTemplateMsg(toUser, tid, url, data) | ||||
| } | } | ||||
| func templateSendAccountBalance(toUser, url, first, remark, name, addr, card, balance string) (resp string, err error) { | |||||
| // {{first.DATA}} | |||||
| // 户名:{{keyword1.DATA}} | |||||
| // 地址:{{keyword2.DATA}} | |||||
| // 卡号:{{keyword3.DATA}} | |||||
| // 余额:{{keyword4.DATA}} | |||||
| // {{remark.DATA}} | |||||
| // 您好,截止上月底您的便民卡余额信息如下 | |||||
| // 户名:王一二 | |||||
| // 地址:市南区宁夏路288号 | |||||
| // 卡号:10000009 | |||||
| // 余额:13.00元 | |||||
| // 感谢您的使用。 | |||||
| tid := getTemplateIDByName("account_balance") | |||||
| data := map[string]templateMsgKeyword{} | |||||
| data["first"] = templateMsgKeyword{first, "#173177"} | |||||
| data["keyword1"] = templateMsgKeyword{name, "#173177"} | |||||
| data["keyword2"] = templateMsgKeyword{addr, "#173177"} | |||||
| data["keyword3"] = templateMsgKeyword{card, "#173177"} | |||||
| data["keyword4"] = templateMsgKeyword{balance, "#173177"} | |||||
| data["remark"] = templateMsgKeyword{remark, "#FF0000"} | |||||
| return kfSendTemplateMsg(toUser, tid, url, data) | |||||
| return | |||||
| } |
| ) | ) | ||||
| func TestSendTemplateJoinVolunteer(t *testing.T) { | func TestSendTemplateJoinVolunteer(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "很高兴有你参加志愿者" | first := "很高兴有你参加志愿者" | ||||
| remark := "明天给你发1万块钱" | remark := "明天给你发1万块钱" | ||||
| } | } | ||||
| func TestSendTemplateJoinTeam(t *testing.T) { | func TestSendTemplateJoinTeam(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "欢迎加入校友会服务团队" | first := "欢迎加入校友会服务团队" | ||||
| remark := "给你发2万张证书" | remark := "给你发2万张证书" | ||||
| } | } | ||||
| func TestSendTemplateCheckinSuccess(t *testing.T) { | func TestSendTemplateCheckinSuccess(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "恭喜签到成功,你是第五位签到者" | first := "恭喜签到成功,你是第五位签到者" | ||||
| remark := "团结向上,一起发展" | remark := "团结向上,一起发展" | ||||
| } | } | ||||
| func TestSendTemplateMsgFormFillupDone(t *testing.T) { | func TestSendTemplateMsgFormFillupDone(t *testing.T) { | ||||
| url := "http://www.google.com.au" | url := "http://www.google.com.au" | ||||
| first := "您的录入信息已经收到,正在核实" | first := "您的录入信息已经收到,正在核实" | ||||
| remark := "若信息有误,会影响您校友会会员的资格" | remark := "若信息有误,会影响您校友会会员的资格" | ||||
| } | } | ||||
| func TestSendTemplateEnrollSuccess(t *testing.T) { | func TestSendTemplateEnrollSuccess(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "即将到来的活动,欢迎你的到来" | first := "即将到来的活动,欢迎你的到来" | ||||
| remark := "怎么才能让校友们积极互动是一个问题" | remark := "怎么才能让校友们积极互动是一个问题" | ||||
| } | } | ||||
| func TestSendTemplateMeetingReminder(t *testing.T) { | func TestSendTemplateMeetingReminder(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "恭喜签到成功,你是第五位签到者" | first := "恭喜签到成功,你是第五位签到者" | ||||
| remark := "怎么才能让校友们积极互动是一个问题" | remark := "怎么才能让校友们积极互动是一个问题" | ||||
| } | } | ||||
| func TestSendTemplateCheckinReminder(t *testing.T) { | func TestSendTemplateCheckinReminder(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "即将到来的活动,欢迎你的到来" | first := "即将到来的活动,欢迎你的到来" | ||||
| remark := "来晚了罚钱,你大爷的" | remark := "来晚了罚钱,你大爷的" | ||||
| } | } | ||||
| func TestSendTemplateMemberFeeReminder(t *testing.T) { | func TestSendTemplateMemberFeeReminder(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "校友会会员费\n" | first := "校友会会员费\n" | ||||
| remark := "逾期不缴费将会被列出来" | remark := "逾期不缴费将会被列出来" | ||||
| } | } | ||||
| func TestSendTemplatePaymentAck(t *testing.T) { | func TestSendTemplatePaymentAck(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "即将到来的活动,欢迎你的到来" | first := "即将到来的活动,欢迎你的到来" | ||||
| remark := "怎么才能让校友们积极互动是一个问题" | remark := "怎么才能让校友们积极互动是一个问题" | ||||
| } | } | ||||
| func TestSendTemplateCheckinFail(t *testing.T) { | func TestSendTemplateCheckinFail(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "--" | first := "--" | ||||
| remark := "checkin failed, due to your location is incorrect" | remark := "checkin failed, due to your location is incorrect" | ||||
| } | } | ||||
| func TestSendTemplateInformCollection(t *testing.T) { | func TestSendTemplateInformCollection(t *testing.T) { | ||||
| url := "http://www.google.com.au/" | url := "http://www.google.com.au/" | ||||
| first := "恭喜你获得本次Lucky Draw奖金 $200澳币" | first := "恭喜你获得本次Lucky Draw奖金 $200澳币" | ||||
| remark := "请你点击详情,通知你已收到奖励" | remark := "请你点击详情,通知你已收到奖励" | ||||
| } | } | ||||
| func TestSendTemplateMsgJoinCommunity(t *testing.T) { | func TestSendTemplateMsgJoinCommunity(t *testing.T) { | ||||
| url := "http://www.google.com.au" | url := "http://www.google.com.au" | ||||
| communityName := "小大同会" | communityName := "小大同会" | ||||
| first := "欢迎加入Community" + communityName | first := "欢迎加入Community" + communityName | ||||
| joinDate := time.Now().Format("2006-01-02 15:04:06 Mon MST -07") | joinDate := time.Now().Format("2006-01-02 15:04:06 Mon MST -07") | ||||
| templateSendJoinCommunity(toUser, url, first, remark, communityName, joinDate) | templateSendJoinCommunity(toUser, url, first, remark, communityName, joinDate) | ||||
| } | } | ||||
| func TestSendTemplateMsgAccountBalance(t *testing.T) { | |||||
| url := "http://www.google.com.au" | |||||
| first := "你有积分 100 " | |||||
| name := "张三二" | |||||
| addr := "西大直街100 号, 广山区, 南京市,中国, 10086" | |||||
| card := "11111 3333 4444 5555" | |||||
| balance := "澳币200元" | |||||
| remark := "如有余额请联络财务兑现: " + time.Now().Format("2006-01-02 15:04:06 Mon MST -07") | |||||
| templateSendAccountBalance(toUser, url, first, remark, name, addr, card, balance) | |||||
| } |
| } | } | ||||
| if proc, hasProc := AllProc[cmd]; hasProc { | if proc, hasProc := AllProc[cmd]; hasProc { | ||||
| proc.init(ss) | |||||
| proc.intro(ss, in) | |||||
| proc.start(ss, in) | |||||
| startProc(proc, ss, in) | |||||
| processed = true | processed = true | ||||
| return true | return true | ||||
| } | } | ||||
| return false //不认识的命令,我们选择这个信息不处理 | return false //不认识的命令,我们选择这个信息不处理 | ||||
| } | } | ||||
| func startProc(proc chatProcedure, ss *openIDSessionData, in *InWechatMsg) { | |||||
| proc.init(ss) | |||||
| proc.intro(ss, in) | |||||
| proc.start(ss, in) | |||||
| } | |||||
| func allCommand(ss *openIDSessionData, in *InWechatMsg) (processed bool) { | func allCommand(ss *openIDSessionData, in *InWechatMsg) (processed bool) { | ||||
| processed = true | processed = true | ||||
| msg := "命令如下:\n" | msg := "命令如下:\n" |
| package main | package main | ||||
| func (ss *openIDSessionData) serveEvents(in* InWechatMsg) (processed bool) { | |||||
| func (ss *openIDSessionData) serveEvents(in *InWechatMsg) (processed bool) { | |||||
| processed = true | processed = true | ||||
| e := in.body.(EventMsg) | e := in.body.(EventMsg) | ||||
| switch e.Event { | switch e.Event { | ||||
| onLocation(in) | onLocation(in) | ||||
| case "CLICK": | case "CLICK": | ||||
| in.replyText("") | in.replyText("") | ||||
| onClick(in) | |||||
| onClick(ss, in) | |||||
| case "VIEW": | case "VIEW": | ||||
| in.replyText("CLICK" + e.EventKey) | |||||
| in.replyText("VIEW" + e.EventKey) | |||||
| case "TEMPLATESENDJOBFINISH": | case "TEMPLATESENDJOBFINISH": | ||||
| // <xml><ToUserName><![CDATA[gh_f09231355c68]]></ToUserName> | // <xml><ToUserName><![CDATA[gh_f09231355c68]]></ToUserName> | ||||
| // <FromUserName><![CDATA[oUN420Wj78vnkNeAJY7RMPXA28oc]]></FromUserName> | // <FromUserName><![CDATA[oUN420Wj78vnkNeAJY7RMPXA28oc]]></FromUserName> |