Beispiel #1
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.weixin_account model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            //利用反射获得属性的所有公共属性
            PropertyInfo[]      pros  = model.GetType().GetProperties();
            List <SqlParameter> paras = new List <SqlParameter>();

            strSql.Append("update " + databaseprefix + "weixin_account set ");
            foreach (PropertyInfo pi in pros)
            {
                //如果不是主键则追加sql字符串
                if (!pi.Name.Equals("id"))
                {
                    //判断属性值是否为空
                    if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals(""))
                    {
                        str1.Append(pi.Name + "=@" + pi.Name + ",");                          //声明参数
                        paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值
                    }
                }
            }
            strSql.Append(str1.ToString().Trim(','));
            strSql.Append(" where id=@id ");
            paras.Add(new SqlParameter("@id", model.id));
            return(DbHelperSQL.ExecuteSql(strSql.ToString(), paras.ToArray()) > 0);
        }
        private bool DoAdd()
        {
            bool result = false;
            Model.weixin_account model = new Model.weixin_account();
            BLL.weixin_account bll = new BLL.weixin_account();

            model.name = txtName.Text.Trim();
            model.originalid = txtOriginalId.Text.Trim();
            model.wxcode = txtWxCode.Text.Trim();
            model.token = txtToKen.Text.Trim();
            model.appid = txtAppId.Text.Trim();
            model.appsecret = txtAppSecret.Text.Trim();
            if (cbIsPush.Checked == true)
            {
                model.is_push = 1;
            }
            else
            {
                model.is_push = 0;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            if (bll.Add(model) > 0)
            {
                AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "增加公众账户:" + model.name); //记录日志
                result = true;
            }
            return result;
        }
Beispiel #3
0
        /// <summary>
        /// 获取JSAPI_TICKET接口
        /// </summary>
        /// <returns></returns>
        public string GetJSAPI_Ticket(int accountId, string accessToken)
        {
            Model.weixin_account accountModel = accountBLL.GetModel(accountId); //公众平台账户信息
            string ticket = JsApiTicketContainer.TryGetTicket(accountModel.appid, accountModel.appsecret);

            return(ticket);
        }
Beispiel #4
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.weixin_account GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder();

            Model.weixin_account model = new Model.weixin_account();
            //利用反射获得属性的所有公共属性
            PropertyInfo[] pros = model.GetType().GetProperties();
            foreach (PropertyInfo p in pros)
            {
                str1.Append(p.Name + ",");//拼接字段
            }
            strSql.Append("select top 1 " + str1.ToString().Trim(','));
            strSql.Append(" from " + databaseprefix + "weixin_account");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@id", SqlDbType.Int, 4)
            };
            parameters[0].Value = id;
            DataTable dt = DbHelperSQL.Query(strSql.ToString(), parameters).Tables[0];

            if (dt.Rows.Count > 0)
            {
                return(DataRowToModel(dt.Rows[0]));
            }
            else
            {
                return(null);
            }
        }
        private bool DoAdd()
        {
            bool result = false;

            Model.weixin_account model = new Model.weixin_account();
            BLL.weixin_account   bll   = new BLL.weixin_account();

            model.name       = txtName.Text.Trim();
            model.originalid = txtOriginalId.Text.Trim();
            model.wxcode     = txtWxCode.Text.Trim();
            model.token      = txtToKen.Text.Trim();
            model.appid      = txtAppId.Text.Trim();
            model.appsecret  = txtAppSecret.Text.Trim();
            if (cbIsPush.Checked == true)
            {
                model.is_push = 1;
            }
            else
            {
                model.is_push = 0;
            }
            model.sort_id = Utils.StrToInt(txtSortId.Text.Trim(), 99);

            if (bll.Add(model) > 0)
            {
                AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "增加公众账户:" + model.name); //记录日志
                result = true;
            }
            return(result);
        }
Beispiel #6
0
        /// <summary>
        /// 返回第一个微信公众号信息
        /// </summary>
        /// <returns></returns>
        protected Model.weixin_account GetWxAccountModel()
        {
            string requestDomain = HttpContext.Current.Request.Url.Authority.ToLower(); //获得来源域名含端口号
            string requestPath   = HttpContext.Current.Request.RawUrl.ToLower();        //当前的URL地址
            string sitePath      = GetSitePath(requestPath, requestDomain);

            BLL.weixin_account   wxBll  = new BLL.weixin_account();
            Model.weixin_account modelt = wxBll.GetModel(1);
            return(modelt);
        }
