|
|
|
@@ -0,0 +1,357 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"log" |
|
|
|
) |
|
|
|
|
|
|
|
type templatesIDInfo struct { |
|
|
|
EnglishID string `json:"english_id"` //never change |
|
|
|
ChineseID string `json:"chinese_id"` //can recreate new template from wechat library |
|
|
|
TemplateID string `json:"template_id"` //dynamically assigned by wechat |
|
|
|
} |
|
|
|
|
|
|
|
type sendTemplateMsg struct { |
|
|
|
ToUser string `json:"touser"` |
|
|
|
TemplateID string `json:"template_id"` |
|
|
|
URL string `json:"url"` |
|
|
|
Data map[string]templateMsgKeyword `json:"data"` |
|
|
|
} |
|
|
|
type templateMsgKeyword struct { |
|
|
|
Value string `json:"value"` |
|
|
|
Color string `json:"color"` |
|
|
|
} |
|
|
|
|
|
|
|
//WechatTemplates Message templates and their ID |
|
|
|
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"}, |
|
|
|
} |
|
|
|
|
|
|
|
func kfSendTemplateMsg(touser, templateid, url string, data map[string]templateMsgKeyword) (resp string, err error) { |
|
|
|
s := sendTemplateMsg{} |
|
|
|
s.ToUser = touser |
|
|
|
s.TemplateID = templateid |
|
|
|
s.Data = data |
|
|
|
s.URL = url |
|
|
|
//marshal |
|
|
|
j, _ := json.Marshal(s) |
|
|
|
log.Println(string(j)) |
|
|
|
//send |
|
|
|
u := getTemplatePOSTURL() |
|
|
|
return postJSON(j, u) |
|
|
|
} |
|
|
|
|
|
|
|
func getTemplatePOSTURL() string { |
|
|
|
atk, _ := GetAccessToken() |
|
|
|
return "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + atk |
|
|
|
} |
|
|
|
|
|
|
|
//中文,英文,匹配一个就行 |
|
|
|
func getTemplateIDByName(name string) string { |
|
|
|
for k, v := range WechatTemplates { |
|
|
|
if v.ChineseID == name { |
|
|
|
return v.TemplateID |
|
|
|
} |
|
|
|
if k == name { |
|
|
|
return v.TemplateID |
|
|
|
} |
|
|
|
} |
|
|
|
return "" |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 01 成功加入志愿者通知 |
|
|
|
func templateSendJoinVolunteer(toUser, url, first, remark, name, staffID, joinDate, totalCount, totalTime string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 姓名:{{keyword1.DATA}} |
|
|
|
// 工号:{{keyword2.DATA}} |
|
|
|
// 加入时间:{{keyword3.DATA}} |
|
|
|
// 参与次数:{{keyword4.DATA}} |
|
|
|
// 累计时间:{{keyword5.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 您已成功加入志愿者 |
|
|
|
// 姓名:黄竹 |
|
|
|
// 工号:317500267 |
|
|
|
// 加入时间:2008年8月 |
|
|
|
// 参与次数:168次 |
|
|
|
// 累计时间:564小时 |
|
|
|
// 感谢您对XX公益事业的支持,欢迎您再次参加我们活动! |
|
|
|
tid := getTemplateIDByName("join_volunteer") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{name, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{staffID, "#173177"} |
|
|
|
data["keyword3"] = templateMsgKeyword{joinDate, "#173177"} |
|
|
|
data["keyword4"] = templateMsgKeyword{totalCount, "#173177"} |
|
|
|
data["keyword5"] = templateMsgKeyword{totalTime, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 02 团队加入成功通知 |
|
|
|
func templateSendJoinTeam(toUser, url, first, remark, teamname, joinDate string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 团队名称:{{keyword1.DATA}} |
|
|
|
// 加入时间:{{keyword2.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 您已成功加入团队! |
|
|
|
// 团队名称:爱心志愿者团队 |
|
|
|
// 加入时间:2017-1-11 8:18:18 |
|
|
|
// 可进入我的团队查看详情 |
|
|
|
tid := getTemplateIDByName("join_team") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{teamname, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{joinDate, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 03 签到成功提醒 |
|
|
|
func templateSendCheckinSuccess(toUser, url, first, remark, activity, date, venue string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 活动:{{keyword1.DATA}} |
|
|
|
// 时间:{{keyword2.DATA}} |
|
|
|
// 地点:{{keyword3.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 您好,您已签到成功。 |
|
|
|
// 活动:李大钊青年干校第2期 |
|
|
|
// 时间:2016.5.28 |
|
|
|
// 地点:多功能报告厅 |
|
|
|
// 请服从工作人员安排,有序就坐。成功加入社群提醒 |
|
|
|
tid := getTemplateIDByName("checkin_success") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{activity, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{date, "#173177"} |
|
|
|
data["keyword3"] = templateMsgKeyword{venue, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 04 会议通知 |
|
|
|
func templateSendMeetingReminder(toUser, url, first, remark, date, subject, venue string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 会议时间:{{keyword1.DATA}} |
|
|
|
// 会议主题:{{keyword2.DATA}} |
|
|
|
// 会议地点:{{keyword3.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 你好 |
|
|
|
// 会议时间:2015年7月10日 |
|
|
|
// 会议主题:户籍相关会议 |
|
|
|
// 会议地点:丰产路派出所5楼501 |
|
|
|
// 请按时参加会议 |
|
|
|
tid := getTemplateIDByName("meeting_reminder") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{date, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{subject, "#173177"} |
|
|
|
data["keyword3"] = templateMsgKeyword{venue, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 05 签到提醒 |
|
|
|
func templateSendCheckinReminder(toUser, url, first, remark, name, subject, time string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 签到姓名:{{keyword1.DATA}} |
|
|
|
// 签到内容:{{keyword2.DATA}} |
|
|
|
// 签到时间:{{keyword3.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 阅读任务提醒 |
|
|
|
// 签到姓名:张三 |
|
|
|
// 签到内容:阅读行动第1天,别忘了打卡签到。 |
|
|
|
// 签到时间:2016年6月12日 9:00 |
|
|
|
// 女子之道,乃是独立,半途折返,是为耻辱。——苏枕书《京都第五年》 回复书名了解更多 回复‘取消阅读提醒’,停止推送 |
|
|
|
tid := getTemplateIDByName("checking_reminder") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{name, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{subject, "#173177"} |
|
|
|
data["keyword3"] = templateMsgKeyword{time, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 06 活动报名成功提醒成功加入社群提醒 |
|
|
|
func templateSendEnrollSuccess(toUser, url, first, remark, activity, host, venue, date string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 活动名称:{{keyword1.DATA}} |
|
|
|
// 主办方:{{keyword2.DATA}} |
|
|
|
// 活动地点:{{keyword3.DATA}} |
|
|
|
// 活动时间:{{keyword4.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// XXX,您已经报名成功 |
|
|
|
// 活动名称:公益啦网络平台培训 |
|
|
|
// 主办方:苏州联益信息 |
|
|
|
// 活动地点:烽火路80号 |
|
|
|
// 活动时间:2016年3月8日 09:30 ~ 16:30 |
|
|
|
// 感谢您的参与,点击查看活动详情 |
|
|
|
|
|
|
|
tid := getTemplateIDByName("checking_reminder") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{activity, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{host, "#173177"} |
|
|
|
data["keyword3"] = templateMsgKeyword{venue, "#173177"} |
|
|
|
data["keyword4"] = templateMsgKeyword{date, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 07 录入完整提醒 |
|
|
|
func templateSendFormFillupDone(toUser, url, first, remark, description, verificationDate string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 录入情况:{{keyword1.DATA}} |
|
|
|
// 审核时间:{{keyword2.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 您好,类克项目办公室通知您: |
|
|
|
// 录入情况:录入完整 |
|
|
|
// 审核时间:2016-11-29 |
|
|
|
// 您的援助申请材料录入完整,进入审核环节。 |
|
|
|
|
|
|
|
tid := getTemplateIDByName("form_fillup_done") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{description, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{verificationDate, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 08 会员缴费提醒 |
|
|
|
func templateSendMemberFeeReminder(toUser, url, first, remark, name, paymentDeadline, paymentValidDate, paymentAmount string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 姓名:{{keyword1.DATA}} |
|
|
|
// 缴费时间:{{keyword2.DATA}} |
|
|
|
// 有效日期:{{keyword3.DATA}} |
|
|
|
// 缴费金额:{{keyword4.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 您好,你已经成为会员 |
|
|
|
// 姓名:郑成功 |
|
|
|
// 缴费时间:2016年7月21日 18:36 |
|
|
|
// 有效日期:2019年7月21日 18:36 |
|
|
|
// 缴费金额:60元 |
|
|
|
// 感谢您的使用。 |
|
|
|
|
|
|
|
tid := getTemplateIDByName("memberfee_reminder") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{name, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{paymentDeadline, "#173177"} |
|
|
|
data["keyword3"] = templateMsgKeyword{paymentValidDate, "#173177"} |
|
|
|
data["keyword4"] = templateMsgKeyword{paymentAmount, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 09 缴费成功通知 |
|
|
|
func templateSendPaymentAck(toUser, url, first, remark, account, addr, amountPaid, balance, paidTo string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 户号:{{keyword1.DATA}} |
|
|
|
// 地址:{{keyword2.DATA}} |
|
|
|
// 支付金额:{{keyword3.DATA}} |
|
|
|
// 当前余额:{{keyword4.DATA}} |
|
|
|
// 收款单位:{{keyword5.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 您好,您已缴费成功 |
|
|
|
// 户号:13000008 |
|
|
|
// 地址:通园新村1栋1单元101 |
|
|
|
// 支付金额:50.00元 |
|
|
|
// 当前余额:51.88元 |
|
|
|
// 收款单位:吴江港华燃气 |
|
|
|
// 如有疑问,详询吴江港华燃气,服务热线0512-63405795 |
|
|
|
tid := getTemplateIDByName("payment_successful") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{account, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{addr, "#173177"} |
|
|
|
data["keyword3"] = templateMsgKeyword{amountPaid, "#173177"} |
|
|
|
data["keyword4"] = templateMsgKeyword{balance, "#173177"} |
|
|
|
data["keyword5"] = templateMsgKeyword{paidTo, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 10 签到失败提醒 |
|
|
|
func templateSendCheckinFail(toUser, url, first, remark, activity, date string) (resp string, err error) { |
|
|
|
|
|
|
|
// {{first.DATA}} |
|
|
|
// 活动名称:{{keyword1.DATA}} |
|
|
|
// 签到时间:{{keyword2.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 亲爱的川大校友,没有找到您的电子签到信息 |
|
|
|
// 活动名称:川大川创联新春团拜会 |
|
|
|
// 签到时间:2014年7月21日 18:36 |
|
|
|
// 点击详情完成签到 |
|
|
|
|
|
|
|
tid := getTemplateIDByName("checkin_failure") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{activity, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{date, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 11 物品领取通知 |
|
|
|
func templateSendInformCollection(toUser, url, first, remark, date, details string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 领取时间:{{keyword1.DATA}} |
|
|
|
// 领取明细:{{keyword2.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 您获得的物品可至网店领取 |
|
|
|
// 领取时间:3月12日-3月17日 |
|
|
|
// 领取内容:新市民卡 |
|
|
|
// 如无法至网店领取,可致电预约上门 |
|
|
|
|
|
|
|
tid := getTemplateIDByName("inform_collection") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{date, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{details, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |
|
|
|
|
|
|
|
//模板编号 12 成功加入社群提醒 |
|
|
|
func templateSendJoinCommunity(toUser, url, first, remark, communityName, joinDate string) (resp string, err error) { |
|
|
|
// {{first.DATA}} |
|
|
|
// 社群名称:{{keyword1.DATA}} |
|
|
|
// 加入时间:{{keyword2.DATA}} |
|
|
|
// {{remark.DATA}} |
|
|
|
|
|
|
|
// 恭喜您已加入社群,欢迎访问主页参加最新活动 |
|
|
|
// 社群名称:天天开心读书会 |
|
|
|
// 加入时间:2014年7月21日 18:36 |
|
|
|
// 感谢您的加入,祝您工作和生活愉快! |
|
|
|
tid := getTemplateIDByName("join_community") |
|
|
|
data := map[string]templateMsgKeyword{} |
|
|
|
data["first"] = templateMsgKeyword{first, "#173177"} |
|
|
|
data["keyword1"] = templateMsgKeyword{communityName, "#173177"} |
|
|
|
data["keyword2"] = templateMsgKeyword{joinDate, "#173177"} |
|
|
|
data["remark"] = templateMsgKeyword{remark, "#FF0000"} |
|
|
|
return kfSendTemplateMsg(toUser, tid, url, data) |
|
|
|
} |