Esempio n. 1
0
        /// <summary>
        /// 更新seesion_key
        /// </summary>
        /// <param name="model"></param>
        /// <param name="Msg"></param>
        /// <returns></returns>
        public bool Update(Code2SessionItem model, out string Msg)
        {
            try
            {
                StringBuilder str = new StringBuilder();
                str.Append("update Basic_WechatAccountInfo set session_key=@session_key,UpdateDate=getdate() where openid=@openid ");
                SqlParameter[] parameters =
                {
                    new SqlParameter("@session_key", SqlDbType.NVarChar, 50),
                    new SqlParameter("@openid",      SqlDbType.NVarChar, 50),
                };
                parameters[0].Value = model.session_key;
                parameters[1].Value = model.Openid;

                int rows = SqlHelper.ExecteNonQuery(CommandType.Text, str.ToString(), parameters);

                Msg = rows > 0 ? "执行成功" : "执行失败";
                bool bl = rows > 0 ? true : false;
                return(bl);
            }
            catch (Exception ex)
            {
                Msg = ex.Message.ToString();
                return(false);
            }
        }
        public object GetCode([FromUri] GetUserInfoItem model)
        {
            string serviceAddress = "https://api.weixin.qq.com/sns/jscode2session?appid=" + model.appid + "&secret="
                                    + model.sercet + "&js_code=" + model.js_code + "&grant_type=authorization_code";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(serviceAddress);

            request.Method      = "GET";
            request.ContentType = "text/html;charset=utf-8";
            HttpWebResponse response         = (HttpWebResponse)request.GetResponse();
            Stream          myResponseStream = response.GetResponseStream();
            StreamReader    myStreamReader   = new StreamReader(myResponseStream, System.Text.Encoding.UTF8);
            string          retString        = myStreamReader.ReadToEnd();

            myStreamReader.Close();
            myResponseStream.Close();
            Code2SessionItem ci = JsonConvert.DeserializeObject <Code2SessionItem>(retString);

            if (ci.Openid != null)
            {
                var obj = new
                {
                    Code    = "10000",
                    Data    = ci.Openid,
                    Success = true
                };
                Formatting microsoftDataFormatSettings = default(Formatting);

                //执行成功后保存openid信息
                Code2SessionServer bll = new Code2SessionServer();
                string             Msg = string.Empty;
                if (!bll.Exists(ci.Openid, out Msg))
                {
                    bll.Add(ci, out Msg);
                }
                else
                {
                    bll.Update(ci, out Msg);
                }
                return(JsonConvert.SerializeObject(obj, microsoftDataFormatSettings));
            }
            else
            {
                var obj = new
                {
                    Code    = ci.errcode,
                    Data    = ci.errmsg,
                    Success = false
                };
                Formatting microsoftDataFormatSettings = default(Formatting);
                return(JsonConvert.SerializeObject(obj, microsoftDataFormatSettings));
            }
        }
Esempio n. 3
0
        public bool Add(Code2SessionItem model, out string Msg)
        {
            try
            {
                StringBuilder str = new StringBuilder();
                str.Append("INSERT INTO [dbo].[Basic_WechatAccountInfo]([Openid],[session_key],[unionid],[CreateDate]=getdate(),[Creator],[UpdateDate]=getdate(),[Modifier])");
                str.Append("VALUES");
                str.Append("(@Openid,@session_key,@unionid,@CreateDate,@Creator,@UpdateDate,@Modifier)");
                SqlParameter[] parameters =
                {
                    new SqlParameter("@Openid",      SqlDbType.NVarChar, 50),
                    new SqlParameter("@session_key", SqlDbType.NVarChar, 50),
                    new SqlParameter("@unionid",     SqlDbType.NVarChar, 50),
                    new SqlParameter("@Creator",     SqlDbType.NVarChar, 50),
                    new SqlParameter("@Modifier",    SqlDbType.NVarChar, 50)
                };
                parameters[0].Value = model.Openid;
                parameters[1].Value = model.session_key;
                parameters[2].Value = model.unionid == null ? "" : model.unionid;
                parameters[3].Value = "system";
                parameters[4].Value = "system";

                int rows = SqlHelper.ExecteNonQuery(CommandType.Text, str.ToString(), parameters);

                bool bl = rows > 0 ? true : false;

                Msg = rows > 0 ? "执行成功" : "执行失败";

                return(bl);
            }
            catch (Exception ex)
            {
                Msg = ex.Message.ToString();
                return(false);
            }
        }
Esempio n. 4
0
 public bool Update(Code2SessionItem model, out string Msg)
 {
     return(dal.Update(model, out Msg));
 }
Esempio n. 5
0
 public bool Add(Code2SessionItem model, out string Msg)
 {
     return(dal.Add(model, out Msg));
 }