public static PaiPaiShopInfo GetShopInfo(string uid, string token) { OpenApiOauth client = new OpenApiOauth(oauthId, oauthKey, long.Parse(uid), token); Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("sellerUin", uid); dic.Add("charset", "utf-8"); dic.Add("format", "json"); string result = client.InvokeOpenApi("http://api.paipai.com/shop/getShopInfo.xhtml", dic, null); System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); PaiPaiShopInfo info = null; try { info = js.Deserialize <PaiPaiShopInfo>(result); } catch (Exception ex) { LogInfo.Add("店铺信息序列化出错", "返回json转化为店铺信息出错,用户QQ号:" + uid + result + ex.Message); } return(info); }
/// <summary> /// 执行SQL语句返回DataTable /// </summary> /// <param name="dbstring">SQL语句</param> /// <returns>返回结果的DataTable</returns> public static DataTable ExecuteDataTable(string dbstring, params SqlParameter[] sqlparam) { Database db = DatabaseFactory.CreateDatabase(); dbstring = ReplaceSQL(dbstring); DbCommand dbCommand = db.GetSqlStringCommand(dbstring); dbCommand.Parameters.AddRange(sqlparam); DataTable dt = new DataTable(); try { //HttpContext.Current.Response.Write(dbstring + "<br>"); dt = db.ExecuteDataSet(dbCommand).Tables[0]; } catch (Exception e) { db = null; LogInfo.Add(dbstring, e.Message); //utils.ShowErrorPage("执行SQL语句时时出错:\r\n" + dbstring + "\r\n\r\n下面为具体错误信息:\r\n" + e.Message); } return(dt); }
public static IList <TaoBaoGoodsClassInfo> GetGoodsClassInfoList(string nickNo, string session) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("nick", nickNo); dic.Add("fields", "cid,name,parent_cid"); string text = Post("taobao.sellercats.list.get", session, dic); IList <TaoBaoGoodsClassInfo> classList = null; if (!string.IsNullOrEmpty(text)) { if (text.Contains("error_response")) { LogInfo.Add("查找商品销售分类出错", text); return(null); } System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); text = text.Replace("{\"sellercats_list_get_response\":{\"seller_cats\":{\"seller_cat\":", "").Replace("]}}}", "") + "]"; try { classList = js.Deserialize <List <TaoBaoGoodsClassInfo> >(text); } catch (Exception ex) { LogInfo.Add("返回json转化为一个商品销售分类出错", text + ex.Message); return(null); } } return(classList); }
public static List <GoodsInfo> GetGoodsInfoList(string nick, string session, string pids) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("num_iids", pids); dic.Add("fields", "num_iid,title,nick,price,pic_url"); string text = Post(nick, "taobao.items.list.get", session, dic, DataFormatType.json); List <GoodsInfo> list = new List <GoodsInfo>(); if (!string.IsNullOrEmpty(text)) { if (text.Contains("error_response")) { LogInfo.Add("批量获取商品信息出错", text); return(list); } System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); text = text.Replace("{\"items_list_get_response\":{\"items\":{\"item\":", "").Replace("}}}", ""); try { list = js.Deserialize <List <GoodsInfo> >(text); } catch (Exception ex) { LogInfo.WriteLog("返回json转化为商品信息集合出错,商品id:" + pids, text + ex.Message); } } return(list); }
/// <summary> /// 根据一个商品ID获得一个商品信息 /// </summary> /// <param name="pid">淘宝商品ID</param> /// <returns></returns> public static GoodsInfo GetGoodsInfo(string pid, string nick, string session) { Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("num_iid", pid); dic.Add("fields", "num_iid,title,nick,price,pic_url"); string text = Post(nick, "taobao.item.get", session, dic, DataFormatType.json); GoodsInfo info = new GoodsInfo(); if (!string.IsNullOrEmpty(text)) { if (text.Contains("error_response")) { LogInfo.Add("获取一个商品信息出错", text); return(info); } System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); text = text.Replace("{\"item_get_response\":{\"item\":", "").Replace("}}", ""); try { info = js.Deserialize <GoodsInfo>(text); } catch (Exception ex) { LogInfo.WriteLog("返回json转化为一个商品信息出错,商品id:" + pid, text + ex.Message); } } return(info); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!string.IsNullOrEmpty(Request.QueryString["istongji"])) { CacheCollection.RemoveCacheByKey(CacheCollection.KEY_ALLBUYNINFO); string nick = Request.QueryString["nick"]; string session = Request.QueryString["session"]; if (Request.Cookies["nick"] == null) { IList <TaoBaoGoodsClassInfo> classList = TopAPI.GetGoodsClassInfoList(nick, session); if (classList != null) { TaoBaoGoodsClassService tbgcDal = new TaoBaoGoodsClassService(); foreach (TaoBaoGoodsClassInfo cinfo in classList) { tbgcDal.InsertGoodsClass(cinfo, nick); } } GoodsService goodsDal = new GoodsService(); IList <TaoBaoGoodsInfo> list = TopAPI.GetGoodsInfoListByNick(nick, session); foreach (TaoBaoGoodsInfo info in list) { goodsDal.InsertGoodsInfo(info, nick); } } HttpCookie cookie = new HttpCookie("nick", HttpUtility.UrlEncode(nick)); HttpCookie cooksession = new HttpCookie("nicksession", session); cookie.Expires = DateTime.Now.AddDays(1); cooksession.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(cookie); LogInfo.Add("添加了cookie", nick); Session["snick"] = nick; Session["ssession"] = session; Response.Cookies.Add(cooksession); HttpCookie tongji = new HttpCookie("istongji", Request.QueryString["istongji"]); tongji.Expires = DateTime.Now.AddDays(1); Response.Cookies.Add(tongji); Response.Redirect("http://www.7fshop.com/top/index.html"); } } }
/// <summary> /// 应该可获取局域网访问者的MAC(未测) /// </summary> /// <returns></returns> public string GetClientMAC() { try { string userip = GetIPAddress(); Int32 ldest = inet_addr(userip); //目的地的ip Int32 lhost = inet_addr("223.4.6.115"); //本地服务器的ip Int64 macinfo = new Int64(); Int32 len = 6; int res = SendARP(ldest, 0, ref macinfo, ref len); string mac_src = macinfo.ToString("X"); if (mac_src == "0") { if (userip == "127.0.0.1") { return("Localhost!"); } else { return("null"); } } while (mac_src.Length < 12) { mac_src = mac_src.Insert(0, "0"); } string mac_dest = ""; for (int i = 0; i < 11; i++) { if (0 == (i % 2)) { if (i == 10) { mac_dest = mac_dest.Insert(0, mac_src.Substring(i, 2)); } else { mac_dest = "-" + mac_dest.Insert(0, mac_src.Substring(i, 2)); } } } return(mac_dest); } catch (Exception err) { LogInfo.Add("获取mac", err.Message); return(err.Message); } }
public static List <TaoBaoGoodsInfo> GetGoodsInfoListByNick(string nick, string session) { bool notlast = true; int page_no = 0; List <TaoBaoGoodsInfo> list = new List <TaoBaoGoodsInfo>(); System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); while (notlast) { page_no++; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("nick", nick); dic.Add("fields", "num_iid,title,cid,pic_url,price,seller_cids,num,modified"); dic.Add("page_no", page_no.ToString()); dic.Add("page_size", "200"); string text = Post("taobao.items.onsale.get", session, dic); if (!string.IsNullOrEmpty(text)) { if (text.Contains("error_response")) { LogInfo.Add(nick, "批量获取用户店铺商品列表出错" + text); return(list); } text = text.Replace("{\"items_onsale_get_response\":{\"items\":{\"item\":", "").Replace("}}}", ""); Regex regex = new Regex("},\"total_results\":\\d+}}"); text = regex.Replace(text, ""); try { List <TaoBaoGoodsInfo> mylist = js.Deserialize <List <TaoBaoGoodsInfo> >(text); list.AddRange(mylist); if (mylist.Count < 200) { notlast = false; return(list); } } catch (Exception ex) { LogInfo.Add(nick, "返回json转化为商品信息集合出错,用户nick:" + nick + text + ex.Message); } } } return(list); }
public void Log(LogInfo logInfo) { LogInfo.Add(logInfo); if (logInfo.Severity == LogSeverity.Error) { NoErrors++; } else if (logInfo.Severity == LogSeverity.Warning) { NoWarnings++; } else { NoMessages++; } if (logInfo.Severity == LogSeverity.Error && PauseOnError) { UnityEngine.Debug.Break(); } }
public static IList <GoodsOrderInfo> GetGoodsOrderInfo(string uid, string token) { OpenApiOauth client = new OpenApiOauth(oauthId, oauthKey, long.Parse(uid), token); List <GoodsOrderInfo> list = new List <GoodsOrderInfo>(); int pageindex = 0; while (true) { pageindex++; Dictionary <string, string> dic = new Dictionary <string, string>(); dic.Add("sellerUin", uid); dic.Add("charset", "utf-8"); dic.Add("format", "json"); dic.Add("pageSize", "20"); dic.Add("pageIndex", pageindex.ToString()); string result = client.InvokeOpenApi("http://api.paipai.com/deal/sellerSearchDealList.xhtml", dic, null); System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); result = result.Substring(result.IndexOf("\"dealList\":[")); result = result.Replace("\"dealList\":[", "["); result = result.Substring(0, result.Length - 2); //Regex regex = new Regex("},\"total_results\":\\d+}}"); //result = regex.Replace(result, ""); try { List <GoodsOrderInfo> newList = js.Deserialize <List <GoodsOrderInfo> >(result); if (newList.Count == 0) { break; } list.AddRange(newList); } catch (Exception ex) { LogInfo.Add("订单序列化出错", "返回json转化为订单信息集合出错,用户QQ号:" + uid + result + ex.Message); } } return(list); }
/// <summary> /// 执行无返回的SQL语句 /// </summary> /// <param name="dbstring">SQL语句</param> /// <returns>是否成功,0失败,1成功</returns> public static int ExecuteNonQuery(string dbstring, params SqlParameter[] sqlparam) { // dbstring = RewriteQueryInMultiLangMode(dbstring); Database db = DatabaseFactory.CreateDatabase(); dbstring = ReplaceSQL(dbstring); DbCommand dbCommand = db.GetSqlStringCommand(dbstring); dbCommand.Parameters.AddRange(sqlparam); try { return(db.ExecuteNonQuery(dbCommand)); } catch (Exception e) { //utils.ShowErrorPage("执行SQL语句时时出错:\r\n" + dbstring + "\r\n\r\n下面为具体错误信息:\r\n" + e.Message); //return 1; LogInfo.Add(dbstring, e.Message); return(0); } }
protected void Page_Load(object sender, EventArgs e) { if (string.IsNullOrEmpty(Request.QueryString["code"])) { Response.Write("请从淘宝授权登录"); Response.End(); return; } IDictionary <string, string> param = new Dictionary <string, string>(); param.Add("client_id", "21093339"); param.Add("client_secret", "c1c22ba85fb91bd20279213ef7b9ee80"); param.Add("grant_type", "authorization_code"); param.Add("code", Request.QueryString["code"]); param.Add("redirect_uri", "http://www.fensehenghuo.com/containerNew.aspx"); string result = ""; HttpWebRequest req = (HttpWebRequest)WebRequest.Create("https://oauth.taobao.com/token"); req.Method = "POST"; req.KeepAlive = true; req.Timeout = 300000; req.ContentType = "application/x-www-form-urlencoded;charset=gb2312"; byte[] postData = Encoding.UTF8.GetBytes(PostData(param)); Stream reqStream = req.GetRequestStream(); reqStream.Write(postData, 0, postData.Length); reqStream.Close(); try { HttpWebResponse rsp = (HttpWebResponse)req.GetResponse(); Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet); Stream stream = null; StreamReader reader = null; stream = rsp.GetResponseStream(); reader = new StreamReader(stream, encoding); result = reader.ReadToEnd(); if (reader != null) { reader.Close(); } if (stream != null) { stream.Close(); } if (rsp != null) { rsp.Close(); } } catch (Exception ex) { LogInfo.Add("淘宝进入异常", ex.Message); } System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); ValiInfo info = js.Deserialize <ValiInfo>(result); top_session = info.access_token; refreshToken = info.refresh_token; nick = HttpUtility.UrlDecode(info.taobao_user_nick); if (nick == null || nick == "") { Response.Write("top签名验证不通过,请不要非法注入"); Response.End(); return; } //判断跳转 GetVersion(nick); GetData(nick); }