using KJD_Web.Model;
using KJD_Web.Utils;
using KJD_WebService.Model;
using KJD_WebService.Model.WxModel;
using NaiBa.Util.Extension;
using NaiBa.Util.Helper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace KJD_Web.Upload.Prod
{
public class BaseClass
{
public static string BuildPDDObjString(string file, bool IsLoginDef = false)
{
string LoginApiUrl = "http://1.13.195.131:9001";
string MainPath = "kuajingda";
return LoginApiUrl + "/bxx_" + file + "?obj=" + MainPath + "/bxx_" + file;
}
public static int TimeDifferent = 0;
public static int VersionCount = 99999999;
public static int CompanyId = 1;
public static string CompanyName = "1";
public static string UserKey = "1";
public static string Mobile = "18888888888";
public static string UserName = "18888888888";
public static string ShopId = "18888888888";
public static string ShopName = "18888888888";
}
public class UserLogin
{
///
/// 获取签名字符串,新版
///
///
public static string GetSignaturex()
{
return GetSignaturex(BaseClass.ShopId, BaseClass.ShopName);
}
public static string GetSignaturex(string shopId, string shopName)
{
if (string.IsNullOrEmpty(shopId))
shopId = "11111111";
if (string.IsNullOrEmpty(shopName))
shopName = "wx11111111";
int time = TimeUtils.DateTimeToTimestampSeconds(DateTime.Now) + BaseClass.TimeDifferent;
string time1 = EncrypUtil.Encryption(time);
return "time=" + time + "&code=" + time1 + "&NbCodeVersion=1" + "&version=" + BaseClass.VersionCount +
"&company_id=" + BaseClass.CompanyId + "&company=" + HtmlUtils.UrlEncodeUtf8(BaseClass.CompanyName) +
"&user_name=" + BaseClass.UserName + "&user_key=" + BaseClass.UserKey + "&mobile=" + BaseClass.Mobile +
"&sid=" + shopId + "&shop=" + HtmlUtils.UrlEncodeUtf8(shopName);
}
}
public partial class WXProd : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FileUpload1.Visible = false;
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
Label1.Text = "";
Label2.Text = "";
string rst = getProd();
Label1.Text = rst;
Label2.Text = rst;
TextBox2.Text = "";
FileUpload1.Visible = false;
}
string getProd()
{
string prodStr = Encoding.UTF8.GetString(this.FileUpload1.FileBytes);
prodStr = TextBox2.Text.Trim();
WXClientProductInfoLite wxClientProd = new WXClientProductInfoLite();
var str_lst = RegexUtils.GetJsonObjStrJson(ref prodStr, "product_key");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.product_key = JsonUtils.DeserializeJsonToObject(regex_str);
if (wxClientProd.product_key == null)
return "解析失败";
}
catch
{
return "解析失败";
}
//商品详情格式
wxClientProd.info = new wx_client_prod_info();
//主标题
wxClientProd.info.title = RegexUtils.GetStringJson(ref prodStr, "title");
if (wxClientProd.info.title.IsNullOrEmpty())
return "解析失败";
//副标题
wxClientProd.info.sub_title = RegexUtils.GetStringJson(ref prodStr, "sub_title");
str_lst = RegexUtils.GetJsonArrStrJson(ref prodStr, "head_img");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.head_img = JsonUtils.DeserializeJsonToListNullable(regex_str);
if (wxClientProd.info.head_img == null)
return "解析失败";
}
catch
{
return "解析失败";
}
var nodeCatId = RegexUtils.GetStringJson(ref prodStr, "nodeCatId");
str_lst = RegexUtils.GetJsonArrStrJson(ref prodStr, "category");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.category = JsonUtils.DeserializeJsonToListNullable(regex_str);
if (wxClientProd.info.category != null && !str_lst.IsNullOrEmpty() && !wxClientProd.info.category.Any(c => c.catIdStr == nodeCatId))
{
wxClientProd.info.category.Add(new wx_client_category() { catId = nodeCatId, cat_id = nodeCatId });
}
//if (wxClientProd.info.category == null)
// return "解析失败";
}
catch
{
return "解析失败";
}
str_lst = RegexUtils.GetJsonObjStrJson(ref prodStr, "detail");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.detail = JsonUtils.DeserializeJsonToObjectNullable(regex_str);
if (wxClientProd.info.detail == null)
{
wxClientProd.info.detail = new wx_client_prod_detail();
wxClientProd.info.detail.detail_img.Add(wxClientProd.info.head_img.FirstOrDefault());
}
//if (wxClientProd.info.detail == null)
// return "解析失败";
}
catch
{
return "解析失败";
}
str_lst = RegexUtils.GetJsonArrStrJson(ref prodStr, "param");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.param = JsonUtils.DeserializeJsonToListNullable(regex_str);
if (wxClientProd.info.param == null)
wxClientProd.info.param = new List();
//if (wxClientProd.info.param == null)
// return "解析失败";
}
catch
{
return "解析失败";
}
//品牌id
wxClientProd.info.brand_id = RegexUtils.GetStringJson(ref prodStr, "brand_id");
//if (wxClientProd.info.brand_id.IsNullOrEmpty())
// return "解析失败";
str_lst = RegexUtils.GetJsonObjStrJson(ref prodStr, "sku_id_list");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.sku_id_list = JsonUtils.DeserializeJsonToObjectNullable(regex_str);
//if (wxClientProd.info.sku_id_list == null)
// return "解析失败";
}
catch
{
return "";
}
str_lst = RegexUtils.GetJsonObjStrJson(ref prodStr, "sku_list");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.sku_list = JsonUtils.DeserializeJsonToObjectNullable(regex_str);
//if (wxClientProd.info.sku_list == null)
// return "解析失败";
}
catch
{
return "解析失败";
}
if (wxClientProd.info.sku_list == null)
{
str_lst = RegexUtils.GetJsonArrStrJson(ref prodStr, "sku_info");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
var sku_infos = JsonUtils.DeserializeJsonToListNullable(regex_str);
if (sku_infos != null)
{
wxClientProd.info.sku_list = new wx_sku();
wxClientProd.info.sku_list.sku_info = sku_infos;
}
}
catch
{
return "解析失败";
}
}
str_lst = RegexUtils.GetJsonArrStrJson(ref prodStr, "product_sale_attrs");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.product_sale_attrs = JsonUtils.DeserializeJsonToListNullable(regex_str);
//if (wxClientProd.info.product_sale_attrs == null)
// return "解析失败";
}
catch
{
return "解析失败";
}
//总销量
wxClientProd.info.total_sold_num = RegexUtils.GetStringJson(ref prodStr, "total_sold_num");
//if (wxClientProd.info.total_sold_num.IsNullOrEmpty())
// return "解析失败";
str_lst = RegexUtils.GetJsonObjStrJson(ref prodStr, "service_desc");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.service_desc = JsonUtils.DeserializeJsonToObjectNullable(regex_str);
//if (wxClientProd.info.service_desc == null)
// return "解析失败";
}
catch
{
return "解析失败";
}
str_lst = RegexUtils.GetJsonObjStrJson(ref prodStr, "express_info");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.express_info = JsonUtils.DeserializeJsonToObjectNullable(regex_str);
//if (wxClientProd.info.express_info == null)
// return;
}
catch
{
return "解析失败";
}
str_lst = RegexUtils.GetJsonArrStrJson(ref prodStr, "headVideoInfo");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.headVideoInfo = JsonUtils.DeserializeJsonToListNullable(regex_str);
//if (wxClientProd.info.headVideoInfo == null)
// return "解析失败";
}
catch
{
return "解析失败";
}
str_lst = RegexUtils.GetJsonObjStrJson(ref prodStr, "afterSaleInfo");
try
{
var regex_str = str_lst.OrderByDescending(s => s.Length).FirstOrDefault();
wxClientProd.info.afterSaleInfo = JsonUtils.DeserializeJsonToObjectNullable