old_flsystem/应用/CouponsSend/QuanInfo.cs

180 lines
6.6 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using Api.Framework;
using Api.Framework.Cps;
using Api.Framework.Tools;
using CsharpHttpHelper;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
namespace CouponsSend
{
public class QuanInfo
{
public string imgUrl { get; set; }
public string duanTitle { get; set; }
public string wenan { get; set; }
public string quanUrl { get; set; }
public string itemUrl { get; set; }
public string itemId { get; set; }
public string activityId { get; set; }
public string sellerId { get; set; }
public QuanInfo(string imageUrl, string duanTitle, string wenan, string quanUrl, string itemUrl)
{
//http://shop.m.taobao.com/shop/coupon.htm?activityId=b3980dab2c9d457ab85d2bd30c756690&sellerId=208479060
if (!string.IsNullOrEmpty(imageUrl))
{
var pic = "http://qun.qq.com/cgi/svr/chatimg/get?pic=" + imageUrl.Replace("{", "").Replace("}", "").Replace("-", "");
//var pic = "http://gchat.qpic.cn/gchatpic_new/{0}/{1}-2697951893-{2}/0?term=2&cldver=8.4.5.4745&rf=naio&msgTime={3}&mType=picGd";
var url = GetLocation(pic);
if (!string.IsNullOrWhiteSpace(url))
url = url.Replace(@"/gchatpic/", @"/gchatpic_new/");
else
url = pic;
this.imgUrl = url;
}
this.duanTitle = this.duanTitle;
this.wenan = wenan;
this.quanUrl = quanUrl;
this.itemUrl = itemUrl;
}
public bool CheckOk(AlimamaApi api, string[] pids)
{
var tbAnalysis = new TBHelper.TbAnalysis();
var item_id = string.Empty;
try
{
item_id = tbAnalysis.FindItemIdByUrlAndTklAndMkl(itemUrl, api, pids);
}
catch (Exception)
{
return false;
}
if (string.IsNullOrWhiteSpace(item_id)) return false;
this.itemId = item_id;
return true;
}
/// <summary>
/// 搜索商品
/// </summary>
//public ItemInfo SerchItem(AlimamaApi api, string q, string adzone_id = "", string site_id = "")
//{
// try
// {
// var reg = Regex.Match(q, @"id=(\d+)");
// Dictionary<string, object> dic = null;
// if (!reg.Success)
// {
// dic = api.SendTaobao("taobao.tbk.sc.material.optional", new { adzone_id = adzone_id, site_id = site_id, q = q });
// if (dic.ContainsKey("result_list"))
// {
// var result_list = dic["result_list"] as Dictionary<string, object>;
// if (result_list != null && result_list.ContainsKey("map_data"))
// {
// var map_data = (result_list["map_data"]) as ArrayList;
// if (map_data != null && map_data.Count != 0)
// dic = map_data[0] as Dictionary<string, object>;
// }
// }
// }
// else
// {
// dic = api.SendTaobao("taobao.tbk.item.info.get", new { num_iids = reg.Groups[1].Value });
// var n_tbk_item = (dic["n_tbk_item"]) as ArrayList;
// if (n_tbk_item != null && n_tbk_item.Count != 0)
// dic = n_tbk_item[0] as Dictionary<string, object>;
// }
// ItemInfo info = new ItemInfo()
// {
// item_id = dic["num_iid"].ToString(),
// item_url = dic["item_url"].ToString(),
// pict_url = dic["pict_url"].ToString(),
// seller_id = dic["seller_id"].ToString(),
// quan_price = 0,
// reserve_price = double.Parse(dic["reserve_price"].ToString()),
// zk_final_price = double.Parse(dic["zk_final_price"].ToString()),
// title = dic["title"].ToString()
// };
// return info;
// }
// catch (Exception ex)
// {
// if (!ex.Message.Contains("无结果") && !ex.Message.Contains("已过期"))
// EventClient.OnEvent(this, $"SerchItem{ex.Message}");
// }
// return null;
//}
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
private string GetLocation(string url)
{
try
{
HttpHelper http = new HttpHelper();
HttpItem item = new HttpItem()
{
URL = url,
Method = "get",
IsToLower = false,
Cookie = "",
Referer = "",
Postdata = "",
Timeout = 5000,
ReadWriteTimeout = 15000,
UserAgent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.154 Safari/537.36 LBBROWSER",
ContentType = "application/x-www-form-urlencoded",
Allowautoredirect = false,
ProxyIp = ""
};
HttpResult result = http.GetHtml(item);
return result.Header.Get("Location");
}
catch (Exception ex)
{
//EventClient.OnEvent(this, $"Location:{url},{ex.Message},{ex.StackTrace}");
}
return string.Empty;
}
}
public class ItemInfo
{
public string item_url { get; set; }
public string pict_url { get; set; }
public string item_id { get; set; }
public string seller_id { get; set; }
public double reserve_price { get; set; }
public string title { get; set; }
public double zk_final_price { get; set; }
public double quan_price { get; set; }
private double _max_commission_rate;
public double max_commission_rate
{
get { return _max_commission_rate; }
set
{
tkCommFee = Math.Round((zk_final_price - quan_price) * (value / 100.00), 2);
_max_commission_rate = value;
}
}
public double tkCommFee { get; set; }
}
}