Beispiel #7
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.weixin_account model)
        {
            int newId;

            using (OleDbConnection conn = new OleDbConnection(DbHelperOleDb.connectionString))
            {
                conn.Open();
                using (OleDbTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into " + databaseprefix + "weixin_account(");
                        strSql.Append("name,originalid,wxcode,token,appid,appsecret,is_push,sort_id,add_time)");
                        strSql.Append(" values (");
                        strSql.Append("@name,@originalid,@wxcode,@token,@appid,@appsecret,@is_push,@sort_id,@add_time)");
                        OleDbParameter[] parameters =
                        {
                            new OleDbParameter("@name",       OleDbType.VarChar, 100),
                            new OleDbParameter("@originalid", OleDbType.VarChar,  50),
                            new OleDbParameter("@wxcode",     OleDbType.VarChar,  50),
                            new OleDbParameter("@token",      OleDbType.VarChar, 300),
                            new OleDbParameter("@appid",      OleDbType.VarChar, 100),
                            new OleDbParameter("@appsecret",  OleDbType.VarChar, 150),
                            new OleDbParameter("@is_push",    OleDbType.Integer,   4),
                            new OleDbParameter("@sort_id",    OleDbType.Integer,   4),
                            new OleDbParameter("@add_time",   OleDbType.Date)
                        };
                        parameters[0].Value = model.name;
                        parameters[1].Value = model.originalid;
                        parameters[2].Value = model.wxcode;
                        parameters[3].Value = model.token;
                        parameters[4].Value = model.appid;
                        parameters[5].Value = model.appsecret;
                        parameters[6].Value = model.is_push;
                        parameters[7].Value = model.sort_id;
                        parameters[8].Value = model.add_time;
                        DbHelperOleDb.ExecuteSql(conn, trans, strSql.ToString(), parameters);
                        //取得新插入的ID
                        newId = GetMaxId(conn, trans);
                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return(-1);
                    }
                }
            }
            return(newId);
        }
Beispiel #8
0
        /// <summary>
        /// 重写虚方法,此方法将在Init事件前执行
        /// </summary>
        protected override void ShowPage()
        {
            int    weixinId = DTRequest.GetQueryInt("wxid");
            string url      = "http://" + DTRequest.GetHost() + HttpContext.Current.Request.RawUrl;

            BLL.weixin_account   wxBll  = new BLL.weixin_account();
            Model.weixin_account modelt = wxBll.GetModel(weixinId);
            if (modelt != null)
            {
                string ticket = JsApiTicketContainer.TryGetJsApiTicket(modelt.appid, modelt.appsecret);
                jssdkUiPackage = JSSDKHelper.GetJsSdkUiPackage(modelt.appid, modelt.appsecret, url);
            }
            this.Init += new EventHandler(article_show_Init);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.weixin_account model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update " + databaseprefix + "weixin_account set ");
            strSql.Append("name=@name,");
            strSql.Append("originalid=@originalid,");
            strSql.Append("wxcode=@wxcode,");
            strSql.Append("token=@token,");
            strSql.Append("appid=@appid,");
            strSql.Append("appsecret=@appsecret,");
            strSql.Append("is_push=@is_push,");
            strSql.Append("sort_id=@sort_id,");
            strSql.Append("add_time=@add_time");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",       SqlDbType.NVarChar,  100),
                new SqlParameter("@originalid", SqlDbType.NVarChar,   50),
                new SqlParameter("@wxcode",     SqlDbType.NVarChar,   50),
                new SqlParameter("@token",      SqlDbType.NVarChar,  300),
                new SqlParameter("@appid",      SqlDbType.NVarChar,  100),
                new SqlParameter("@appsecret",  SqlDbType.NVarChar,  150),
                new SqlParameter("@is_push",    SqlDbType.TinyInt,     1),
                new SqlParameter("@sort_id",    SqlDbType.Int,         4),
                new SqlParameter("@add_time",   SqlDbType.DateTime),
                new SqlParameter("@id",         SqlDbType.Int, 4)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.originalid;
            parameters[2].Value = model.wxcode;
            parameters[3].Value = model.token;
            parameters[4].Value = model.appid;
            parameters[5].Value = model.appsecret;
            parameters[6].Value = model.is_push;
            parameters[7].Value = model.sort_id;
            parameters[8].Value = model.add_time;
            parameters[9].Value = model.id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Beispiel #10
0
 /// <summary>
 /// 父类的构造函数
 /// </summary>
 public BasePage()
 {
     //是否关闭网站
     if (config.webstatus == 0)
     {
         HttpContext.Current.Response.Redirect(linkurl("error", "?msg=" + Utils.UrlEncode(config.webclosereason)));
         return;
     }
     //取得站点信息
     site      = GetSiteModel();
     wxAccount = GetWxAccountModel();
     //抛出一个虚方法给继承重写
     ShowPage();
 }
 /// <summary>
 /// 得到一个对象实体
 /// </summary>
 public Model.weixin_account DataRowToModel(DataRow row)
 {
     Model.weixin_account model = new Model.weixin_account();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["name"] != null)
         {
             model.name = row["name"].ToString();
         }
         if (row["originalid"] != null)
         {
             model.originalid = row["originalid"].ToString();
         }
         if (row["wxcode"] != null)
         {
             model.wxcode = row["wxcode"].ToString();
         }
         if (row["token"] != null)
         {
             model.token = row["token"].ToString();
         }
         if (row["appid"] != null)
         {
             model.appid = row["appid"].ToString();
         }
         if (row["appsecret"] != null)
         {
             model.appsecret = row["appsecret"].ToString();
         }
         if (row["is_push"] != null && row["is_push"].ToString() != "")
         {
             model.is_push = int.Parse(row["is_push"].ToString());
         }
         if (row["sort_id"] != null && row["sort_id"].ToString() != "")
         {
             model.sort_id = int.Parse(row["sort_id"].ToString());
         }
         if (row["add_time"] != null && row["add_time"].ToString() != "")
         {
             model.add_time = DateTime.Parse(row["add_time"].ToString());
         }
     }
     return(model);
 }
