181 lines
6.8 KiB
C#
181 lines
6.8 KiB
C#
/*
|
|
* 纯API设置进宝
|
|
* 肖俊
|
|
* 2019-7-31
|
|
*/
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.IO.Compression;
|
|
using System.Linq;
|
|
using System.Management.Instrumentation;
|
|
using System.Net;
|
|
using System.Runtime.CompilerServices;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using AllBase;
|
|
//using JavaScriptEngineSwitcher.Core;
|
|
//using JavaScriptEngineSwitcher.V8;
|
|
using Work.Api;
|
|
using Work.CollectClass;
|
|
|
|
namespace Work.ManageClass
|
|
{
|
|
public class CpsShopNew
|
|
{
|
|
public static string Name;
|
|
public static List<ShopChatBase> ShopTemp = new List<ShopChatBase>();
|
|
public static int ThreadCount = 3;
|
|
public static bool IsUseProxy = false;
|
|
public static bool IsdayProduct = false;
|
|
public static int dayProduct = 0;
|
|
/// <summary>
|
|
/// 是否正在模拟请求并休眠,如果是,将在SleepSim方法中继续休眠,拉开模拟请求间隔
|
|
/// </summary>
|
|
private static bool isSleepSim = false;
|
|
|
|
|
|
public static bool ByCouponPercent = false;
|
|
public static int ShopPerCent = 0, ShopPercentAll = 0,
|
|
CouponAllCount = 0,
|
|
CouponCount = 0,
|
|
ConponDays = 0,
|
|
SalsPrice1 = 0,
|
|
SalsPrice11 = 0,
|
|
CouponPrice1 = 0,
|
|
SalsPrice2 = 0,
|
|
SalsPrice22 = 0,
|
|
CouponPrice2 = 0,
|
|
SalsPrice3 = 0,
|
|
SalsPrice33 = 0,
|
|
CouponPrice3 = 0, CouponPercent = 0;
|
|
}
|
|
|
|
public class CpsSetAllGoods
|
|
{
|
|
public static int discount;
|
|
public static int day;
|
|
public static int initQuantity;
|
|
public static int userLimit;
|
|
public static int Amount;
|
|
public static string adslName;
|
|
public static string adslPassWord;
|
|
public static bool adslflag = false;
|
|
public static List<CpsPriceRangeCoup> cpsPriceRangeCoupList = new List<CpsPriceRangeCoup>();
|
|
public static bool isStop = false;
|
|
|
|
private AdslHelper adsl = null;
|
|
private DateTime lasttime = DateTime.MinValue;
|
|
|
|
public static string getAnti0aon()
|
|
{
|
|
string anti = "";
|
|
//using (IJsEngine jsEngine = new V8JsEngine())
|
|
//{
|
|
// jsEngine.Execute(GetProductOnlineClass.PinDuoDUo_0ao);
|
|
// anti = jsEngine.CallFunction("get_anti", "").ToString();
|
|
// try
|
|
// { anti = "0ao" + anti.Substring(3); }
|
|
// catch { }
|
|
//}
|
|
return anti;
|
|
}
|
|
|
|
public static string Request_mms_pinduoduo_com(string url, string referer, string cookie, string data, string antiContent, IWebProxy proxy = null)
|
|
{
|
|
string responseText = "";
|
|
HttpWebResponse response = null;
|
|
|
|
try
|
|
{
|
|
//HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://mms.pinduoduo.com/cps/api/coupon/createCommonCoupon");
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
|
|
|
|
request.KeepAlive = true;
|
|
request.Accept = "application/json";
|
|
//request.Headers.Add("Anti-Content", @"0aoAfxnUgOQoU9dVEHIuLKYezEfQ51QpOcKVg_S0aww9S8dseM_tTxYptgFssmH7wfRCpRvfISyXp-bZ8hcq7ux0Z1kvhFUkfIMk7EsEefUAZS7Jv1vYHm1Cplb4GZ43dSFtKu19dO7snIyL-VRj0JFy0ETKDkf1EdaPbWEu22sZ4s1duGD6WO9lgeS-oTsEwwa9ohcX2E_DG2PggPHqIuxcN_tIthAewaqklSPvPmFwzYxrlo256wd2i74SMvTzGTB--UkZ3gPl5t6K-6IVCz1MDD7WDS9HeoGm4RBmyd0LIpXG400lOfKBvPh-z09PL3_hjiL1KiBCENrs1ANosN35LJ8zhlCRi0YrDxphd8LGJFWDG0LrARGRuMW7d3d4IlWlEKFFMiucGGNlIZqDyExDIMny-8T-KY8fJ8BnNuzWyr");
|
|
request.Headers.Add("Anti-Content", antiContent);
|
|
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36";
|
|
request.UserAgent = BaseClass.ChromeUserAgent;
|
|
request.ContentType = "application/json;charset=UTF-8";
|
|
request.Headers.Add("Origin", @"https://mms.pinduoduo.com");
|
|
request.Headers.Add("Sec-Fetch-Site", @"same-origin");
|
|
request.Headers.Add("Sec-Fetch-Mode", @"cors");
|
|
request.Headers.Add("Sec-Fetch-Dest", @"empty");
|
|
request.Referer = referer;
|
|
request.Headers.Set(HttpRequestHeader.AcceptEncoding, "gzip, deflate, br");
|
|
request.Headers.Set(HttpRequestHeader.AcceptLanguage, "zh-CN,zh;q=0.9");
|
|
request.Headers.Set(HttpRequestHeader.Cookie, cookie);
|
|
if (proxy != null)
|
|
request.Proxy = proxy;
|
|
|
|
request.Method = "POST";
|
|
request.ServicePoint.Expect100Continue = false;
|
|
|
|
string body = data;
|
|
byte[] postBytes = System.Text.Encoding.UTF8.GetBytes(body);
|
|
request.ContentLength = postBytes.Length;
|
|
Stream stream = request.GetRequestStream();
|
|
stream.Write(postBytes, 0, postBytes.Length);
|
|
stream.Close();
|
|
|
|
response = (HttpWebResponse)request.GetResponse();
|
|
}
|
|
catch (WebException e)
|
|
{
|
|
if (e.Status == WebExceptionStatus.ProtocolError) response = (HttpWebResponse)e.Response;
|
|
else responseText = "error," + e.Message;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
responseText = "error," + ex.Message;
|
|
}
|
|
if (response != null)
|
|
{
|
|
if (string.IsNullOrEmpty(responseText))
|
|
responseText = ReadResponse(response);
|
|
response.Close();
|
|
}
|
|
|
|
Thread.Sleep(50 + Randomx.GetId(100));
|
|
|
|
return responseText;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 读取返回值
|
|
/// </summary>
|
|
/// <param name="response"></param>
|
|
/// <returns></returns>
|
|
public static string ReadResponse(HttpWebResponse response)
|
|
{
|
|
using (Stream responseStream = response.GetResponseStream())
|
|
{
|
|
Stream streamToRead = responseStream;
|
|
if (response.ContentEncoding.ToLower().Contains("gzip"))
|
|
{
|
|
streamToRead = new GZipStream(streamToRead, CompressionMode.Decompress);
|
|
}
|
|
else if (response.ContentEncoding.ToLower().Contains("deflate"))
|
|
{
|
|
streamToRead = new DeflateStream(streamToRead, CompressionMode.Decompress);
|
|
}
|
|
|
|
using (StreamReader streamReader = new StreamReader(streamToRead, Encoding.UTF8))
|
|
{
|
|
return streamReader.ReadToEnd();
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
public class CpsPriceRangeCoup
|
|
{
|
|
public int MinPrice = 0;
|
|
public int MaxPrice = 0;
|
|
public int CoupPrice = 0;
|
|
}
|
|
}
|