@ -22,24 +22,24 @@ namespace 齐越慧眼
static string jwtToken ;
public static string JwtToken {
public static string JwtToken {
get
{
#if DEBUG
return "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiIxNDM5OTA3NDY1MDMzNDIwODAwIiwidGVhbUlkIjoiMTQzNjI4ODUwMDIzNTI0MzUyMCIsImV4cCI6MTY3MTAwOTkyM30.p3yLjbeUilDZxkfRv4GaCvIYJ_jFoe_8Sw8hY18swdA" ;
#endif
if ( string . IsNullOrEmpty ( jwtToken ) )
{
jwtToken = GetMemoryToken ( ) . Replace ( "\r\n" , "" ) ;
jwtToken = GetMemoryToken ( ) . Replace ( "\r\n" , "" ) ;
}
return jwtToken ;
}
}
static int getTokentCount = 0 ;
@ -141,9 +141,9 @@ namespace 齐越慧眼
bool isSuccess = data . Success ;
if ( isSuccess )
{
string json = data . Data . ToString ( ) ;
UserInfo u = Newtonsoft . Json . JsonConvert . DeserializeObject < UserInfo > ( json ) ;
{
string json = data . Data . ToString ( ) ;
UserInfo u = Newtonsoft . Json . JsonConvert . DeserializeObject < UserInfo > ( json ) ;
return ( true , u ) ;
}
@ -155,9 +155,9 @@ namespace 齐越慧眼
/// </summary>
/// <param name="model"></param>
/// <returns></returns>
public static ( bool isOk , bool isCanel , string msg ) SetItemLabel ( ItemLabelDto model )
public static ( bool isOk , bool isCanel , string msg ) SetItemLabel ( ItemLabelDto model )
{
var result = Http ( "/HuiYan/itemlabels/SetItemLabel" , Newtonsoft . Json . JsonConvert . SerializeObject ( model ) ) ;
var result = Http ( "/HuiYan/itemlabels/SetItemLabel" , Newtonsoft . Json . JsonConvert . SerializeObject ( model ) ) ;
var data = Newtonsoft . Json . JsonConvert . DeserializeObject < dynamic > ( result ) ;
@ -171,7 +171,7 @@ namespace 齐越慧眼
/// </summary>
/// <param name="shopId"></param>
/// <returns></returns>
public static ( bool isOk , bool isCanel , string msg ) SetAlbbCooperation ( string shopId )
public static ( bool isOk , bool isCanel , string msg ) SetAlbbCooperation ( string shopId )
{
var result = Http ( $"/HuiYan/itemlabels/SetAlbbCooperation?shopId={shopId}" , "" ) ;
@ -218,7 +218,7 @@ namespace 齐越慧眼
/// <param name="ids"></param>
/// <param name="platform"></param>
/// <returns></returns>
public static ( bool isOk , List < ItemlabelInfoDto > datas ) GetLabelByItemIds ( List < string > ids , ItemPlatform platform )
public static ( bool isOk , List < ItemlabelInfoDto > datas ) GetLabelByItemIds ( List < string > ids , ItemPlatform platform )
{
try
{
@ -234,7 +234,7 @@ namespace 齐越慧眼
return ( isSuccess , datas ? ? new List < ItemlabelInfoDto > ( ) ) ;
}
catch
catch
{
return ( false , new List < ItemlabelInfoDto > ( ) ) ;
}
@ -257,11 +257,11 @@ namespace 齐越慧眼
bool isSuccess = data . Success ;
return ( isSuccess , data . Msg ? ? "操作失败" ) ;
return ( isSuccess , data . Msg ? ? "操作失败" ) ;
}
catch
{
return ( false , "系统异常" ) ;
return ( false , "系统异常" ) ;
}
}
@ -286,7 +286,7 @@ namespace 齐越慧眼
HttpClient http = new HttpClient ( ) ;
http . Timeout = new TimeSpan ( 0 , 0 , 3 5 ) ;
http . DefaultRequestHeaders . Add ( "Authorization" , "Bearer " + JwtToken ) ;
if ( postData ! = null )
if ( postData ! = null )
{
StringContent content = new StringContent ( postData ) ;
content . Headers . ContentType = new System . Net . Http . Headers . MediaTypeHeaderValue ( "application/json" ) ;
@ -330,5 +330,111 @@ namespace 齐越慧眼
return null ;
}
}
/// <summary>
/// 根据Sku获取详情
/// </summary>
/// <param name="skuId"></param>
/// <returns></returns>
public static ( int status , dynamic result ) GetItemDetail ( string skuId )
{
try
{
HttpClient http = new HttpClient ( ) ;
http . DefaultRequestHeaders . Add ( "Cookie" , App . JdCookie ) ;
http . DefaultRequestHeaders . Add ( "User-Agent" , "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 SE 2.X MetaSr 1.0" ) ;
string html = http . GetStringAsync ( $"https://item.jd.com/{skuId}.html" ) . Result ;
if ( html . Contains ( "passport.jd.com/new/login.aspx" ) | | html . Contains ( "//item.jd.com/html/token.html?returnUrl=" ) )
{
return ( 2 , null ) ;
}
int start = html . IndexOf ( "var pageConfig" ) ;
int end = html . IndexOf ( "};" , start ) ;
string json = html . Substring ( start , end - start ) ;
start = json . IndexOf ( "{" ) ;
json = json . Substring ( start , json . Length - start ) ;
json + = "}" ;
var data = Newtonsoft . Json . JsonConvert . DeserializeObject < dynamic > ( json ) ;
return ( 0 , data ) ;
}
catch ( Exception ex )
{
return ( 1 , ex . Message ) ;
}
}
/// <summary>
/// 获取价格
/// </summary>
/// <param name="skuId"></param>
/// <returns></returns>
public static ( string price , string commont ) GetItemPrice ( string skuId )
{
try
{
HttpClient http = new HttpClient ( ) ;
http . DefaultRequestHeaders . Add ( "Cookie" , App . JdCookie ) ;
http . DefaultRequestHeaders . Add ( "User-Agent" , "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 SE 2.X MetaSr 1.0" ) ;
string html = http . GetStringAsync ( $"https://item-soa.jd.com/getWareBusiness?skuId={skuId}" ) . Result ;
if ( ! string . IsNullOrEmpty ( html ) )
{
var data = Newtonsoft . Json . JsonConvert . DeserializeObject < dynamic > ( html ) ;
string price = data . price . p . ToString ( ) ;
string commont = GetItemCommentCount ( skuId ) ;
return ( price , commont ) ;
}
}
catch ( Exception ex )
{
return ( string . Empty , string . Empty ) ;
}
return ( string . Empty , string . Empty ) ;
}
public static string GetItemCommentCount ( string skuId )
{
try
{
HttpClient http = new HttpClient ( ) ;
http . DefaultRequestHeaders . Add ( "Cookie" , App . JdCookie ) ;
http . DefaultRequestHeaders . Add ( "User-Agent" , "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36 SE 2.X MetaSr 1.0" ) ;
string html = http . GetStringAsync ( $"https://club.jd.com/comment/productCommentSummaries.action?referenceIds={skuId}" ) . Result ;
if ( ! string . IsNullOrEmpty ( html ) )
{
var data = Newtonsoft . Json . JsonConvert . DeserializeObject < dynamic > ( html ) ;
string count = data . CommentsCount [ 0 ] . CommentCountStr . ToString ( ) ;
return count ;
}
}
catch ( Exception ex )
{
return "" ;
}
return "" ;
}
}
}