コード例 #1
0
ファイル: weixin_controller.go プロジェクト: xiongpf/Jeremiah
func handleEventMsg(w http.ResponseWriter, msg []byte) {
	var message EventMessage
	if err := xml.Unmarshal(msg, &message); err != nil {
		log.Println(err.Error())
		return
	}

	user := models.FollowUser{
		UserId:      message.FromUserName,
		UserName:    "",
		NickName:    "",
		Description: "",
	}

	var ret []byte
	//订阅
	if message.Event == "subscribe" {
		var feedback TextMessage
		var option models.Option
		option.Key = "follow_feedback_text"
		if err := models.Orm.Read(&option, "Key"); err == nil {
			feedback.Content = option.Value
		} else {
			feedback.Content = "欢迎关注贝贝科技生活馆,您有什么想和小贝说的呢?"
		}
		feedback.FromUserName = message.ToUserName
		feedback.ToUserName = message.FromUserName
		feedback.MsgType = MSG_TYPE_TEXT
		ret, _ = xml.Marshal(feedback)

		user.FollowOn = time.Now()

		if created, _, err := models.Orm.ReadOrCreate(&user, "UserId"); err == nil {
			if !created {
				user.FollowOn = time.Now()
				models.Orm.Update(&user)
			} else {
			}
		} else {
			log.Println(err.Error())
		}

	} else if message.Event == "unsubscribe" { //退订
		user.UnFollowOn = time.Now()
		if created, _, err := models.Orm.ReadOrCreate(&user, "UserId"); err == nil {
			if !created {
				user.UnFollowOn = time.Now()
				models.Orm.Update(&user)
			} else {
			}
		} else {
			log.Println(err.Error())
		}
	}
	w.Write(ret)
}
コード例 #2
0
ファイル: weixin_controller.go プロジェクト: xiongpf/Jeremiah
func makeDefaultContent(message *TextMessage) {
	var option models.Option
	message.MsgType = MSG_TYPE_TEXT
	option.Key = "msg_feedback_text"
	if err := models.Orm.Read(&option, "Key"); err == nil {
		message.Content = fmt.Sprintf(option.Value, strings.TrimSpace(message.Content))
	} else {
		message.Content = fmt.Sprintf("您刚才说“%v”,小贝已经清楚地记下了!", strings.TrimSpace(message.Content))
	}
	message.Content += "您还可以...\n"
	message.Content += fmt.Sprintf("\n<a href=\"http://%s/weixin/viewOrder?userID=%s\">查询我的订单</a>", siteIp, message.FromUserName)
	message.Content += fmt.Sprintf("\n<a href=\"http://%s/weixin/user?userID=%s\">完善个人信息</a>", siteIp, message.FromUserName)
	message.Content += fmt.Sprintf("\n<a href=\"http://%s/weixin/bindOrderNumber?userID=%s\">绑定订单</a>", siteIp, message.FromUserName)

}