コード例 #1
0
ファイル: loginController.cs プロジェクト: FinchYang/ao
        private bool savePic(string picstr, picType picType, string identity, businessType btype)
        {
            try
            {
                var fpath = Path.Combine(_picpath, identity);

                if (!Directory.Exists(fpath))
                {
                    Directory.CreateDirectory(fpath);
                }
                var fname = Path.Combine(fpath, identity, btype.ToString(), picType + ".jpg");
                var index = picstr.IndexOf("base64,");
                System.IO.File.WriteAllBytes(fname, Convert.FromBase64String(picstr.Substring(index + 7)));
            }
            catch (Exception ex)
            {
                _log.LogInformation("savePic error: {0}", ex);
                return(false);
            }
            return(true);
        }
コード例 #2
0
        public commonresponse downloadpic(picType picType)
        {
            //   highlevel.LogRequest("downloadpic", "downloadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString());

            var accinfo = highlevel.GetInfoByToken(Request.Headers);

            if (accinfo.status != responseStatus.ok)
            {
                return(accinfo);
            }

            try
            {
                var fname = Path.Combine(_picpath, accinfo.Identity, accinfo.businessType.ToString(), picType + ".jpg");
                highlevel.infolog(_log, "downloadpic", fname);
                var bbytes = System.IO.File.ReadAllBytes(fname);
                var retstr = "data:image/jpeg;base64," + Convert.ToBase64String(bbytes);
                try
                {
                    var he = Request.Host.ToString();
                    foreach (var a in Request.Headers)
                    {
                        he += "--" + a.Key + "=" + a.Value;
                    }
                    Task.Run(() => highlevel.LogRequest(he + picType + accinfo.Identity,
                                                        "downloadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString(), (short)accinfo.businessType));
                }
                catch (Exception ex) { _log.LogError("dblog error:", ex); }
                return(new downloadresponse {
                    status = responseStatus.ok, picture = retstr
                });
            }
            catch (Exception ex)
            {
                _log.LogError("{0}-{1}-{2}", DateTime.Now, "downloadpic", ex.Message);
                return(new commonresponse {
                    status = responseStatus.processerror, content = ex.Message
                });
            }
        }
コード例 #3
0
ファイル: loginController.cs プロジェクト: FinchYang/ao
        public commonresponse downloadpic(picType picType)
        {
            LogRequest("downloadpic", "downloadpic", Request.HttpContext.Connection.RemoteIpAddress.ToString());

            var identity = string.Empty;
            var btype    = businessType.basicinfo;

            try
            {
                var htoken = Request.Headers["token"].First();

                if (string.IsNullOrEmpty(htoken))
                {
                    return(new commonresponse {
                        status = responseStatus.tokenerror
                    });
                }
                var found = false;

                foreach (var a in tokens)
                {
                    if (a.Token == htoken)
                    {
                        identity = a.idinfo.Identity;
                        btype    = a.idinfo.businessType;
                        found    = true;
                        break;
                    }
                }
                if (!found)
                {
                    var redisdb     = highlevel.redis.GetDatabase();
                    var cacheidinfo = redisdb.StringGet(htoken);
                    if (cacheidinfo == "nil")
                    {
                        return(new commonresponse {
                            status = responseStatus.tokenerror
                        });
                    }
                    var ci = JsonConvert.DeserializeObject <idinfo>(cacheidinfo);
                    identity = ci.Identity;
                    btype    = ci.businessType;
                }
            }
            catch (Exception ex)
            {
                return(new commonresponse {
                    status = responseStatus.tokenerror
                });
            }

            try
            {
                var fname  = Path.Combine(_picpath, identity, btype.ToString(), picType + ".jpg");
                var bbytes = System.IO.File.ReadAllBytes(fname);
                var retstr = Convert.ToBase64String(bbytes);
                return(new downloadresponse {
                    status = responseStatus.ok, picture = retstr
                });
            }
            catch (Exception ex)
            {
                return(new commonresponse {
                    status = responseStatus.processerror
                });
            }
        }