/// <summary> /// 获取用户头像URL地址 /// </summary> /// <param name="model"></param> /// <returns></returns> public string GetUserFaceUrl(int faceID, int customID) { string faceUrl = string.Empty; if (customID == 0) { // 使用系统头像 faceUrl = string.Format("/gamepic/Avatar{0}.png", faceID); } else { AccountsFace faceModel = GetAccountsFace(customID); if (faceModel == null) { // 使用系统头像 faceUrl = string.Format("/gamepic/Avatar{0}.png", faceID); } else { // 生成随机数 Random rand = new Random(); double randomNumber = rand.NextDouble(); // 自定义头像 faceUrl = string.Format("/WS/UserFace.ashx?customid={0}&x={1}", customID, randomNumber); } } return(faceUrl); }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "application/json"; //验证登陆 if (!FacadeManage.aidePlatformManagerFacade.CheckedUserLogon()) { return; } //自定义头像 int customID = GameRequest.GetInt("customid", 0); if (customID == 0) { return; } AccountsFacade accountsFacade = new AccountsFacade(); AccountsFace faceModel = accountsFacade.GetAccountsFace(customID); if (faceModel == null) { return; } else { byte[] faceByte = ( byte[] )faceModel.CustomFace; // 新建画布 int width = 48; int height = 48; Bitmap bitmap = new Bitmap(width, height); // 循环像素 int site = 4; for (int y = 0; y < 48; y++) { for (int x = 0; x < 48; x++) { byte b = faceByte[site - 4]; byte g = faceByte[site - 3]; byte r = faceByte[site - 2]; bitmap.SetPixel(x, y, Color.FromArgb(r, g, b)); site = site + 4; } } // 输出图片 System.IO.MemoryStream ms = new System.IO.MemoryStream( ); bitmap.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); context.Response.ClearContent( ); context.Response.ContentType = "image/jpeg"; context.Response.BinaryWrite(ms.ToArray( )); bitmap.Dispose( ); } }
/// <summary> /// 页面加载 /// </summary> protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } string state = GameRequest.GetQueryString("s"); string type = GameRequest.GetQueryString("y"); if (state == "already") { int gameid = GameRequest.GetQueryInt("g", 0); if (gameid <= 0) { return; } AccountsInfo info = FacadeManage.aideAccountsFacade.GetAccountsInfoByGameID(gameid); if (info == null) { return; } Nickname = info.NickName; Spread = gameid.ToString(); AccountsFace face = FacadeManage.aideAccountsFacade.GetAccountsFace(info.CustomID); FaceUrl = face != null ? face.FaceUrl : FaceUrl; SystemStatusInfo status = FacadeManage.aideAccountsFacade.GetSystemStatusInfo(AppConfig.ConfigInfoKey.JJBindSpreadPresent .ToString()); if (status != null) { Diamond = status.StatusValue.ToString(); } PlatformDownloadUrl = Fetch.GetDownLoadUrl(Page.Request); Title = "推广邀请 - " + AppConfig.PageTitle; } else { string domain = Request.Url.Authority; int gameid = FacadeManage.aideAccountsFacade.GetGameIDByAgentDomain(domain); if (gameid <= 0) { string[] domainStr = domain.Split('.'); if (domainStr.Length == 3 && Regex.IsMatch(domainStr[0], "^[0-9]*$")) { gameid = Convert.ToInt32(domainStr[0]); } else { gameid = GameRequest.GetQueryInt("g", 0); } } Response.Redirect("/Mobile/WxRegister.aspx?t=81&g=" + gameid + (!string.IsNullOrEmpty(type)?"&y=" + type:"")); } }
public Message InsertCustomFace(AccountsFace accountsFace) { System.Collections.Generic.List <System.Data.Common.DbParameter> list = new System.Collections.Generic.List <System.Data.Common.DbParameter>(); list.Add(base.Database.MakeInParam("dwUserID", accountsFace.UserID)); list.Add(base.Database.MakeInParam("imgCustomFace", accountsFace.CustomFace)); list.Add(base.Database.MakeInParam("strClientIP", accountsFace.InsertAddr)); list.Add(base.Database.MakeInParam("strMachineID", accountsFace.InsertMachine)); list.Add(base.Database.MakeOutParam("strErrorDescribe", typeof(string), 127)); return(MessageHelper.GetMessageForObject <AccountsInfo>(base.Database, "NET_PW_InsertCustomFace", list)); }
/// <summary> /// 上传头像 /// </summary> /// <param name="accountsFace"></param> /// <returns></returns> public Message InsertCustomFace(AccountsFace accountsFace) { List <DbParameter> parms = new List <DbParameter>(); parms.Add(Database.MakeInParam("dwUserID", accountsFace.UserID)); parms.Add(Database.MakeInParam("imgCustomFace", accountsFace.CustomFace)); parms.Add(Database.MakeInParam("strClientIP", accountsFace.InsertAddr)); parms.Add(Database.MakeInParam("strMachineID", accountsFace.InsertMachine)); parms.Add(Database.MakeOutParam("strErrorDescribe", typeof(string), 127)); return(MessageHelper.GetMessageForObject <AccountsInfo>(Database, "NET_PW_InsertCustomFace", parms)); }
/// <summary> /// 获取自定义头像实体 /// </summary> /// <param name="customId">自定义头像</param> /// <returns></returns> public AccountsFace GetAccountsFace(int customId) { string sqlQuery = "SELECT * FROM AccountsFace WHERE ID=@ID"; List <DbParameter> prams = new List <DbParameter>(); prams.Add(Database.MakeInParam("ID", customId)); AccountsFace model = Database.ExecuteObject <AccountsFace>(sqlQuery, prams); return(model); }
public void ProcessRequest(HttpContext context) { //允许跨站请求域名 context.Response.AddHeader("Access-Control-Allow-Origin", AppConfig.MoblieInterfaceDomain); context.Response.ContentType = "application/json"; int userid = GameRequest.GetQueryInt("userid", 0); int customId = GameRequest.GetInt("customid", 0); string time = GameRequest.GetQueryString("time"); string sign = GameRequest.GetQueryString("sign"); //签名验证 AjaxJsonValid ajv = Fetch.VerifySignData(userid + AppConfig.MoblieInterfaceKey + time, sign); ////接口版本号 //ajv.SetDataItem("apiVersion", 20171106); //if (ajv.code == (int) ApiCode.VertySignErrorCode) //{ // context.Response.Write(ajv.SerializeToJson()); // return; //} //参数验证 if (userid <= 0 || customId <= 0) { ajv.code = (int)ApiCode.VertyParamErrorCode; ajv.msg = string.Format(EnumHelper.GetDesc(ApiCode.VertyParamErrorCode), ""); context.Response.Write(ajv.SerializeToJson()); return; } AccountsFace faceModel = FacadeManage.aideAccountsFacade.GetAccountsFace(customId); if (faceModel == null || faceModel.UserID != userid) { ajv.msg = "抱歉,头像参数无效"; context.Response.Write(ajv.SerializeToJson()); return; } ConfigInfo webCfg = FacadeManage.aideNativeWebFacade.GetConfigInfo(AppConfig.SiteConfigKey.WebSiteConfig.ToString()); string imageServerHost = webCfg.Field2; ajv.SetValidDataValue(true); ajv.SetDataItem("UserID", faceModel.UserID); ajv.SetDataItem("FaceUrl", string.IsNullOrEmpty(faceModel.FaceUrl) ? "" : (faceModel.FaceUrl.IndexOf("http://", StringComparison.Ordinal) > -1 ? faceModel.FaceUrl : $"{imageServerHost}{faceModel.FaceUrl}")); context.Response.Write(ajv.SerializeToJson()); }
public string GetUserFaceUrl(int faceID, int customID) { string empty = string.Empty; if (customID != 0) { AccountsFace accountsFace = GetAccountsFace(customID); if (accountsFace != null) { Random random = new Random(); double num = random.NextDouble(); return(string.Format("/Tools/UserFace.ashx?customid={0}&x={1}", customID, num)); } return(string.Format("/gamepic/Avatar{0}.png", faceID)); } return(string.Format("/gamepic/Avatar{0}.png", faceID)); }
/// <summary> /// 判断自定义头像是否存在 /// </summary> /// <param name="customID">自定义头像标识</param> /// <returns>存在返回:True 否则返回:False</returns> public bool ExistCustomFace(int customID) { if (customID == 0) { return(false); } else { AccountsFace faceModel = GetAccountsFace(customID); if (faceModel == null) { return(false); } else { return(true); } } }
/// <summary> /// 上传头像 /// </summary> /// <param name="accountsFace"></param> /// <returns></returns> public Message InsertCustomFace(AccountsFace accountsFace) { return(accountsData.InsertCustomFace(accountsFace)); }
/// <summary> /// 上传自定义头像 /// </summary> /// <param name="context"></param> public void UploadFace(HttpContext context) { Message msg = new Message(); AjaxJsonValid ajv = new AjaxJsonValid(); int userID = GameRequest.GetFormInt("userID", 0); // 用户标识 string signature = GameRequest.GetFormString("signature"); // 签名数据 string time = GameRequest.GetFormString("time"); // 过期时间 string clientIP = GameRequest.GetFormString("clientIP"); // 客户端IP string machineID = GameRequest.GetFormString("machineID"); // 机器码ID // 验证签名 //Message message = FacadeManage.aideAccountsFacade.CheckUserSignature(userID, time, signature); //if (!message.Success) //{ // ajv.msg = message.Content; // context.Response.Write(ajv.SerializeToJson()); // return; //} //// 验证数据 //if (string.IsNullOrEmpty(clientIP)) //{ // ajv.msg = "请传入IP地址!"; // context.Response.Write(ajv.SerializeToJson()); // return; //} //if (string.IsNullOrEmpty(machineID)) //{ // ajv.msg = "请传入机器码ID!"; // context.Response.Write(ajv.SerializeToJson()); // return; //} // 最大上传 1M int maxSize = 1048576; // 验证文件格式 if (context.Request.Files.Count == 0) { ajv.msg = "请选择一个头像!"; context.Response.Write(ajv.SerializeToJson()); return; } HttpPostedFile file = context.Request.Files[0]; if (file.InputStream == null || file.InputStream.Length == 0) { ajv.msg = "请上传有效的头像!"; context.Response.Write(ajv.SerializeToJson()); return; } // 验证头像大小 if (file.InputStream.Length > maxSize) { msg.Content = string.Format("头像不能超过 {0} M!", 1); context.Response.Write(ajv.SerializeToJson()); return; } // 尝试转化为图片 System.Drawing.Image image = null; try { image = System.Drawing.Image.FromStream(file.InputStream); } catch { image.Dispose(); msg.Content = string.Format("非法文件,目前只支持图片格式文件,对您使用不便感到非常抱歉。"); context.Response.Write(ajv.SerializeToJson()); return; } //缩放图片 Bitmap bitmap = new Bitmap(48, 48); Graphics g = Graphics.FromImage(bitmap); g.DrawImage(image, 0, 0, 48, 48); //获取像素 int x, y, site = 0; byte[] b = new byte[48 * 48 * 4]; for (y = 0; y < 48; y++) { for (x = 0; x < 48; x++) { Color pixelColor = bitmap.GetPixel(x, y); b[site] = pixelColor.B; b[site + 1] = pixelColor.G; b[site + 2] = pixelColor.R; b[site + 3] = 0; site = site + 4; } } //保存图片 AccountsFace accountsFace = new AccountsFace(); accountsFace.UserID = userID; accountsFace.CustomFace = b; accountsFace.InsertAddr = GameRequest.GetUserIP(); accountsFace.InsertTime = DateTime.Now; msg = FacadeManage.aideAccountsFacade.InsertCustomFace(accountsFace); if (msg.Success) { AccountsInfo model = msg.EntityList[0] as AccountsInfo; ajv.AddDataItem("CustomID", model.CustomID); } ajv.msg = "上传成功!"; ajv.SetValidDataValue(true); context.Response.Write(ajv.SerializeToJson()); //释放资源 image.Dispose(); bitmap.Dispose(); g.Dispose(); }
/// <summary> /// 页面加载 /// </summary> protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { return; } string state = GameRequest.GetQueryString("s"); string type = GameRequest.GetQueryString("y"); if (state == "already") { int gameid = GameRequest.GetQueryInt("g", 0); if (gameid <= 0) { return; } //保存IP绑定信息 string UserIP = GameRequest.GetUserIP(); int result = FacadeManage.aideAccountsFacade.UserIPBind(UserIP, gameid); AccountsInfo info = FacadeManage.aideAccountsFacade.GetAccountsInfoByGameID(gameid); if (info == null) { return; } Nickname = info.NickName.Length > 9 ? (info.NickName.Substring(0, 6) + "...") : info.NickName; Spread = gameid.ToString(); AccountsFace face = FacadeManage.aideAccountsFacade.GetAccountsFace(info.CustomID); FaceUrl = face != null ? face.FaceUrl : FaceUrl; SystemStatusInfo status = FacadeManage.aideAccountsFacade.GetSystemStatusInfo(AppConfig.ConfigInfoKey.JJBindSpreadPresent .ToString()); if (status != null) { Diamond = status.StatusValue.ToString(); } int terminalType = Fetch.GetTerminalType(Request); ConfigInfo config = FacadeManage.aideNativeWebFacade.GetConfigInfo(AppConfig.SiteConfigKey.MobilePlatformVersion.ToString()); if (config != null) { PlatformDownloadUrl = terminalType == 2 ? config.Field5 : config.Field6; } Title = "推广邀请 - " + AppConfig.PageTitle; } else { string domain = Request.Url.Authority; int gameid = FacadeManage.aideAgentFacade.GetGameIDByAgentDomain(domain); if (gameid <= 0) { string[] domainStr = domain.Split('.'); if (domainStr.Length == 3 && Regex.IsMatch(domainStr[0], "^[0-9]*$")) { gameid = Convert.ToInt32(domainStr[0]); } else { gameid = GameRequest.GetQueryInt("g", 0); } } Response.Redirect("/Mobile/WxRegister.aspx?t=81&g=" + gameid + (!string.IsNullOrEmpty(type) ? "&y=" + type : "")); } }