Beispiel #12
0
 /// <summary>
 /// �õ�һ������ʵ��
 /// </summary>
 public Model.weixin_account DataRowToModel(DataRow row)
 {
     Model.weixin_account model = new Model.weixin_account();
     if (row != null)
     {
         if (row["id"] != null && row["id"].ToString() != "")
         {
             model.id = int.Parse(row["id"].ToString());
         }
         if (row["name"] != null)
         {
             model.name = row["name"].ToString();
         }
         if (row["originalid"] != null)
         {
             model.originalid = row["originalid"].ToString();
         }
         if (row["wxcode"] != null)
         {
             model.wxcode = row["wxcode"].ToString();
         }
         if (row["token"] != null)
         {
             model.token = row["token"].ToString();
         }
         if (row["appid"] != null)
         {
             model.appid = row["appid"].ToString();
         }
         if (row["appsecret"] != null)
         {
             model.appsecret = row["appsecret"].ToString();
         }
         if (row["is_push"] != null && row["is_push"].ToString() != "")
         {
             model.is_push = int.Parse(row["is_push"].ToString());
         }
         if (row["sort_id"] != null && row["sort_id"].ToString() != "")
         {
             model.sort_id = int.Parse(row["sort_id"].ToString());
         }
         if (row["add_time"] != null && row["add_time"].ToString() != "")
         {
             model.add_time = DateTime.Parse(row["add_time"].ToString());
         }
     }
     return model;
 }
Beispiel #13
0
        BLL.weixin_account accountBLL = new BLL.weixin_account();         //公众平台账户

        /// <summary>
        /// 及时获得access_token值
        /// access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。正常情况下access_token有效期为7200秒,
        /// 重复获取将导致上次获取的access_token失效。
        /// 每日限额获取access_token.我们将access_token保存到数据库里,间隔时间为20分钟,从微信公众平台获得一次。
        /// </summary>
        public string GetAccessToken(int accountId, out string error)
        {
            string access_token = string.Empty;

            error = string.Empty;
            try
            {
                Model.weixin_account accountModel = accountBLL.GetModel(accountId); //公众平台账户信息
                if (string.IsNullOrEmpty(accountModel.appid) || string.IsNullOrEmpty(accountModel.appsecret))
                {
                    error = "AppId或者AppSecret未填写,请在补全信息!";
                    return(string.Empty);
                }
                //没有找到该账户则获取AccessToKen写入存储1200秒
                if (!tokenBLL.ExistsAccount(accountId))
                {
                    var result = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetToken(accountModel.appid, accountModel.appsecret);
                    access_token = result.access_token;
                    tokenBLL.Add(accountId, access_token);
                    return(access_token);
                }
                //获取公众账户的实体
                Model.weixin_access_token tokenModel = tokenBLL.GetAccountModel(accountId);
                //计算时间判断是否过期
                TimeSpan ts           = DateTime.Now - tokenModel.add_time;
                double   chajunSecond = ts.TotalSeconds;
                if (string.IsNullOrEmpty(tokenModel.access_token) || chajunSecond >= tokenModel.expires_in)
                {
                    //从微信平台重新获得AccessToken
                    var result = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetToken(accountModel.appid, accountModel.appsecret);
                    access_token = result.access_token;
                    //更新到数据库里的AccessToken
                    tokenModel.access_token = access_token;
                    tokenModel.add_time     = DateTime.Now;
                    tokenBLL.Update(tokenModel);
                }
                else
                {
                    access_token = tokenModel.access_token;
                }
            }
            catch (Exception ex)
            {
                error = "获取AccessToken出错:" + ex.Message;
            }
            return(access_token);
        }
