using AllBase; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Work.Api; namespace Work.ManageClass { public class AutoQuestion { public string Name; public ShopChatBase Shop; public static int ShopThreadCount = 50; public int rowindex = 0; public int colindex = 0; public static List ShopQuestionList = new List(); public static List pairList = new List(); public AutoQuestion(string name) { Name = name; } public void SetQuestion() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectQue) continue; var p = new AutoQuestionControl(Name, shop); p.rowindex = rowindex; p.colindex = colindex; Threadx.ThreadListWait(ref ts, new Thread(p.SetQuestion), ShopThreadCount); Thread.Sleep(3000); } Threadx.ThreadListWait(ref ts); } public void QueryQuestion() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectQue) continue; var p = new AutoQuestionControl(Name, shop); Threadx.ThreadListWait(ref ts, new Thread(p.QueryQuestion), ShopThreadCount); Thread.Sleep(3000); } Threadx.ThreadListWait(ref ts); } public void SetAllQuestion() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectQue) continue; var p = new AutoQuestionControl(Name, shop); p.rowindex = rowindex; p.colindex = colindex; Threadx.ThreadListWait(ref ts, new Thread(p.SetAllQuestion), ShopThreadCount); Thread.Sleep(3000); } Threadx.ThreadListWait(ref ts); } public void SetAllEquity() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectQue) continue; var p = new AutoQuestionControl(Name, shop); p.rowindex = rowindex; p.colindex = colindex; Threadx.ThreadListWait(ref ts, new Thread(p.SetAllEquity), ShopThreadCount); Thread.Sleep(3000); } Threadx.ThreadListWait(ref ts); } public void SetSingleEquity() { List ts = new List(); for (int i = 0; i < GetShopLoginInfo.Shops.Count; i++) { var shop = GetShopLoginInfo.Shops[i]; if (!shop.SelectQue) continue; var p = new AutoQuestionControl(Name, shop); p.rowindex = rowindex; Threadx.ThreadListWait(ref ts, new Thread(p.SetSingleEquity), ShopThreadCount); Thread.Sleep(3000); } Threadx.ThreadListWait(ref ts); } } public class AutoQuestionControl { public string Name; public ShopChatBase Shop; public int rowindex = 0; public int colindex = 0; public List satusList = new List(); public AutoQuestionControl(string name, ShopChatBase shop) { Name = name; Shop = shop; } public void QueryQuestion() { QueryQuestion(0); } public void QueryQuestion(int type=0) { AutoQuestion.pairList.Clear(); satusList.Clear(); string url = "https://mms.pinduoduo.com/rivendell/api/qualification/getQualificationList"; string refere = "https://mms.pinduoduo.com/mallcenter/ability/index"; string data = "{}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies); var m = BaseRegex.GetMatchRegex(ref html, @"{""questionnaireId"":[^}]+?}"); for (int j = 0; m != null && j < m.Count; j++) { string item = m[j].Groups[0].Value; int questionnaireId = BaseRegex.GetIntJson(ref item, "questionnaireId"); int finished = BaseRegex.GetIntJson(ref item, "finished"); QuestionKeyValue qk = new QuestionKeyValue(); qk.key = questionnaireId; qk.value = finished; satusList.Add(qk); } ShopQuestion sq = new ShopQuestion(); sq.Shop = Shop; sq.satusList = satusList; AutoQuestion.ShopQuestionList.Add(sq); m = BaseRegex.GetMatchRegex(ref html, @"""qualificationBenefit"":\s*\[\{[^}]+?\}"); for (int j = 0; m != null && j < m.Count; j++) { string item = m[j].Groups[0].Value; int finished = BaseRegex.GetIntJson(ref item, "benefitStatus"); QuestionKeyValue qk = new QuestionKeyValue(); qk.key = j + 1; qk.value = finished; AutoQuestion.pairList.Add(qk); } if (type == 0) LogSave.Add(Name, Shop.ShopName + "查询店铺答题状况完成。"); else { var p = AutoQuestion.pairList.Find(s => s.value == 0); if (p != null) { ShopQuestion sqx = new ShopQuestion(); sqx.Shop = Shop; sqx.status = "领取权益部分失败"; AutoQuestion.ShopQuestionList.Add(sqx); LogSave.Add(Name, Shop.ShopName + "领取权益部分失败。"); } else { ShopQuestion sqx = new ShopQuestion(); sqx.Shop = Shop; sqx.status = "领取权益完成"; AutoQuestion.ShopQuestionList.Add(sqx); LogSave.Add(Name, Shop.ShopName + "领取权益完成。"); } } } public void SetQuestion() { if (rowindex == 0 || colindex == 0) return; string cookies = Shop.Cookies; string url = "https://mms.pinduoduo.com/rivendell/api/qualification/getQualificationList"; string refere = "https://mms.pinduoduo.com/mallcenter/ability/index"; string data = "{}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); var m = BaseRegex.GetMatchRegex(ref html, @"{""questionnaireId"":[^}]+?}"); for (int j = 0; m != null && j < m.Count; j++) { string item = m[j].Groups[0].Value; int questionnaireId = BaseRegex.GetIntJson(ref item, "questionnaireId"); int finished = BaseRegex.GetIntJson(ref item, "finished"); if (questionnaireId == colindex && finished == 1) { string result = RetResult(colindex, "已通过,考试无需再考"); ShopQuestion sq = new ShopQuestion(); sq.Shop = Shop; sq.status = "已通过,考试无需再考"; AutoQuestion.ShopQuestionList.Add(sq); LogSave.Add(Name, result); return; } else { break; } } Thread.Sleep(1000); url = "https://mms.pinduoduo.com/rivendell/api/questionnaire/getQuestionnaireDetail"; refere = "https://mms.pinduoduo.com/mallcenter/ability/exam/"+ colindex; data = "{\"questionnaireId\":"+colindex+"}"; html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); Thread.Sleep(1000); url = "https://mms.pinduoduo.com/rivendell/api/qualification/detail"; refere = "https://mms.pinduoduo.com/mallcenter/ability/exam/"+ colindex; data = "{\"qualificationId\":"+rowindex+"}"; html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); Thread.Sleep(200); url = "https://mms.pinduoduo.com/rivendell/api/questionnaire/updateReadRecord"; refere = "https://mms.pinduoduo.com/mallcenter/ability/exam/"+ colindex; data = "{\"questionnaireId\":"+ colindex + "}"; html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); if (html.Contains("\"success\":true")) { ShopQuestion sq = new ShopQuestion(); sq.Shop = Shop; sq.status = "已通过"; AutoQuestion.ShopQuestionList.Add(sq); LogSave.Add(Name, RetResult(colindex)); } } public void SetAllQuestion() { satusList.Clear(); string urlx = "https://mms.pinduoduo.com/rivendell/api/qualification/getQualificationList"; string referex = "https://mms.pinduoduo.com/mallcenter/ability/index"; string datax = "{}"; string htmlx = GetPostTaobaoHtml.UploadTaobaoPost(urlx, referex, true, datax, Shop.Cookies); var m = BaseRegex.GetMatchRegex(ref htmlx, @"{""questionnaireId"":[^}]+?}"); for (int j = 0; m != null && j < m.Count; j++) { string item = m[j].Groups[0].Value; int questionnaireId = BaseRegex.GetIntJson(ref item, "questionnaireId"); int finished = BaseRegex.GetIntJson(ref item, "finished"); QuestionKeyValue qk = new QuestionKeyValue(); qk.key = questionnaireId; qk.value = finished; satusList.Add(qk); } string cookies = Shop.Cookies; for (int i =1; i < 5; i++) { for (int j = 1; j < 5; j++) { rowindex = i; colindex = j + 4 * (i - 1); var staval = satusList.Find(sa => sa.key == colindex); if (staval.value==1) { string result = RetResult(colindex, "已通过,考试无需再考"); ShopQuestion sq = new ShopQuestion(); sq.Shop = Shop; sq.status = result; AutoQuestion.ShopQuestionList.Add(sq); LogSave.Add(Name, RetResult(colindex)); continue; } string url = "https://mms.pinduoduo.com/rivendell/api/questionnaire/getQuestionnaireDetail"; string refere = "https://mms.pinduoduo.com/mallcenter/ability/exam/" + colindex; string data = "{\"questionnaireId\":" + colindex + "}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); Thread.Sleep(200); url = "https://mms.pinduoduo.com/rivendell/api/qualification/detail"; refere = "https://mms.pinduoduo.com/mallcenter/ability/exam/" + colindex; data = "{\"qualificationId\":" + rowindex + "}"; html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); Thread.Sleep(200); url = "https://mms.pinduoduo.com/rivendell/api/questionnaire/updateReadRecord"; refere = "https://mms.pinduoduo.com/mallcenter/ability/exam/" + colindex; data = "{\"questionnaireId\":" + colindex + "}"; html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); if (html.Contains("\"success\":true")) { string result = RetResult(colindex); //ShopQuestion sq = new ShopQuestion(); //sq.Shop = Shop; //sq.status = result; //AutoQuestion.ShopQuestionList.Add(sq); LogSave.Add(Name, result); } int randx = new Random(Guid.NewGuid().GetHashCode()).Next(1, 5); Thread.Sleep(randx); } } QueryStatusQuestion(); } public void QueryStatusQuestion() { satusList.Clear(); string url = "https://mms.pinduoduo.com/rivendell/api/qualification/getQualificationList"; string refere = "https://mms.pinduoduo.com/mallcenter/ability/index"; string data = "{}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, Shop.Cookies); var m = BaseRegex.GetMatchRegex(ref html, @"{""questionnaireId"":[^}]+?}"); for (int j = 0; m != null && j < m.Count; j++) { string item = m[j].Groups[0].Value; int questionnaireId = BaseRegex.GetIntJson(ref item, "questionnaireId"); int finished = BaseRegex.GetIntJson(ref item, "finished"); QuestionKeyValue qk = new QuestionKeyValue(); qk.key = questionnaireId; qk.value = finished; satusList.Add(qk); } var p = satusList.Find(s=>s.value==0); if (p != null) { ShopQuestion sq = new ShopQuestion(); sq.Shop = Shop; sq.status = "答题部分失败"; AutoQuestion.ShopQuestionList.Add(sq); } else { ShopQuestion sq = new ShopQuestion(); sq.Shop = Shop; sq.status = "答题全部成功"; AutoQuestion.ShopQuestionList.Add(sq); } } public void SetAllEquity() { satusList.Clear(); string urlx = "https://mms.pinduoduo.com/rivendell/api/qualification/getQualificationList"; string referex = "https://mms.pinduoduo.com/mallcenter/ability/index"; string datax = "{}"; string htmlx = GetPostTaobaoHtml.UploadTaobaoPost(urlx, referex, true, datax, Shop.Cookies); var m = BaseRegex.GetMatchRegex(ref htmlx, @"{""questionnaireId"":[^}]+?}"); for (int j = 0; m != null && j < m.Count; j++) { string item = m[j].Groups[0].Value; int questionnaireId = BaseRegex.GetIntJson(ref item, "questionnaireId"); int finished = BaseRegex.GetIntJson(ref item, "finished"); QuestionKeyValue qk = new QuestionKeyValue(); qk.key = questionnaireId; qk.value = finished; satusList.Add(qk); } string cookies = Shop.Cookies; for (int i = 1; i < 5; i++) { rowindex = i; if (satusList[4 * i - 4].value != 1 || satusList[4 * i - 3].value != 1 || satusList[4 * i - 2].value != 1 || satusList[4 * i-1].value != 1) continue; string url = "https://mms.pinduoduo.com/rivendell/api/qualification/receiveBenefits"; string refere = "https://mms.pinduoduo.com/mallcenter/ability/index"; string data = "{\"qualificationId\":" + rowindex + "}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); LogSave.Add(Name, RetResultEqu(i)); int randx = new Random(Guid.NewGuid().GetHashCode()).Next(1, 5); Thread.Sleep(randx); } QueryQuestion(1); } public void SetSingleEquity() { satusList.Clear(); string urlx = "https://mms.pinduoduo.com/rivendell/api/qualification/getQualificationList"; string referex = "https://mms.pinduoduo.com/mallcenter/ability/index"; string datax = "{}"; string htmlx = GetPostTaobaoHtml.UploadTaobaoPost(urlx, referex, true, datax, Shop.Cookies); var m = BaseRegex.GetMatchRegex(ref htmlx, @"{""questionnaireId"":[^}]+?}"); for (int j = 0; m != null && j < m.Count; j++) { string item = m[j].Groups[0].Value; int questionnaireId = BaseRegex.GetIntJson(ref item, "questionnaireId"); int finished = BaseRegex.GetIntJson(ref item, "finished"); QuestionKeyValue qk = new QuestionKeyValue(); qk.key = questionnaireId; qk.value = finished; satusList.Add(qk); } string cookies = Shop.Cookies; if (satusList[4 * rowindex - 4].value != 1 || satusList[4 * rowindex - 3].value != 1 || satusList[4 * rowindex - 2].value != 1 || satusList[4 * rowindex - 1].value != 1) return; string url = "https://mms.pinduoduo.com/rivendell/api/qualification/receiveBenefits"; string refere = "https://mms.pinduoduo.com/mallcenter/ability/index"; string data = "{\"qualificationId\":" + rowindex + "}"; string html = GetPostTaobaoHtml.UploadTaobaoPost(url, refere, true, data, cookies); LogSave.Add(Name, RetResultEqu(rowindex)); QueryQuestion(1); int randx = new Random(Guid.NewGuid().GetHashCode()).Next(1, 5); Thread.Sleep(randx); } public string RetResultEqu(int col, string str = "已领取权益") { string result = ""; switch (col) { case 1: result = "基础经营能力认证,"; break; case 2: result = "高级经营能力认证,"; break; case 3: result = "推广能力认证,"; break; case 4: result = "活动能力认证,"; break; } return Shop.ShopName + ":" + result + str; } public string RetResult(int col,string str= "已通过") { string result = ""; switch(col) { case 1: result = "基础经营能力认证,试题Ⅰ:新商家入驻"; break; case 2: result = "基础经营能力认证,试题Ⅱ:平台规则"; break; case 3: result = "基础经营能力认证,试题Ⅲ:商品设置、店铺运营"; break; case 4: result = "基础经营能力认证,试题Ⅳ:客户服务"; break; case 5: result = "高级经营能力认证,试题Ⅰ:店铺管理"; break; case 6: result = "高级经营能力认证,试题Ⅱ:商品管理"; break; case 7: result = "高级经营能力认证,试题Ⅲ:订单管理"; break; case 8: result = "高级经营能力认证,试题Ⅳ:售后管理"; break; case 9: result = "推广能力认证,试题Ⅰ:营销推广入门"; break; case 10: result = "推广能力认证,试题Ⅱ:营销推广基础"; break; case 11: result = "推广能力认证,试题Ⅲ:营销推广进阶"; break; case 12: result = "推广能力认证,试题Ⅳ:多多进宝"; break; case 13: result = "活动能力认证,试题Ⅰ:秒杀活动"; break; case 14: result = "活动能力认证,试题Ⅱ:领券中心"; break; case 15: result = "活动能力认证,试题Ⅲ:竞价"; break; case 16: result = "活动能力认证,试题Ⅳ:报名活动注意事项"; break; } return Shop.ShopName+":"+result+ str; } } public class ShopQuestion { public ShopChatBase Shop; public string status; public List satusList = new List(); } public class QuestionKeyValue { public int key; public int value; } }