<%@ WebHandler Language="C#" Class="chromeSaveUrlData" %> using System; using System.Web; using System.Runtime.Serialization.Json; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using System.Web.Services.Protocols; using System.Security.Cryptography; using System.Text; using System.Web.SessionState; using System.Data; using System.Collections.Generic; using System.IO.Compression; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Linq; using Facebook; using System.Net; using System.Collections.Specialized; public class chromeSaveUrlData : IHttpHandler { public void ProcessRequest(HttpContext context) { result objRet = new result(); DataContractJsonSerializer json = new DataContractJsonSerializer(objRet.GetType()); context.Response.ContentType = "application/json;charset=utf-8"; context.Response.AddHeader("Access-Control-Allow-Origin", "*"); string id = (context.Request["id"] == null) ? "" : context.Request["id"].ToString(); string pwd = (context.Request["pwd"] == null) ? "" : context.Request["pwd"].ToString(); string method = (context.Request["method"] == null) ? "" : context.Request["method"].ToString(); string project_uid = (context.Request["project_uid"] == null) ? "" : context.Request["project_uid"].ToString(); string url_uid = (context.Request["url_uid"] == null) ? "" : context.Request["url_uid"].ToString(); string url_descript = (context.Request["url_descript"] == null) ? "" : context.Request["url_descript"].ToString(); string url_directToUrl = (context.Request["url_directToUrl"] == null) ? "" : context.Request["url_directToUrl"].ToString(); string url_Code = (context.Request["url_Code"] == null) ? "" : context.Request["url_Code"].ToString(); string url_gifTag = (context.Request["url_gifTag"] == null) ? "N" : context.Request["url_gifTag"].ToString(); string url_gifLink = (context.Request["url_gifLink"] == null) ? "" : context.Request["url_gifLink"].ToString(); string url_fbTag = (context.Request["url_fbTag"] == null) ? "N" : context.Request["url_fbTag"].ToString(); string url_fbTitle = (context.Request["url_fbTitle"] == null) ? "" : context.Request["url_fbTitle"].ToString(); string url_fbDescript = (context.Request["url_fbDescript"] == null) ? "" : context.Request["url_fbDescript"].ToString(); string url_fbPixel = (context.Request["url_fbPixel"] == null) ? "N" : context.Request["url_fbPixel"].ToString(); string url_fbPixelCode = (context.Request["url_fbPixelCode"] == null) ? "" : context.Request["url_fbPixelCode"].ToString(); string url_googleAds = (context.Request["url_googleAds"] == null) ? "N" : context.Request["url_googleAds"].ToString(); string url_googleAwConversionId = (context.Request["url_googleAwConversionId"] == null) ? "" : context.Request["url_googleAwConversionId"].ToString(); string url_playBtn = (context.Request["url_playBtn"] == null) ? "N" : context.Request["url_playBtn"].ToString(); string pic_data = (context.Request["pic_data"] == null) ? "" : context.Request["pic_data"].ToString(); string url_photoId = ""; string errmsg = ""; if (url_descript == "") { errmsg += "沒有短網址說明!\n"; } if (url_descript == "") { errmsg += "沒有短網址說明!\n"; } if (url_Code == "") { errmsg += "沒有短網址碼!\n"; } if (url_directToUrl == "") { errmsg += "沒有目的地網址!\n"; } if (project_uid == "") { errmsg += "沒有專案代碼!\n"; } if (method == "") { errmsg += "Method!\n"; } if (errmsg.Length > 0) { objRet.ret = "no"; objRet.err_code = "0005"; objRet.message = errmsg; json.WriteObject(context.Response.OutputStream, objRet); return; } string user_sql = string.Format("select * from users where user_id = '{0}'", id); autoBindDataTable objUser = new autoBindDataTable(user_sql); if (objUser.dataRows.Count == 0) { string elab_sql = string.Format("select * from new_userdata where userid = '{0}'", id); autoBindElab objElabUser = new autoBindElab(elab_sql); if (objElabUser.dataRows.Count == 0) { objRet.ret = "no"; objRet.err_code = "0001"; objRet.message = "無此帳號密碼!"; json.WriteObject(context.Response.OutputStream, objRet); return; } else { objRet.ret = "no"; objRet.err_code = "0002"; objRet.message = "此帳號尚未擁有權限,請專案管理者加入權限!"; json.WriteObject(context.Response.OutputStream, objRet); return; } } else { //系統內建帳號 if (objUser.dataRows[0]["user_type"].ToString() == "Y") { if (objUser.dataRows[0]["user_onjob"].ToString() == "N") { objRet.ret = "no"; objRet.err_code = "0003"; objRet.message = "此帳號已經離職!"; json.WriteObject(context.Response.OutputStream, objRet); return; } if (pwd != SHA256_Encode(objUser.dataRows[0]["user_pwd"].ToString())) { string test = SHA256_Encode(objUser.dataRows[0]["user_pwd"].ToString()); objRet.ret = "no"; objRet.err_code = "0004"; objRet.message = "密碼有誤!"; json.WriteObject(context.Response.OutputStream, objRet); return; } } //E白板帳號 if (objUser.dataRows[0]["user_type"].ToString() == "N") { string elab_sql = string.Format("select * from new_userdata where userid = '{0}'", id); autoBindElab objElabUser = new autoBindElab(elab_sql); if (objElabUser.dataRows.Count == 0) { objRet.ret = "no"; objRet.err_code = "0001"; objRet.message = "無此帳號密碼!"; json.WriteObject(context.Response.OutputStream, objRet); return; } else { if (objElabUser.dataRows[0]["onjob"].ToString() == "1") { objUser.dataRows[0]["user_onjob"] = "N"; objUser.updateDataTable(); objRet.ret = "no"; objRet.err_code = "0003"; objRet.message = "此帳號已經離職!"; json.WriteObject(context.Response.OutputStream, objRet); return; } if (pwd != SHA256_Encode(objElabUser.dataRows[0]["userpw"].ToString())) { objRet.ret = "no"; objRet.err_code = "0004"; objRet.message = "密碼有誤!"; json.WriteObject(context.Response.OutputStream, objRet); return; } } } if (method == "add") { string checkString = string.Format("select * from url where url_Code Collate SQL_Latin1_General_CP1_CS_AS = '{0}'", url_Code); autoBindDataTable checkSQL = new autoBindDataTable(checkString); if (checkSQL.dataRows.Count > 0) { objRet.ret = "no"; objRet.err_code = "0006"; objRet.message = "此短網址已經被使用了,請換一組短網址碼再試一次!"; json.WriteObject(context.Response.OutputStream, objRet); return; } url_uid = globalClass.CreateRandomCode(32); url_photoId = globalClass.CreateRandomCode(36); urlObj objUrl = new urlObj(); objUrl.url_uid = url_uid; objUrl.project_uid = project_uid; objUrl.url_descript = url_descript; objUrl.url_directToUrl = url_directToUrl; objUrl.url_Code = url_Code; objUrl.url_playBtn = url_playBtn; objUrl.url_fbTag = url_fbTag; objUrl.url_gifTag = url_gifTag; objUrl.url_gifLink = url_gifLink; objUrl.url_fbTitle = url_fbTitle; objUrl.url_fbDescript = url_fbDescript; objUrl.url_fbPixel = url_fbPixel; objUrl.url_fbPixelCode = url_fbPixelCode; objUrl.url_googleAds = url_googleAds; objUrl.url_googleAwConversionId = url_googleAwConversionId; objUrl.url_createUid = id; objUrl.url_photoId = url_photoId; string picChange = "N"; JToken jsonObj; string base64Img = ""; try { jsonObj = JValue.Parse(pic_data); picChange = jsonObj[0]["meta"]["picChange"].ToString(); base64Img = jsonObj[0]["output"]["image"].ToString(); } catch { } if (picChange == "Y") { //base64Img = jsonObj[0]["output"]["image"].ToString(); objUrl.pic_image = globalClass.Base64ToImage(base64Img); } try { objUrl.updateData(); objRet.data = objUrl; objRet.ret = "yes"; } catch (Exception ex) { objRet.ret = "no"; objRet.err_code = "9999"; objRet.message = ex.Message; } json.WriteObject(context.Response.OutputStream, objRet); return; } } } string SHA256_Encode(string value) { byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(value); try { SHA256 sha256 = new SHA256CryptoServiceProvider(); byte[] retVal = sha256.ComputeHash(bytValue); StringBuilder sb = new StringBuilder(); for (int i = 0; i < retVal.Length; i++) { sb.Append(retVal[i].ToString("x2")); } return sb.ToString(); } catch (Exception ex) { throw new Exception("GetSHA256HashFromString() fail,error:" + ex.Message); } } public class result { public string ret = "no"; public string err_code = "0000"; public string message = ""; public urlObj data = new urlObj(); } public bool IsReusable { get { return false; } } }