using AllBase; using AllBase.Model.Result; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Work.DouyinApiClass { public class DouyinApi { public Dictionary Data = new Dictionary(); public Dictionary JsonData = new Dictionary(); public ShopLoginInfo Shop = null; public string Type, Name; public static string Gate = "https://openapi-fxg.jinritemai.com/"; public DouyinApi(ShopLoginInfo shop) { Shop = shop; } public string GetDataDouyin() { return ""; } public string GetFreightTemplateList() { Type = "freightTemplate.list"; string html = GetData(); return html; } /// /// 获取店铺的已授权品牌列表 /// /// public string shopBrandList() { Type = "shop.brandList"; string html = GetData(); return html; } /// ///类目品牌列表 /// /// public string cateBrandList() { Type = "brand.list"; string html = GetData(); return html; } public string GetCateProperty() { Type = "product.getCateProperty"; string html = GetData(); return html; } public string GetCatePropertyV2() { Type = "product.getCatePropertyV2"; string html = GetData(); return html; } public string GetShopCategory(int cid) { Type = "shop.GetShopCategory"; JsonData.Add("cid", cid.ToString()); string html = GetData(); return html; } public string GetUploadVideo() { Type = "material.uploadVideoAsync"; string html = GetData(); return html; } public string GetProperty() { Type = "product.getCateProperty"; string html = GetData(); return html; } public string GetAdd() { Type = "product.addV2"; string html = GetData(); return html; } public string GetProductList() { Type = "product.listV2"; string html = GetData(); return html; } public string SetProductOnline() { Type = "product.setOnline"; string html = GetData(); return html; } public string SetProductOffline() { Type = "product.setOffline"; string html = GetData(); return html; } public string GetResultUpdateRule() { Type = "product.getProductUpdateRule"; string html = GetData(); return html; } public string SetProductStock() { Type = "sku.syncStock"; string html = GetData(); return html; } public string DeleteProduct() { Type = "product.del"; string html = GetData(); return html; } public string GetProductEdit() { Type = "product.editV2"; string html = GetData(); return html; } public string GetProductDetail() { Type = "product.detail"; string html = GetData(); return html; } public string GetEditStock() { Type = "sku.syncStock"; string html = GetData(); return html; } public string GetEditPrice() { Type = "sku.editPrice"; string html = GetData(); return html; } /// /// 创建图片文件夹 /// /// public string GetCreateFolder() { Type = "material.createFolder"; string html = GetData(); return html; } /// /// 查询图片文件夹 /// /// public string GetSearchFolder() { Type = "material.searchFolder"; string html = GetData(); return html; } /// /// 查询图片文件夹 /// /// public string GetSearchMaterial() { Type = "material.searchMaterial"; string html = GetData(); return html; } /// /// 上传图片 /// /// public string GetUploadImageSync() { Type = "material.uploadImageSync"; string html = GetData(); return html; } /// /// 批量上传图片 /// /// public string GetBatchUploadImageSync() { Type = "material.batchUploadImageSync"; string html = GetData(); return html; } public string MaterialDeleteFolder() { Type = "material.deleteFolder"; string html = GetData(); return html == null ? "" : html; } public string MaterialDeleteMaterial() { Type = "material.deleteMaterial"; string html = GetData(); return html == null ? "" : html; } /// /// 获取类目资质证书 /// /// public string GetQualificationConfig() { Type = "product.qualificationConfig"; string html = GetData(); return html; } /// /// 罗盘店铺信息open api /// /// public string GetStatData() { Type = "compass.GetStatData"; string html = GetData(); return html; } public string GetDataJson() { StringBuilder stringBuilder = new StringBuilder(); foreach (string current in JsonData.Keys) { stringBuilder.AppendFormat((stringBuilder.Length > 0) ? ",\"{0}\":\"{1}\"" : "\"{0}\":\"{1}\"", current, JsonData[current].ToString()); } string json = "{" + stringBuilder.ToString() + "}"; return json; } public string GetDataSignPara() { StringBuilder stringBuilderData = new StringBuilder(); foreach (string current in Data.Keys) { if (current == "access_token" || current == "sign" || current == "param_json") continue; stringBuilderData.AppendFormat((stringBuilderData.Length > 0) ? ",\"{0}\":\"{1}\"" : "\"{0}\":\"{1}\"", current, Data[current].ToString()); } string param = "{" + stringBuilderData.ToString() + "}"; return param; } public string GetDataFxgPara() { StringBuilder stringBuilderData = new StringBuilder(); foreach (string current in Data.Keys) { stringBuilderData.AppendFormat((stringBuilderData.Length > 0) ? "&{0}={1}" : "{0}={1}", current, Data[current]?.ToString()); } string param = stringBuilderData.ToString(); return param; } public string GetData() { #region 获取接口数据 string json = GetDataJson(); json = HttpUtility.UrlEncode(json, Encoding.UTF8); #endregion #region 获取sign string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Data["app_key"] = Shop.AppKey; Data["timestamp"] = timestamp; Data["method"] = Type; Data["v"] = "2"; //Data["sign"] = ""; string param = GetDataSignPara(); string url = BaseClass.BuildObjString("sign&act=signature"); string data = UserLogin.GetSignaturex() + "¶m_json=" + "" + json + "" + "¶ms=" + param; if (Shop.ShopAccount == "权益服务齐全的专营店") url = "http://new.qixiaoke.com/index.php?obj=douyin/sign&act=signature_boe"; string html = GetHtml.PostUtf8(url, data); string sign = BaseRegex.GetStringJson(ref html, "sign"); for (int i = 0; i < 5 && (string.IsNullOrEmpty(sign)); i++) { html = GetHtml.PostUtf8(url, data); sign = BaseRegex.GetStringJson(ref html, "sign"); } #endregion #region 提交抖店 Data["param_json"] = json; Data["access_token"] = Shop.AccessToken; Data["sign"] = sign; string fxgPara = GetDataFxgPara(); string urlx = "https://openapi-fxg.jinritemai.com/" + Type.Replace(".", "/"); if (Shop.ShopAccount == "权益服务齐全的专营店") urlx = "https://openapi.jinritemai.com/" + Type.Replace(".", "/"); string datax = fxgPara; string htmlx = GetHtml.PostUtf8(urlx, datax); int retryTime = 0; while (!htmlx.Contains("\"code\":10000") && retryTime < 3) { System.Threading.Thread.Sleep(500); if (htmlx.Contains("非法的参数")) htmlx = GetHtml.PostUtf8(urlx, datax); retryTime++; } return htmlx; #endregion } public string AddFreightTemplateListByBuyApi() { Type = "freightTemplate.create"; string html = GetBuyApiData(); return html; } public string GetFreightTemplateListByBuyApi() { Type = "freightTemplate.list"; string html = GetBuyApiData(); return html; } public string GetDouyinAddressAreaByBuyApi(string province_id) { if (string.IsNullOrEmpty(province_id) || province_id == "0") Type = "address.getProvince"; else Type = "address.getAreasByProvince"; JsonData["province_id"] = province_id; string html = GetBuyApiData(); return html; } public string GetBuyApiData() { #region 获取接口数据 string json = GetHtml.UrlEncodeUtf8(GetDataJson()); // string timestamp = BaseClass.DateTimeToTimestampSeconds(DateTime.Now).ToString(); //json = HttpUtility.UrlEncode(json, Encoding.UTF8); #endregion #region 获取sign string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); Data["app_key"] = "7016502755254683171"; //Shop.AppKey; Data["timestamp"] = timestamp; Data["method"] = Type; Data["v"] = "2"; string param = GetHtml.UrlEncodeUtf8(GetDataSignPara()); string url = "http://103.90.155.35:54" + (new Random().Next(10, 20)) + "/sign.php?act=signature"; //string url = BaseClass.DouYinBuildObjString("sign&act=signature"); string data = UserLogin.GetSignaturex() + "¶m_json=" + json + "" + "¶ms=" + param + "&service=2"; string html = GetHtml.PostUtf8(url, data); string sign = BaseRegex.GetStringJson(ref html, "sign"); // "c4df970da7f412d4dc7f5f9e0ee1b0e8" #endregion #region 提交抖店 Data["param_json"] = json; Data["access_token"] = Shop.BuyApiAuth.AccessToken; Data["sign"] = sign; string fxgPara = GetDataFxgPara(); string urlx = "https://openapi-fxg.jinritemai.com/" + Type.Replace(".", "/") + "?app_key=7016502755254683171×tamp=" + timestamp + "&method=" + Type + "&v=2¶m_json=" + json + "&access_token=" + Shop.BuyApiAuth.AccessToken + "&sign=" + sign; string datax = fxgPara; string htmlx = GetHtml.PostUtf8(urlx, datax); return htmlx; #endregion } } }