123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- using Common.Wechat;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Data.SqlClient;
- using ZcPeng.PublicLibrary;
- /*todo:该文件仅用于调试,正式部署请删除。*/
- namespace ZcPeng.weixin.PublicAccount
- {
- /// <summary>
- /// 消息类型
- /// </summary>
- public enum MessageType
- {
- /// <summary>
- /// 请求
- /// </summary>
- Request,
- /// <summary>
- /// 响应
- /// </summary>
- Response,
- /// <summary>
- /// 异常
- /// </summary>
- Exception
- }
- /// <summary>
- /// Message:消息
- /// </summary>
- public class Message
- {
- //private Guid guid;
- //private MessageType request;
- //private string v1;
- //private string v2;
- /// <summary>
- /// ID
- /// </summary>
- public Guid Id { get; set; }
- /// <summary>
- /// 类型
- /// </summary>
- public MessageType Type { get; set; }
- /// <summary>
- /// 内容
- /// </summary>
- public string Content { get; set; }
- /// <summary>
- /// 访问api方法
- /// </summary>
- public string Method { get; set; }
- /// <summary>
- /// 访问Result
- /// </summary>
- public string Result { get; set; }
- /// <summary>
- /// 时间
- /// </summary>
- public DateTime Time { get; set; }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="id"></param>
- /// <param name="type"></param>
- /// <param name="content"></param>
- /// <param name="time"></param>
- 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;
- }
- /// <summary>
- /// 构造函数
- /// </summary>
- /// <param name="type"></param>
- /// <param name="content"></param>
- Message(MessageType type, string content)
- : this(Guid.NewGuid(), type, content, DateTime.Now,"","")
- {
- }
- /// <summary>
- /// 返回参数列表
- /// </summary>
- /// <returns></returns>
- private List<SqlParameter> ToParameters()
- {
- List<SqlParameter> parameters = new List<SqlParameter>(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;
- }
- /// <summary>
- /// 插入新消息
- /// </summary>
- /// <param name="message">消息</param>
- /// <returns>返回插入是否成功</returns>
- 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<SqlParameter> parameters = message.ToParameters();
- return DataAccess.ExecuteCommand(commandText, parameters, out result) > 0;
- }
- }
- }
|