public TokenExpireCheckResult GetTokenExpireDate(string token) { TokenExpireCheckResult result = new TokenExpireCheckResult(); try { List<Dictionary<string, string>> dic = new List<Dictionary<string, string>>(); var req = new GetTokenStatusRequest { EbayTokenID = token }; var res = new ItemService(UrlConst.Instance.CBT_GEPAPI_URL + "api/Outbound_ItemService").GetTokenStatus(req); foreach (var data in res.Response) { if (data.Key == "ExpirationTime") { result.Date = DateTime.Parse(data.Value); } result.Result = true; } } catch (Exception ex) { result.Result = false; } return result; }
/// <summary> /// eBay에 리스팅후 결과를 반환한다. /// </summary> /// <param name="data">eBay 리스팅 대기상품</param> /// <returns></returns> private ResultSet SetListItem(eBayItemsData data) { ResultSet result = new ResultSet(); try { TaInfo taInfo = new BizDac.TaInfoBiz().FindTaUser(data.ta); var queryTainfo = (from t in taInfo.accounts where ((int)t.site_id) == data.site select t).ToList(); //사이트 정보가 없으면 에러 if (queryTainfo.Count() == 0) { result.isResult = false; result.Message = "사이트 정보가 없습니다"; return result; } ListItemRequest req = new ListItemRequest(); //등록과 재등록을 구분해 준다. if (String.IsNullOrEmpty(data.itemno)) { logger.Info("forSeller listing id : " + data._id); req = new ListItemRequest { EbayItemInfo = CreateJsonData(data) , EbayTokenID = queryTainfo[0].token , InventoryID = data._id.ToString() , SiteID = data.site , ItemID = "" }; } else { logger.Info("forSeller relisting id : " + data._id); req = new ListItemRequest { EbayItemInfo = CreateJsonData(data) , EbayTokenID = queryTainfo[0].token , InventoryID = data._id.ToString() , SiteID = data.site ,ItemID = data.itemno.ToString() }; } var res = new ItemService(apiUrl).ListItem (req); result.eBayResponse = res.Response; if (res.Ack == AckType.Failure) { result.isResult = false; result.Message = "eBay 리스팅에 실패했습니다."; } else { result.isResult = true; } } catch (Exception ex) { result.Message = ex.Message.ToString(); } return result; }
/// <summary> /// eBayItem Revise /// 리스팅 중인 상품의 eBay 정보를 수정하고 GEP의 eBay 정보를 update 한다. /// </summary> /// <param name="id">eBay_items 컬렉션의 _id, Inventory ID로 사용됨</param> /// <param name="data">수정할 상품정보</param> /// <returns></returns> public Boolean ReviseItem(String id, eBayItemsDataForSeller data) { var asis = GetEbayItemData(id); if (!asis.dynamicData.ListingDuration.Equals(data.ListingDuration)) { //리스팅 종료일 재계산 : 오늘 날짜 + data.ListingDuration + 7일 DateTime new_edt = DateTime.Today.AddDays(data.ListingDuration + 7); //clone 상품 팔자주문 변경 bool res = new ItemOrderBiz().EditCloneItemOrder(asis.cln_itemno, new_edt, asis.gep_info.src_price, asis.gep_info.src_settle_price, asis.gep_info.src_qty, asis.ta, ""); //실패시 eBay 상품정보 Revise 하지 않음. if (res == false) return false; } //eBay 상품 정보 수정 //실패시 eBay_Items 수정하지 않음. JsonWriterSettings jset = new JsonWriterSettings(); jset.OutputMode = JsonOutputMode.JavaScript; var result = new ItemService(apiUrl).ReviseItem(new ReviseItemRequest { EbayItemInfo = Util.EncodeUTF8To64(data.ToJson(jset)), EbayTokenID = new CommonBiz().GeteBayToken(asis.ebay_acnt), InventoryID = id, ItemID = asis.itemno, SiteID = asis.site, }); if (!result.Ack.Equals(AckType.Success)) { return false; } //eBay_Items 수정 if (SeteBayItems(id, data) < 0) return false; //모두 성공하면 true 리턴 return true; }
/// <summary> /// ebay_items의 _id 상품에 대하여 판매 중지 요청 /// </summary> /// <param name="id">ebay_items 컬렉션의 id 임. eBay 의 실제 상품 번호 아님!</param> /// <returns> /// 성공시 Success = true, Message = null /// 실패시 Success = false, Messsage = 실패사유 /// </returns> public eBayItemResultBase RequestStopListing(string id) { eBayItemsData info = new eBayItemDac().View(Query.EQ("_id", ObjectId.Parse(id))); if (String.IsNullOrWhiteSpace(info.itemno)) { return new eBayItemResultBase { Success = false, Message = "eBay 상품번호가 없어 판매중지요청을 할 수 없습니다." }; } if (string.IsNullOrWhiteSpace(info.ebay_acnt)) { return new eBayItemResultBase { Success = false, Message = "eBay 계정이 존재하지 않거나 유효한 eBay 계정이 아닙니다." }; } //TODO valid한 SiteID인지도 체크 해야되! 근데 valid한 SiteID가 뭔지를 몰라 ㅋㅋㅋㅋㅋ var ebayToken = new CommonBiz().GeteBayTokenId(info.ebay_acnt); if (String.IsNullOrWhiteSpace(ebayToken)) { return new eBayItemResultBase { Success = false, Message = "eBay 계정이 존재하지 않거나 유효한 eBay 계정이 아닙니다." }; } var request = new CloseItemRequest { EbayTokenID = ebayToken, ItemID = info.itemno, SiteID = info.site }; var response = new ItemService(apiUrl).CloseItem(request); if (response.Ack.Equals(AckType.Failure)) { return new eBayItemResultBase { Success = false, Message = (from messages in response.Response.Messages select messages[AckType.Failure.ToString()]).ToArray().ToString() }; } //TODO 해당 eBay item 판매중지상태로 update SaveItemStatus(new ObjectId(id), eBayItemStat.Stop); //clone 상품 팔자주문 내리기 new ItemOrderBiz().DeleteOrder(info.gep_info.src_no, info.gep_info.src_seller.sid, info.gep_info.src_seller.sid); return new eBayItemResultBase { Success = true }; }
/// <summary> /// forSeller와 thirft통신하여 카테고리별 상세 정보를 가져온다. /// </summary> /// <param name="siteid">사이트 아이디</param> /// <param name="categoryID">카테고리 아이디</param> /// <returns></returns> public ebayItemDataForSeller GetForSellerDataParseJSON(int siteid, long categoryID) { var req = new GetSiteDetailsRequest { SiteID = siteid , CategoryID = categoryID.ToString() }; var res = new ItemService(apiUrl).GetSiteDetails(req); //thirft통신으로 인코딩되서 넘어온것을 디코딩 한다. string JsonData = Encoding.ASCII.GetString(Convert.FromBase64String(res.Response)); ebayItemDataForSeller Data = new ebayItemDataForSeller(); List<ebayItemDataForSellerDetail> Details = new List<ebayItemDataForSellerDetail>(); JSONObject jsonObject = JSONObject.CreateFromString(JsonData); JSONObject jsonDetails = jsonObject.Dictionary["details"]; Data.site = jsonObject.Dictionary["site"].String; //카테고리값이 잘못 들어갈 경우 이값이 안들어와서 에러가 날수 있다. if (jsonObject.Dictionary.Keys.Contains("translated_category_full_path")) { JSONObject KorCateName = jsonObject.Dictionary["translated_category_full_path"]; Data.translated_category_full_path = KorCateName.String; } #region currency 채움. JSONObject jsonCurrency = jsonObject.Dictionary["currency"]; Data.currency.buy = jsonCurrency.Dictionary["buy"].String; Data.currency.change_val = jsonCurrency.Dictionary["change_val"].String; Data.currency.hname = jsonCurrency.Dictionary["hname"].String; Data.currency.receive = jsonCurrency.Dictionary["receive"].String; Data.currency.sell = jsonCurrency.Dictionary["sell"].String; Data.currency.send = jsonCurrency.Dictionary["send"].String; Data.currency.sign = jsonCurrency.Dictionary["sign"].String; Data.currency.standard = jsonCurrency.Dictionary["standard"].String; #endregion #region categories 채움 //categories 채움 foreach (var SubData in jsonObject.Dictionary["categories"].Array) { Data.categories.Add(new Categori() { AutoPayEnabled = Convert.ToBoolean(SubData.Dictionary["AutoPayEnabled"].String) , BestOfferEnabled = Convert.ToBoolean(SubData.Dictionary["BestOfferEnabled"].String) , CategoryName = SubData.Dictionary["CategoryName"].String , CategoryID = Convert.ToInt32(SubData.Dictionary["CategoryID"].String) , CategoryLevel = Convert.ToInt32(SubData.Dictionary["CategoryLevel"].String) , CategoryParentID = Convert.ToInt32(SubData.Dictionary["CategoryParentID"].String) }); } #endregion #region Controll 채움 List<JSONObject> detailObject = new List<JSONObject>(); foreach (var data in jsonDetails.Array) { ebayItemDataForSellerDetail Detail = new ebayItemDataForSellerDetail(); Detail.fieldName = data.Dictionary["field_name"].String; Detail.fieldNameKr = data.Dictionary["field_name_kr"].String; Detail.type = data.Dictionary["type"].String; Detail.isrequire = data.Dictionary.Keys.Contains("isrequire") == true ? data.Dictionary["isrequire"].String : ""; Detail.length = data.Dictionary.Keys.Contains("length") == true ? Util.GetSafeInt(data.Dictionary["length"].String) : 900; //Value 부분 List<ebayItemDataForSellerValues> Values = new List<ebayItemDataForSellerValues>(); // value안에 depth가 있는 특이부분 if (data.Dictionary.Keys.Contains("values") && Detail.type != "LIST" && Detail.fieldName == "ListingDuration") { foreach (var valuesData in data.Dictionary["values"].Dictionary) { ebayItemDataForSellerValues settingsValues = new ebayItemDataForSellerValues(); settingsValues.key = valuesData.Key; List<ebayItemDataForSellerValuesDepth1> listDepth = new List<ebayItemDataForSellerValuesDepth1>(); foreach (var valuesDataDepth1 in valuesData.Value.Array) { ebayItemDataForSellerValuesDepth1 depth1 = new ebayItemDataForSellerValuesDepth1(); depth1.key = valuesDataDepth1.Dictionary["key"].String; depth1.value = valuesDataDepth1.Dictionary["value"].String; depth1.show_value = valuesDataDepth1.Dictionary["show_value"].String; listDepth.Add(depth1); } settingsValues.settingsValuesDepth1 = listDepth; Values.Add(settingsValues); } Detail.values = Values; } //상품 상세 정보 채움. else if (Detail.fieldName == "ItemSpecifics") { foreach (var SubData in data.Dictionary["values"].Array) { string Name = SubData.Dictionary["Name"].String; ValidationRules ValidationRules = new GEP.Data.ValidationRules(); List<ValueRecommendation> ValueRecommendations = new List<GEP.Data.ValueRecommendation>(); if (SubData.Dictionary.Keys.Contains("ValueRecommendation")) { if (SubData.Dictionary["ValueRecommendation"].Array != null) { foreach (var t in SubData.Dictionary["ValueRecommendation"].Array) { ValueRecommendation ValueRecommendation = new ValueRecommendation(); if (t.Dictionary.Keys.Contains("Value")) { ValueRecommendation.Value = t.Dictionary["Value"].String; } if (t.Dictionary.Keys.Contains("ValidationRules")) { ValueRecommendation.ValidationRules = CreateValidationRules(t.Dictionary["ValidationRules"]); } ValueRecommendations.Add(ValueRecommendation); } } } if (SubData.Dictionary.Keys.Contains("ValidationRules")) { ValidationRules = CreateValidationRules(SubData.Dictionary["ValidationRules"]); } ebayItemDataForSellerValues Value = new ebayItemDataForSellerValues(); Value.Name = Name; Value.ValidationRules = ValidationRules; Value.ValueRecommendation = ValueRecommendations; Values.Add(Value); } Detail.values = Values; } //나머지 데이터 else { if (data.Dictionary.Keys.Contains("values")) { if (data.Dictionary["values"].Array != null) { foreach (var valuesData in data.Dictionary["values"].Array) { //데이터가 들쑥날쑥해서 있는지 없는지 꼭 체크 해줘야함. ebayItemDataForSellerValues Value = new ebayItemDataForSellerValues(); if (valuesData.Dictionary.Keys.Contains("key")) { Value.key = valuesData.Dictionary["key"].String; } if (valuesData.Dictionary.Keys.Contains("value")) { Value.value = valuesData.Dictionary["value"].String; } if (valuesData.Dictionary.Keys.Contains("Description")) { Value.description = valuesData.Dictionary["Description"].String; } if (valuesData.Dictionary.Keys.Contains("Location")) { Value.location = valuesData.Dictionary["Location"].String; } if (valuesData.Dictionary.Keys.Contains("Region")) { Value.region = valuesData.Dictionary["Region"].String; } if (valuesData.Dictionary.Keys.Contains("show_value")) { Value.show_value = valuesData.Dictionary["show_value"].String; } Values.Add(Value); } } else { var valuesData = data.Dictionary["values"]; ebayItemDataForSellerValues Value = new ebayItemDataForSellerValues(); if (valuesData.Dictionary.Keys.Contains("key")) { Value.key = valuesData.Dictionary["key"].String; } if (valuesData.Dictionary.Keys.Contains("value")) { Value.value = valuesData.Dictionary["value"].String; } if (valuesData.Dictionary.Keys.Contains("Description")) { Value.description = valuesData.Dictionary["Description"].String; } if (valuesData.Dictionary.Keys.Contains("Location")) { Value.location = valuesData.Dictionary["Location"].String; } if (valuesData.Dictionary.Keys.Contains("Region")) { Value.region = valuesData.Dictionary["Region"].String; } if (valuesData.Dictionary.Keys.Contains("show_value")) { Value.show_value = valuesData.Dictionary["show_value"].String; } Values.Add(Value); } } Detail.values = Values; } Details.Add(Detail); } Data.details = Details; #endregion return Data; }
/// <summary> /// eBay Verify /// </summary> public eBayItemVerifyResult Verify(string _id, string ta_id) { eBayItemsData info = new eBayItemDac().View(Query.EQ("_id", ObjectId.Parse(_id))); VerifyItemRequest req = new VerifyItemRequest(); req.SiteID = info.site; req.EbayTokenID = new CommonBiz().GeteBayToken(info.ebay_acnt); if (info.itemno != null) req.InventoryID = Util.GetSafeString(info.itemno); JsonWriterSettings jset = new JsonWriterSettings(); jset.OutputMode = JsonOutputMode.JavaScript; req.EbayItemInfo = Util.EncodeUTF8To64(info.dynamicData.ToJson<eBayItemsDataForSeller>(jset)); // base64(json)로 데이터 생성 eBayItemVerifyResult result = new eBayItemVerifyResult(); VerifyItemResponse res = new VerifyItemResponse(); try { res = new ItemService(apiUrl).VerifyItem(req); if (res.Ack == AckType.Success) // Thrift 통신 성공 { if (res.Response.Ack == AckType.Success) // Verify 결과 { result.Success = true; result.Message = "Verify 성공하였습니다."; } else { result.Success = false; result.Message = ""; foreach (Dictionary<string, string> msg in res.Response.Messages) { foreach (string key in msg.Keys) { result.Message += "[" + key + "] " + msg[key] + "\n"; } } } } else { result.Success = false; result.Message = "Thrift 통신에 실패하였습니다."; } } catch (ThriftClientException tce) { result.Success = false; //result.Message = "알 수 없는 오류로 인하여 eBay 상품 Verify에 실패하였습니다."; result.Message = tce.Message; } catch (ThriftException te) { result.Success = false; //result.Message = "알 수 없는 오류로 인하여 eBay 상품 Verify에 실패하였습니다."; result.Message = te.ExceptionMessage; } catch (Exception ex) { result.Success = false; //result.Message = "알 수 없는 오류로 인하여 eBay 상품 Verify에 실패하였습니다."; result.Message = ex.Message; } // Verify 결과 저장 // 심민섭 수정 // 실패시 메세지 저장 string ver_code = result.Success == true ? "성공" : "실패"; new eBayItemDac().Save(Query.EQ("_id", ObjectId.Parse(_id)), Update.Set("ver_code", ver_code).Set("ver_message", result.Message)); return result; }
/// <summary> /// eBay 카테고리를 검색한다. /// </summary> /// <param name="id">사이트 ID</param> /// <param name="serchString">검색어</param> /// <returns></returns> public List<SuggestedCategories> GetCategoryData(int id, string serchString) { var req = new GetSuggestedCategoriesRequest { SiteID = id , Keyword = serchString }; var res = new ItemService(apiUrl).GetSuggestedCategories(req); return res.Response; }
/// <summary> /// eBay Category 조회 /// </summary> /// <param name="search">조회 조건</param> /// <returns>eBayCategories 개체</returns> public eBayCategories GeteBayCategories(eBayCategorySearch search) { var req = new GetCategoriesRequest() { SiteID = search.SiteId, CategoryLevel = search.CategoryLevel, ParentCategoryID = search.ParentId }; GetCategoriesResponse res = null; try { res = new ItemService("http://gepapidev.gmarket.co.kr/api/Outbound_ItemService").GetCategories(req); } catch (ThriftClientException tce) { return new eBayCategories { Success = false, ErrorMsg = tce.Message }; } catch (ThriftException te) { return new eBayCategories { Success = false, ErrorMsg = te.ExceptionMessage }; } catch (Exception ex) { Debug.WriteLine(ex); return new eBayCategories { Success = false, ErrorMsg = "알 수 없는 오류가 발생했습니다. 오류 내용은 개발자에게 자동 전달됩니다." }; } if (res.Ack.Equals(AckType.Failure)) { //error 처리 return new eBayCategories { Success = false, ErrorMsg = "error" }; } var result = new eBayCategories { Success = true, ResultData = from q in res.Response select new eBayCategory { Id = q.Key, Name = q.Value["CategoryName"], IsLeaf = q.Value.ContainsKey("LeafCategory") && q.Value["LeafCategory"].Equals("true") } }; return result; }
public ConfigeBaySettings SettingsParseJSON(int siteId) { var req = new GetConfigDetailsRequest { SiteID = siteId }; GetConfigDetailsRequest request = new GetConfigDetailsRequest(); request.SiteID = siteId; var res = new ItemService(UrlConst.Instance.CBT_GEPAPI_URL + "/api/Outbound_ItemService").GetConfigDetails(req); string SettingsJson = Encoding.ASCII.GetString(Convert.FromBase64String(res.Response)); ConfigeBaySettings settings = new ConfigeBaySettings(); List<ConfigeBaySettingsDetail> listSettingsDetail = new List<ConfigeBaySettingsDetail>(); JSONObject jsonObject = JSONObject.CreateFromString(SettingsJson); JSONObject jsonCurrency = jsonObject.Dictionary["currency"]; JSONObject jsonDetails = jsonObject.Dictionary["details"]; settings.site = jsonObject.Dictionary["site"].String; settings.buy = jsonCurrency.Dictionary["buy"].String; settings.change_val = jsonCurrency.Dictionary["change_val"].String; settings.hname = jsonCurrency.Dictionary["hname"].String; settings.receive = jsonCurrency.Dictionary["receive"].String; settings.sell = jsonCurrency.Dictionary["sell"].String; settings.send = jsonCurrency.Dictionary["send"].String; settings.sign = jsonCurrency.Dictionary["sign"].String; settings.standard = jsonCurrency.Dictionary["standard"].String; //Controll 부분 List<JSONObject> detailObject = new List<JSONObject>(); foreach (var data in jsonDetails.Array) { ConfigeBaySettingsDetail settingsDetail = new ConfigeBaySettingsDetail(); settingsDetail.fieldName = data.Dictionary["field_name"].String; settingsDetail.fieldNameKr = data.Dictionary["field_name_kr"].String; settingsDetail.type = data.Dictionary["type"].String; settingsDetail.isrequire = data.Dictionary.Keys.Contains("isrequire") == true ? data.Dictionary["isrequire"].String : ""; settingsDetail.length = data.Dictionary.Keys.Contains("length") == true ? Util.GetSafeInt(data.Dictionary["length"].String) : 900; //Value 부분 List<ConfigeBaySettingsValues> listSettingsValues = new List<ConfigeBaySettingsValues>(); if (data.Dictionary.Keys.Contains("values") && settingsDetail.type != "CUSTOM" && settingsDetail.fieldName != "ListingDuration") { foreach (var valuesData in data.Dictionary["values"].Array) { ConfigeBaySettingsValues settingsValues = new ConfigeBaySettingsValues(); settingsValues.key = valuesData.Dictionary["key"].String; settingsValues.value = valuesData.Dictionary["value"].String; if (valuesData.Dictionary.ContainsKey("show_value")) { settingsValues.show_value = valuesData.Dictionary["show_value"].String; } listSettingsValues.Add(settingsValues); } settingsDetail.values = listSettingsValues; } // value안에 depth가 있는 특이부분 else if (data.Dictionary.Keys.Contains("values") && settingsDetail.type != "CUSTOM" && settingsDetail.fieldName == "ListingDuration") { foreach (var valuesData in data.Dictionary["values"].Dictionary) { ConfigeBaySettingsValues settingsValues = new ConfigeBaySettingsValues(); settingsValues.key = valuesData.Key; List<ConfigeBaySettingsValuesDepth1> listDepth = new List<ConfigeBaySettingsValuesDepth1>(); foreach (var valuesDataDepth1 in valuesData.Value.Array) { ConfigeBaySettingsValuesDepth1 depth1 = new ConfigeBaySettingsValuesDepth1(); depth1.key = valuesDataDepth1.Dictionary["key"].String; depth1.value = valuesDataDepth1.Dictionary["value"].String; if (valuesDataDepth1.Dictionary.ContainsKey("show_value")) { depth1.show_value = valuesDataDepth1.Dictionary["show_value"].String; } listDepth.Add(depth1); } settingsValues.settingsValuesDepth1 = listDepth; listSettingsValues.Add(settingsValues); } settingsDetail.values = listSettingsValues; } //List 국가 코드 부분 if (data.Dictionary.Keys.Contains("values") && settingsDetail.type == "CUSTOM") { foreach (var valuesData in data.Dictionary["values"].Array) { ConfigeBaySettingsValues settingsValues = new ConfigeBaySettingsValues(); settingsValues.description = valuesData.Dictionary["Description"].String; settingsValues.location = valuesData.Dictionary["Location"].String; settingsValues.region = valuesData.Dictionary["Region"].String; listSettingsValues.Add(settingsValues); } settingsDetail.values = listSettingsValues; } listSettingsDetail.Add(settingsDetail); } settings.details = listSettingsDetail; return settings; }
private Dictionary<string, object> GeteBaySuggestedCategory(int siteId, string lcategoryNm, string mcategoryNm, string scategoryNm, string srcNo, string srcName) { var req = new GetTranslateItemConvertingRequest { ServiceName = "GMKT", SiteID = siteId, InventoryID = srcNo, Title = srcName, CategoryIDList = new List<string> { lcategoryNm, mcategoryNm, scategoryNm } }; var res = new ItemService(UrlConst.Instance.CBT_GEPAPI_URL + "/api/Outbound_ItemService").GetTranslateItemConverting( new List<GetTranslateItemConvertingRequest> { req } ); Dictionary<string, object> resultDic = new Dictionary<string, object>(); foreach (var data in res.Response) { resultDic.Add("category", data.CategoryID); resultDic.Add("name", data.Title); resultDic.Add("categoryPathOriginal", data.CategoryPathOriginal == null ? "" : data.CategoryPathOriginal); } return resultDic; }