Beispiel #14
0
 //保存
 protected void btnSubmit_Click(object sender, EventArgs e)
 {
     BLL.weixin_account   bll   = new BLL.weixin_account();
     Model.weixin_account model = bll.GetModel();
     if (model == null)
     {
         model = new Model.weixin_account();
     }
     model.name       = txtName.Text.Trim();
     model.originalid = txtOriginalId.Text.Trim();
     model.wxcode     = txtWxCode.Text.Trim();
     model.token      = txtToKen.Text.Trim();
     model.appid      = txtAppId.Text.Trim();
     model.appsecret  = txtAppSecret.Text.Trim();
     if (cbIsPush.Checked == true)
     {
         model.is_push = 1;
     }
     else
     {
         model.is_push = 0;
     }
     //保存数据
     if (model.id > 0)
     {
         if (bll.Update(model))
         {
             AddAdminLog(DTEnums.ActionEnum.Edit.ToString(), "编辑公众账户:" + model.name); //记录日志
             JscriptMsg("编辑公众账户成功!", "account_edit.aspx");
             return;
         }
     }
     else
     {
         if (bll.Add(model) > 0)
         {
             AddAdminLog(DTEnums.ActionEnum.Add.ToString(), "增加公众账户:" + model.name); //记录日志
             JscriptMsg("编辑公众账户成功!", "account_edit.aspx");
             return;
         }
     }
     JscriptMsg("保存过程中发生错误!", string.Empty);
     return;
 }
Beispiel #15
0
 /// <summary>
 /// 将对象转换实体
 /// </summary>
 public Model.weixin_account DataRowToModel(DataRow row)
 {
     Model.weixin_account model = new Model.weixin_account();
     if (row != null)
     {
         //利用反射获得属性的所有公共属性
         Type modelType = model.GetType();
         for (int i = 0; i < row.Table.Columns.Count; i++)
         {
             //查找实体是否存在列表相同的公共属性
             PropertyInfo proInfo = modelType.GetProperty(row.Table.Columns[i].ColumnName);
             if (proInfo != null && row[i] != DBNull.Value)
             {
                 proInfo.SetValue(model, row[i], null);//用索引值设置属性值
             }
         }
     }
     return(model);
 }
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.weixin_account model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into " + databaseprefix + "weixin_account(");
            strSql.Append("name,originalid,wxcode,token,appid,appsecret,is_push,sort_id,add_time)");
            strSql.Append(" values (");
            strSql.Append("@name,@originalid,@wxcode,@token,@appid,@appsecret,@is_push,@sort_id,@add_time)");
            strSql.Append(";select @@IDENTITY");
            SqlParameter[] parameters =
            {
                new SqlParameter("@name",       SqlDbType.NVarChar, 100),
                new SqlParameter("@originalid", SqlDbType.NVarChar,  50),
                new SqlParameter("@wxcode",     SqlDbType.NVarChar,  50),
                new SqlParameter("@token",      SqlDbType.NVarChar, 300),
                new SqlParameter("@appid",      SqlDbType.NVarChar, 100),
                new SqlParameter("@appsecret",  SqlDbType.NVarChar, 150),
                new SqlParameter("@is_push",    SqlDbType.TinyInt,    1),
                new SqlParameter("@sort_id",    SqlDbType.Int,        4),
                new SqlParameter("@add_time",   SqlDbType.DateTime)
            };
            parameters[0].Value = model.name;
            parameters[1].Value = model.originalid;
            parameters[2].Value = model.wxcode;
            parameters[3].Value = model.token;
            parameters[4].Value = model.appid;
            parameters[5].Value = model.appsecret;
            parameters[6].Value = model.is_push;
            parameters[7].Value = model.sort_id;
            parameters[8].Value = model.add_time;

            object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters);

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
Beispiel #17
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.weixin_account model)
        {
            StringBuilder strSql = new StringBuilder();
            StringBuilder str1   = new StringBuilder(); //数据字段
            StringBuilder str2   = new StringBuilder(); //数据参数

            //利用反射获得属性的所有公共属性
            PropertyInfo[]      pros  = model.GetType().GetProperties();
            List <SqlParameter> paras = new List <SqlParameter>();

            strSql.Append("insert into " + databaseprefix + "weixin_account(");
            foreach (PropertyInfo pi in pros)
            {
                //如果不是主键则追加sql字符串
                if (!pi.Name.Equals("id"))
                {
                    //判断属性值是否为空
                    if (pi.GetValue(model, null) != null && !pi.GetValue(model, null).ToString().Equals(""))
                    {
                        str1.Append(pi.Name + ",");                                           //拼接字段
                        str2.Append("@" + pi.Name + ",");                                     //声明参数
                        paras.Add(new SqlParameter("@" + pi.Name, pi.GetValue(model, null))); //对参数赋值
                    }
                }
            }
            strSql.Append(str1.ToString().Trim(','));
            strSql.Append(") values (");
            strSql.Append(str2.ToString().Trim(','));
            strSql.Append(") ");
            strSql.Append(";select @@IDENTITY;");
            object obj = DbHelperSQL.GetSingle(strSql.ToString(), paras.ToArray());

            if (obj == null)
            {
                return(0);
            }
            else
            {
                return(Convert.ToInt32(obj));
            }
        }
        private void ShowInfo(int _id)
        {
            BLL.weixin_account   bll   = new BLL.weixin_account();
            Model.weixin_account model = bll.GetModel(_id);

            txtName.Text       = model.name;
            txtOriginalId.Text = model.originalid;
            txtWxCode.Text     = model.wxcode;
            txtToKen.Text      = model.token;
            txtAppId.Text      = model.appid;
            txtAppSecret.Text  = model.appsecret;
            if (model.is_push == 1)
            {
                cbIsPush.Checked = true;
            }
            else
            {
                cbIsPush.Checked = false;
            }
            txtSortId.Text = model.sort_id.ToString();
        }
