using Common.Wechat; using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; using ZcPeng.PublicLibrary; /*todo:该文件仅用于调试,正式部署请删除。*/ namespace ZcPeng.weixin.PublicAccount { /// /// 消息类型 /// public enum MessageType { /// /// 请求 /// Request, /// /// 响应 /// Response, /// /// 异常 /// Exception } /// /// Message:消息 /// public class Message { //private Guid guid; //private MessageType request; //private string v1; //private string v2; /// /// ID /// public Guid Id { get; set; } /// /// 类型 /// public MessageType Type { get; set; } /// /// 内容 /// public string Content { get; set; } /// /// 访问api方法 /// public string Method { get; set; } /// /// 访问Result /// public string Result { get; set; } /// /// 时间 /// public DateTime Time { get; set; } /// /// 构造函数 /// /// /// /// /// public Message(Guid id, MessageType type, string content, DateTime time,string method, string result) { Id = id; Type = type; Content = content; Time = time; Method = method; Result = result; } /// /// 构造函数 /// /// /// Message(MessageType type, string content) : this(Guid.NewGuid(), type, content, DateTime.Now,"","") { } /// /// 返回参数列表 /// /// private List ToParameters() { List parameters = new List(4); SqlParameter p = new SqlParameter("@Id", SqlDbType.UniqueIdentifier, 16); p.Value = Id; parameters.Add(p); p = new SqlParameter("@Type", SqlDbType.Int, 4); p.Value = (int)Type; parameters.Add(p); p = new SqlParameter("@Content", SqlDbType.NVarChar); p.Value = Content; parameters.Add(p); p = new SqlParameter("@Time", SqlDbType.DateTime, 8); p.Value = Time; parameters.Add(p); p = new SqlParameter("@Method", SqlDbType.NVarChar); p.Value = Method; parameters.Add(p); p = new SqlParameter("@Result", SqlDbType.NVarChar); p.Value = Result; parameters.Add(p); return parameters; } /// /// 插入新消息 /// /// 消息 /// 返回插入是否成功 public static bool Insert(Message message) { string commandText = "INSERT INTO "+Config.TablePrefix+"Message (Id,Type,Content,Time,Method,Result)" + " VALUES (@Id,@Type,@Content,@Time,@Method,@Result)"; string result; List parameters = message.ToParameters(); return DataAccess.ExecuteCommand(commandText, parameters, out result) > 0; } } }