Beispiel #19
0
 private void ShowInfo()
 {
     BLL.weixin_account   bll   = new BLL.weixin_account();
     Model.weixin_account model = bll.GetModel();
     if (model != null)
     {
         txtName.Text       = model.name;
         txtOriginalId.Text = model.originalid;
         txtWxCode.Text     = model.wxcode;
         txtToKen.Text      = model.token;
         txtAppId.Text      = model.appid;
         txtAppSecret.Text  = model.appsecret;
         if (model.is_push == 1)
         {
             cbIsPush.Checked = true;
         }
         else
         {
             cbIsPush.Checked = false;
         }
     }
 }
Beispiel #20
0
        /// <summary>
        ///【强制刷新】access_token值
        /// access_token是公众号的全局唯一票据,公众号调用各接口时都需使用access_token。正常情况下access_token有效期为7200秒,
        /// 重复获取将导致上次获取的access_token失效。
        /// 每日限额获取access_token.我们将access_token保存到数据库里,间隔时间为20分钟,从微信公众平台获得一次。
        /// </summary>
        /// <returns></returns>
        public string FlushAccessToken(int accountId, out string error)
        {
            string access_token = string.Empty;

            error = string.Empty;
            try
            {
                Model.weixin_account accountModel = accountBLL.GetModel(accountId); //公众平台账户信息
                if (string.IsNullOrEmpty(accountModel.appid) || string.IsNullOrEmpty(accountModel.appsecret))
                {
                    error = "AppId或者AppSecret未填写,请在补全信息!";
                    return("");
                }

                var result = Senparc.Weixin.MP.CommonAPIs.CommonApi.GetToken(accountModel.appid, accountModel.appsecret);
                access_token = result.access_token;

                //没有找到该账户则获取AccessToKen写入存储1200秒
                if (!tokenBLL.ExistsAccount(accountId))
                {
                    tokenBLL.Add(accountId, access_token);
                }
                else
                {
                    //获取公众账户的实体
                    Model.weixin_access_token tokenModel = tokenBLL.GetAccountModel(accountId);
                    //更新到数据库里的AccessToken
                    tokenModel.access_token = access_token;
                    tokenModel.add_time     = DateTime.Now;
                    tokenBLL.Update(tokenModel);
                }
            }
            catch (Exception ex)
            {
                error = "获得AccessToken出错:" + ex.Message;
            }
            return(access_token);
        }
Beispiel #21
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(Model.weixin_account model)
 {
     return(dal.Update(model));
 }
Beispiel #22
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public int  Add(Model.weixin_account model)
 {
     return(dal.Add(model));
 }