1.优化代运营 补偿机制

This commit is contained in:
老道 2023-02-02 15:37:56 +08:00
parent fb296bb61c
commit 26303e1ffb
2 changed files with 379 additions and 331 deletions

View File

@ -51,15 +51,22 @@ namespace ProductClient
//创建配置文件
Config = this.ReadConfig<Config>();
//var thread = TimerTask.NewTimer<MonitorThread>(60) as MonitorThread;
EventClient.DyyNoticeEvent += EventClient_DyyNoticeEvent;
var thread = TimerTask.NewTimer<MonitorThread>(60) as MonitorThread;
//EventClient_DyyNoticeEvent(null, new DyyNoticeEvent()
//{
// //Data = "{\"Id\":\"122522636742819840\",\"TaskId\":\"122522636742819840\",\"IsGoods\":true}"
// Data = "{\"TaskId\":\"142515582485397504\",\"CollectionSourceId\":\"129505086429724672\",\"IsGoods\":true}"
//});
Task.Run(() =>
{
thread.Sleep(1000 * 30);
MonitorThread.GetDyyCircleGoodsLastTask();
});
}
catch (Exception ex)
{

View File

@ -17,6 +17,7 @@ using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using Api.Framework.Data.TB;
using Api.Framework.Events;
using static Api.Framework.Tools.TBHelper.TbAnalysis;
namespace ProductClient
@ -31,6 +32,17 @@ namespace ProductClient
try
{
count++;
var node = 5;
var hour = DateTime.Now.Hour;
if (2 <= hour && hour <= 6)
{
node = 30;
}
if (count % node == 0)
{
GetDyyCircleGoodsLastTask();
}
#region web接口检测
//if (count % 5 == 0)
@ -229,6 +241,35 @@ namespace ProductClient
//private static string ZJYUrl = string.Empty;
public static void GetDyyCircleGoodsLastTask()
{
try
{
var taskId = Class1.Config.SignId;
var sourceId = Class1.Config.sourceId;
if (sourceId == null)
{
sourceId = "129505086429724672";
}
// $"{taskId}[分段]{collectionSourceId}"
HttpHelper http = new HttpHelper();
var html = http.GetHtml($"http://goods.api.52cmg.cn/api/WechatMomentsGoods-WechatMoments/GetLastTaskV2", postData: $"SourceId={sourceId}&LastTaskId={taskId}").Html;
//"{\"TaskId\":\"130145086167056384\",\"CollectionSourceId\":\"129505086429724672\",\"IsGoods\":true}"
if (string.IsNullOrWhiteSpace(html))
{
return;
}
EventClient.OnDyyNoticeEvent(null, new DyyNoticeEvent() { Data = html });
}
catch (Exception ex)
{
EventClient.OnEvent("", $"代运营朋友圈 - 补偿:{ex.Message}");
}
}
/// <summary>
/// 阿里妈妈转连接
/// </summary>
@ -298,7 +339,7 @@ namespace ProductClient
if (string.IsNullOrWhiteSpace( /*ZJYUrl*/zjyUrl))
{
throw new Exception("生成防屏蔽连接为空,终止操作");
}
}
if (appendQrcode)
{
compositeQRCode = ApiClient.GetQRImage(turnItem.ItemTitle, turnItem.Price.ToString("0.00"), turnItem.CouponPrice.ToString("0"), turnItem.UseCouponPrice.ToString("0.00"), turnItem.ImageUrl, zjyUrl, Class1.Config.qrImageType);
@ -315,361 +356,361 @@ namespace ProductClient
/// </summary>
/// <param name="itemInfo"></param>
private string PinDuoDuoConvertLink(string itemUrl, bool appendQrcode, out string compositeQRCode)
{
var goods_id = PDDHelper.GetPddGoodsID(itemUrl);
if (string.IsNullOrWhiteSpace(goods_id)) throw new Exception("@解析拼多多商品Id失败,操作终止");
var session = ApiClient.GetSession();
if (string.IsNullOrWhiteSpace(Class1.Config.pddPid)) throw new Exception("未设置拼多多推广位,终止操作");
var reg = Regex.Match(Class1.Config.pddPid, @"(?<cpsname>\d+)_(\d+)");
if (!reg.Success) throw new Exception("拼多多推广位不符合格式,终止操作");
var cpsname = reg.Groups["cpsname"].ToString();
var adzone_pid = Class1.Config.pddPid;
var cps = new fl_cps_member() { username = cpsname, usernick = string.Empty, cookies = string.Empty, cpstype = CpsType., abnormal_tip = SwitchType., is_download = SwitchType., online = true };
PinduoduoApi api = CpsClient.CreatePinduoduoRequest(cps);
if (api == null) throw new Exception("创建多多进宝API请求失败,终止操作");
ArrayList goods_details = null;
var isBind = false;
var result = api.SendPinduoduo("pdd.ddk.oauth.member.authority.query", new { pid = adzone_pid });
if (result.ContainsKey("authority_query_response"))
{
var authority_query_response = result["authority_query_response"] as Dictionary<string, object>;
if (authority_query_response != null && authority_query_response.Count != 0)
isBind = int.Parse(authority_query_response["bind"].ToString()) == 1;//1-已绑定0-未绑定
}
goods_details = PDDHelper.FindSendGuideGoodsInfo(api, adzone_pid, goods_id, isBind);
//没有查到返利提示
if (goods_details == null || goods_details.Count == 0)
throw new Exception("该商品无返利,操作终止");
foreach (var item in goods_details)
{
var temp = item as Dictionary<string, object>;
string mall_id = string.Empty;
if (temp.ContainsKey("mall_id")) mall_id = temp["mall_id"].ToString();
var goods_sign = temp["goods_sign"].ToString();
var goods_name = (temp["goods_name"] ?? string.Empty).ToString().Replace("", "").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&").Replace("&quot;", "\"").Replace(" &copy;", "©"); //获取商品标签
var goods_desc = (temp["goods_desc"] ?? string.Empty).ToString(); //商品描述
var goods_thumbnail_url = (temp["goods_thumbnail_url"] ?? string.Empty).ToString(); //商品主图
var min_group_price = Math.Round(temp["min_group_price"] == null ? 0 : (double.Parse(temp["min_group_price"].ToString()) / 100.00), 2); //最低价sku的拼团价单位为分
//var min_normal_price = Math.Round(temp["min_normal_price"] == null ? 0 : (double.Parse(temp["min_normal_price"].ToString()) / 100.00), 2); //最低价sku的单买价单位为分
var _coupon_discount = double.Parse((temp["coupon_discount"] ?? 0).ToString());
var coupon_discount = _coupon_discount == 0 ? 0 : Math.Round(_coupon_discount / 100.00, 2); //优惠券面额,单位为分
var pddHelper = new PDDHelper();
var manyShoppingUrl = pddHelper.GetShoppingUrl(api, new { p_id = adzone_pid, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = true, generate_short_url = true, generate_weapp_webview = true, force_duo_id = true, generate_authority_url = !isBind, generate_schema_url = true });
if (appendQrcode)
compositeQRCode = ApiClient.GetQRImage(goods_name, min_group_price.ToString(), coupon_discount.ToString(), ((decimal)min_group_price - (decimal)coupon_discount).ToString(), goods_thumbnail_url, manyShoppingUrl, Class1.Config.qrImageType, CpsType., goods_desc);
else compositeQRCode = string.Empty;
return manyShoppingUrl;
}
//EventClient.OnEvent(this, $"朋友圈代运营拼多多转链异常:{ex.Message} - {ex.StackTrace}");
compositeQRCode = string.Empty;
return string.Empty;
}
/// <summary>
/// 京东联盟转连接
/// </summary>
/// <param name="itemInfo"></param>
private string JingDongConvertLink(string itemUrl, bool appendQrcode, out string compositeQRCode)
{
var itemId = JDHelper.GetJingdongItemId(itemUrl);//匹配京东链接获取京东宝贝ID
if (string.IsNullOrEmpty(itemId)) throw new Exception($"@解析京东商品Id失败{itemUrl}");
var session = ApiClient.GetSession();
//var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.custom_type == Resources.SoftwareType && f.alliance_id == (int)CpsType.京东联盟);
//if (adzone == null) throw new Exception("未设置京东推广位,终止操作");
if (string.IsNullOrWhiteSpace(Class1.Config.jdPid)) throw new Exception("未设置京东推广位,终止操作");
var reg = Regex.Match(Class1.Config.jdPid, @"(?<pid>(?<cpsname>\d+)_\d+_(?<positionId>\d+))_(?<key>.+)");
if (!reg.Success) throw new Exception("推广位格式不正确");
var cpsname = reg.Groups["cpsname"].ToString();
var key = reg.Groups["key"].ToString();
//var pid = reg.Groups["pid"].ToString();
var positionId = reg.Groups["positionId"].ToString();
var cps = new fl_cps_member() { username = key, usernick = cpsname, cpstype = CpsType., online = true, cookies = string.Empty, abnormal_tip = SwitchType., is_download = SwitchType. };
//var cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.京东联盟 && f.username == adzone.adzone_pid_cps_name);
//if (cps == null) throw new Exception("京东账号异常,终止操作");
var api = new JingdongApi(cps);
if (api == null) throw new Exception("创建京东联盟API请求失败,终止操作");
var goodInfoResult = api.SendJingdong("jd.union.open.goods.query", new { goodsReqDTO = new { skuIds = new string[] { itemId } } });
var goodData = goodInfoResult.ConvertToObj<goodInfo_temp>();
if (goodData.data == null) throw new Exception("京东无返利信息");
foreach (Dictionary<string, object> _goodinfo in goodData.data)
{
var goodinfo = _goodinfo.ConvertToObj<GoodsResp>();
goodinfo.skuName = goodinfo.skuName.Replace("", "").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&").Replace("&quot;", "\"").Replace(" &copy;", "©");
if (goodinfo.commissionInfo.Count != 0)//有佣金
{
var isJdSale = goodinfo.isJdSale == 0 ? false : true;//是否已是京东自营
var goods_id = PDDHelper.GetPddGoodsID(itemUrl);
if (string.IsNullOrWhiteSpace(goods_id)) throw new Exception("@解析拼多多商品Id失败,操作终止");
var session = ApiClient.GetSession();
double price = double.Parse(goodinfo.priceInfo["price"].ToString()); //商品价格
if (string.IsNullOrWhiteSpace(Class1.Config.pddPid)) throw new Exception("未设置拼多多推广位,终止操作");
var reg = Regex.Match(Class1.Config.pddPid, @"(?<cpsname>\d+)_(\d+)");
if (!reg.Success) throw new Exception("拼多多推广位不符合格式,终止操作");
var cpsname = reg.Groups["cpsname"].ToString();
var adzone_pid = Class1.Config.pddPid;
var commissionshare = decimal.Parse(goodinfo.commissionInfo["commissionShare"].ToString()) / 100m;//普通用户佣金比例 ,通用接口中的佣金比例
var cps = new fl_cps_member() { username = cpsname, usernick = string.Empty, cookies = string.Empty, cpstype = CpsType., abnormal_tip = SwitchType., is_download = SwitchType., online = true };
#region ,,
try
PinduoduoApi api = CpsClient.CreatePinduoduoRequest(cps);
if (api == null) throw new Exception("创建多多进宝API请求失败,终止操作");
ArrayList goods_details = null;
var isBind = false;
var result = api.SendPinduoduo("pdd.ddk.oauth.member.authority.query", new { pid = adzone_pid });
if (result.ContainsKey("authority_query_response"))
{
var goodResult = api.SendJingdong("jd.union.open.goods.promotiongoodsinfo.query", new { skuIds = itemId });
if (goodResult != null && goodResult.ContainsKey("data"))
var authority_query_response = result["authority_query_response"] as Dictionary<string, object>;
if (authority_query_response != null && authority_query_response.Count != 0)
isBind = int.Parse(authority_query_response["bind"].ToString()) == 1;//1-已绑定0-未绑定
}
goods_details = PDDHelper.FindSendGuideGoodsInfo(api, adzone_pid, goods_id, isBind);
//没有查到返利提示
if (goods_details == null || goods_details.Count == 0)
throw new Exception("该商品无返利,操作终止");
foreach (var item in goods_details)
{
var temp = item as Dictionary<string, object>;
string mall_id = string.Empty;
if (temp.ContainsKey("mall_id")) mall_id = temp["mall_id"].ToString();
var goods_sign = temp["goods_sign"].ToString();
var goods_name = (temp["goods_name"] ?? string.Empty).ToString().Replace("", "").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&").Replace("&quot;", "\"").Replace(" &copy;", "©"); //获取商品标签
var goods_desc = (temp["goods_desc"] ?? string.Empty).ToString(); //商品描述
var goods_thumbnail_url = (temp["goods_thumbnail_url"] ?? string.Empty).ToString(); //商品主图
var min_group_price = Math.Round(temp["min_group_price"] == null ? 0 : (double.Parse(temp["min_group_price"].ToString()) / 100.00), 2); //最低价sku的拼团价单位为分
//var min_normal_price = Math.Round(temp["min_normal_price"] == null ? 0 : (double.Parse(temp["min_normal_price"].ToString()) / 100.00), 2); //最低价sku的单买价单位为分
var _coupon_discount = double.Parse((temp["coupon_discount"] ?? 0).ToString());
var coupon_discount = _coupon_discount == 0 ? 0 : Math.Round(_coupon_discount / 100.00, 2); //优惠券面额,单位为分
var pddHelper = new PDDHelper();
var manyShoppingUrl = pddHelper.GetShoppingUrl(api, new { p_id = adzone_pid, goods_sign_list = $"[\"{goods_sign}\"]", multi_group = true, generate_short_url = true, generate_weapp_webview = true, force_duo_id = true, generate_authority_url = !isBind, generate_schema_url = true });
if (appendQrcode)
compositeQRCode = ApiClient.GetQRImage(goods_name, min_group_price.ToString(), coupon_discount.ToString(), ((decimal)min_group_price - (decimal)coupon_discount).ToString(), goods_thumbnail_url, manyShoppingUrl, Class1.Config.qrImageType, CpsType., goods_desc);
else compositeQRCode = string.Empty;
return manyShoppingUrl;
}
//EventClient.OnEvent(this, $"朋友圈代运营拼多多转链异常:{ex.Message} - {ex.StackTrace}");
compositeQRCode = string.Empty;
return string.Empty;
}
/// <summary>
/// 京东联盟转连接
/// </summary>
/// <param name="itemInfo"></param>
private string JingDongConvertLink(string itemUrl, bool appendQrcode, out string compositeQRCode)
{
var itemId = JDHelper.GetJingdongItemId(itemUrl);//匹配京东链接获取京东宝贝ID
if (string.IsNullOrEmpty(itemId)) throw new Exception($"@解析京东商品Id失败{itemUrl}");
var session = ApiClient.GetSession();
//var adzone = session.FindAdzoneInfos().FirstOrDefault(f => f.custom_type == Resources.SoftwareType && f.alliance_id == (int)CpsType.京东联盟);
//if (adzone == null) throw new Exception("未设置京东推广位,终止操作");
if (string.IsNullOrWhiteSpace(Class1.Config.jdPid)) throw new Exception("未设置京东推广位,终止操作");
var reg = Regex.Match(Class1.Config.jdPid, @"(?<pid>(?<cpsname>\d+)_\d+_(?<positionId>\d+))_(?<key>.+)");
if (!reg.Success) throw new Exception("推广位格式不正确");
var cpsname = reg.Groups["cpsname"].ToString();
var key = reg.Groups["key"].ToString();
//var pid = reg.Groups["pid"].ToString();
var positionId = reg.Groups["positionId"].ToString();
var cps = new fl_cps_member() { username = key, usernick = cpsname, cpstype = CpsType., online = true, cookies = string.Empty, abnormal_tip = SwitchType., is_download = SwitchType. };
//var cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.京东联盟 && f.username == adzone.adzone_pid_cps_name);
//if (cps == null) throw new Exception("京东账号异常,终止操作");
var api = new JingdongApi(cps);
if (api == null) throw new Exception("创建京东联盟API请求失败,终止操作");
var goodInfoResult = api.SendJingdong("jd.union.open.goods.query", new { goodsReqDTO = new { skuIds = new string[] { itemId } } });
var goodData = goodInfoResult.ConvertToObj<goodInfo_temp>();
if (goodData.data == null) throw new Exception("京东无返利信息");
foreach (Dictionary<string, object> _goodinfo in goodData.data)
{
var goodinfo = _goodinfo.ConvertToObj<GoodsResp>();
goodinfo.skuName = goodinfo.skuName.Replace("", "").Replace("&lt;", "<").Replace("&gt;", ">").Replace("&amp;", "&").Replace("&quot;", "\"").Replace(" &copy;", "©");
if (goodinfo.commissionInfo.Count != 0)//有佣金
{
var _goodData = goodResult["data"] as ArrayList;
if (_goodData != null && _goodData.Count != 0)
var isJdSale = goodinfo.isJdSale == 0 ? false : true;//是否已是京东自营
double price = double.Parse(goodinfo.priceInfo["price"].ToString()); //商品价格
var commissionshare = decimal.Parse(goodinfo.commissionInfo["commissionShare"].ToString()) / 100m;//普通用户佣金比例 ,通用接口中的佣金比例
#region ,,
try
{
foreach (Dictionary<string, object> data in _goodData)
var goodResult = api.SendJingdong("jd.union.open.goods.promotiongoodsinfo.query", new { skuIds = itemId });
if (goodResult != null && goodResult.ContainsKey("data"))
{
if (data.ContainsKey("commisionRatioWl"))
var _goodData = goodResult["data"] as ArrayList;
if (_goodData != null && _goodData.Count != 0)
{
commissionshare = decimal.Parse(data["commisionRatioWl"].ToString()) / 100m; //接口中该商品的实际佣金,比较准一些,
break;
foreach (Dictionary<string, object> data in _goodData)
{
if (data.ContainsKey("commisionRatioWl"))
{
commissionshare = decimal.Parse(data["commisionRatioWl"].ToString()) / 100m; //接口中该商品的实际佣金,比较准一些,
break;
}
}
}
}
}
}
}
catch (Exception)
{ }
#endregion
catch (Exception)
{ }
#endregion
ItemPoint usecoupon_commfee = null;//普通用户 用优惠券后积分信息
//ItemPoint usecoupon_commfee_plus = null;//plus用户 用优惠券后积分信息
string couponlike = string.Empty; //优惠券链接
double discount = 0; //优惠券金额
if (goodinfo.couponInfo.Count != 0)
{
//goodinfo.couponInfo[0].couponList[0];
var couponList = goodinfo.couponInfo["couponList"] as ArrayList;
if (couponList.Count != 0)//有优惠券
{
foreach (Dictionary<string, object> coupon in couponList)
ItemPoint usecoupon_commfee = null;//普通用户 用优惠券后积分信息
//ItemPoint usecoupon_commfee_plus = null;//plus用户 用优惠券后积分信息
string couponlike = string.Empty; //优惠券链接
double discount = 0; //优惠券金额
if (goodinfo.couponInfo.Count != 0)
{
var quota = double.Parse(coupon["quota"].ToString()); //券消费限额
if (quota > price) break;//优惠券面额大于商品单价时终止
discount = double.Parse(coupon["discount"].ToString());
couponlike = coupon["link"].ToString(); //优惠券链接
break;//TODO 这里难道有多个优惠券?先不管,直接获取第一个
//goodinfo.couponInfo[0].couponList[0];
var couponList = goodinfo.couponInfo["couponList"] as ArrayList;
if (couponList.Count != 0)//有优惠券
{
foreach (Dictionary<string, object> coupon in couponList)
{
var quota = double.Parse(coupon["quota"].ToString()); //券消费限额
if (quota > price) break;//优惠券面额大于商品单价时终止
discount = double.Parse(coupon["discount"].ToString());
couponlike = coupon["link"].ToString(); //优惠券链接
break;//TODO 这里难道有多个优惠券?先不管,直接获取第一个
}
}
}
}
}
var buyshorturl = string.Empty; //转连后的地址
#region (广 [()])
Dictionary<string, object> conversionlinkresult = null; //查询到的转换链接对象
//var positionId = adzone.adzone_pid.Substring(adzone.adzone_pid.LastIndexOf("_") + 1);
if (string.IsNullOrWhiteSpace(couponlike))
{
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = cps.usernick } });//宝贝id 和 用户的目标推客的联盟id
}
else
{
try
{
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = cps.usernick, couponUrl = couponlike } });
}
catch (Exception)
{
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = cps.usernick } });//宝贝id 和 用户的目标推客的联盟id
couponlike = string.Empty;
}
}
if (conversionlinkresult != null)
{
if (conversionlinkresult["code"].ToString() != "200") throw new Exception($"京东查询接口调用失败:{conversionlinkresult["message"].ToString()}");//抛出错误信息
if (conversionlinkresult.ContainsKey("data"))
{
var data = conversionlinkresult["data"] as Dictionary<string, object>;
if (data.ContainsKey("shortURL")) buyshorturl = data["shortURL"].ToString();//购买短连接
}
if (string.IsNullOrWhiteSpace(buyshorturl)) throw new Exception("京东转链失败,请稍后重试");
}
#endregion
var imageList = goodinfo.imageInfo["imageList"] as ArrayList;
string imageUrl = string.Empty;
if (imageList.Count > 0)
imageUrl = (imageList[0] as Dictionary<string, object>)["url"].ToString(); //宝贝主图
if (appendQrcode)
compositeQRCode = ApiClient.GetQRImage(goodinfo.skuName, price.ToString(), discount.ToString(), ((decimal)price - (decimal)discount).ToString(), imageUrl, buyshorturl, Class1.Config.qrImageType, CpsType.);
else compositeQRCode = string.Empty;
return buyshorturl;
}
}
//EventClient.OnEvent(this, $"朋友圈代运营京东转链异常:{ex.Message} - {ex.StackTrace}");
compositeQRCode = string.Empty;
return string.Empty;
}
///// <summary>
///// 执行发送任务
///// </summary>
//private void _ExecuteSend(string objectDesc, string comment)
//{
// try
// {
// if (string.IsNullOrWhiteSpace(objectDesc)) return;
// var clients = Chat.Framework.ChatClient.WXClient.Values.ToList().Where(f => (f.WeixinType == WeixinType.Grpc微信 || f.WeixinType == WeixinType.Hook微信) && f.Status == WxStatus.在线).ToList();
// if (clients.Count != 0)
// {
// foreach (var _item in clients)
// {
// var item = _item;
// //Task.Run(() =>
// //{
// try
// {
// //objectDesc = Regex.Replace(objectDesc, @"videomd5=""(.{32})""", @"videomd5=""" + Util.GetMD5Hash(Guid.NewGuid().ToByteArray()) + @"""");
// //objectDesc = Regex.Replace(objectDesc, @"md5=""(.{32})""", @"md5=""" + Util.GetMD5Hash(Guid.NewGuid().ToByteArray()) + @"""");
// objectDesc = objectDesc.Replace("[活动口令]", Class1.Config.actionLink);
// var json = item.SendCircle(objectDesc);//发送朋友圈的主内容
// if (string.IsNullOrWhiteSpace(json))
// EventClient.OnEvent(this, $"【代运营朋友圈】 => {item.WeixinHao},转发失败");
// else
// EventClient.OnEvent(this, $"【代运营朋友圈】 => {item.WeixinHao},转发成功");
// if (!Class1.Config.isPl)
// {
// var reg = Regex.Match(json.Replace("<![CDATA[", "").Replace("]]>", ""), @"<id>(?<id>\d{15,})</id>");//获取返回的朋友圈id
// if (reg.Success && !string.IsNullOrWhiteSpace(comment))
// {
// var id = reg.Groups["id"].Value;
// var commentStr = string.Empty;
// if (string.IsNullOrWhiteSpace(Class1.Config.appendComment))
// commentStr = string.Join("[分段]", comment);
// else
// commentStr = string.Join("[分段]", comment, Class1.Config.appendComment);
// if (!string.IsNullOrWhiteSpace(commentStr))
// item.SendCircleComment(item.User.Username, id, commentStr.Replace("[活动口令]", Class1.Config.actionLink));
// }
// }
// }
// catch (Exception ex)
// {
// EventClient.OnEvent(this, $"【代运营朋友圈】 发送异常:{ex.Message} - {ex.StackTrace}");
// }
// //});
// }
// if (Class1.Config.Monitor_Interval != 0)
// {
// Class1.Config.LastSendTime = DateTime.Now;
// Util.Save(Class1.Config);
// }
// EventClient.OnEvent(this, $"【代运营朋友圈】 所有账号发送完毕");
// }
// }
// catch (Exception ex)
// {
// EventClient.OnEvent(this, $"【代运营朋友圈】 发送失败:{ex.Message} - {ex.StackTrace}");
// }
//}
/// <summary>
/// 执行发送任务
/// </summary>
public static void _ExecuteSend(string objectDesc, List<string> comments, bool isGoods, string taskId)
{
try
{
if (string.IsNullOrWhiteSpace(objectDesc))
{
return;
}
comments.Add(Class1.Config.appendComment);
var commentStr = string.Join("[分段]", comments);
var clients = Chat.Framework.ChatClient.WXClient.Values.ToList().Where(f => (f.WeixinType == WeixinType.Grpc微信 || f.WeixinType == WeixinType.Hook微信) && f.Status == WxStatus.线).ToList();
if (clients.Count != 0)
{
foreach (var _item in clients)
{
var item = _item;
//Task.Run(() =>
//{
try
{
//objectDesc = Regex.Replace(objectDesc, @"videomd5=""(.{32})""", @"videomd5=""" + Util.GetMD5Hash(Guid.NewGuid().ToByteArray()) + @"""");
//objectDesc = Regex.Replace(objectDesc, @"md5=""(.{32})""", @"md5=""" + Util.GetMD5Hash(Guid.NewGuid().ToByteArray()) + @"""");
objectDesc = objectDesc.Replace("[活动口令]", Class1.Config.actionLink);
var json = item.SendCircle(objectDesc);//发送朋友圈的主内容
if (string.IsNullOrWhiteSpace(json))
EventClient.OnEvent(null, $"【代运营朋友圈】 => {item.WeixinHao},转发失败");
var buyshorturl = string.Empty; //转连后的地址
#region (广 [()])
Dictionary<string, object> conversionlinkresult = null; //查询到的转换链接对象
//var positionId = adzone.adzone_pid.Substring(adzone.adzone_pid.LastIndexOf("_") + 1);
if (string.IsNullOrWhiteSpace(couponlike))
{
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = cps.usernick } });//宝贝id 和 用户的目标推客的联盟id
}
else
EventClient.OnEvent(null, $"【代运营朋友圈】 => {item.WeixinHao},转发成功");
//if (!Class1.Config.isPl)
//{
var reg = Regex.Match(json.Replace("<![CDATA[", "").Replace("]]>", ""), @"<id>(?<id>\d{15,})</id>");//获取返回的朋友圈id
if (reg.Success && !string.IsNullOrWhiteSpace(commentStr))
{
var id = reg.Groups["id"].Value;
EventClient.OnEvent(null, $"【代运营朋友圈】 => {item.WeixinHao},评论内容:{commentStr}");
if (!string.IsNullOrWhiteSpace(commentStr))
try
{
item.SendCircleComment(item.User.Username, id, commentStr.Replace("[活动口令]", Class1.Config.actionLink));
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = cps.usernick, couponUrl = couponlike } });
}
if (isGoods)
catch (Exception)
{
#region
HttpHelper http = new HttpHelper();
var html = http.GetHtml($"http://goods.api.52cmg.cn/api/WechatMomentsGoods-WechatMoments/RecordSending?taskId={taskId}").Html;
#endregion
conversionlinkresult = api.SendJingdong("jd.union.open.promotion.byunionid.get", new { promotionCodeReq = new { materialId = $@"https://item.m.jd.com/product/{itemId}.html", positionId = positionId, unionId = cps.usernick } });//宝贝id 和 用户的目标推客的联盟id
couponlike = string.Empty;
}
}
//}
if (conversionlinkresult != null)
{
if (conversionlinkresult["code"].ToString() != "200") throw new Exception($"京东查询接口调用失败:{conversionlinkresult["message"].ToString()}");//抛出错误信息
if (conversionlinkresult.ContainsKey("data"))
{
var data = conversionlinkresult["data"] as Dictionary<string, object>;
if (data.ContainsKey("shortURL")) buyshorturl = data["shortURL"].ToString();//购买短连接
}
if (string.IsNullOrWhiteSpace(buyshorturl)) throw new Exception("京东转链失败,请稍后重试");
}
#endregion
var imageList = goodinfo.imageInfo["imageList"] as ArrayList;
string imageUrl = string.Empty;
if (imageList.Count > 0)
imageUrl = (imageList[0] as Dictionary<string, object>)["url"].ToString(); //宝贝主图
if (appendQrcode)
compositeQRCode = ApiClient.GetQRImage(goodinfo.skuName, price.ToString(), discount.ToString(), ((decimal)price - (decimal)discount).ToString(), imageUrl, buyshorturl, Class1.Config.qrImageType, CpsType.);
else compositeQRCode = string.Empty;
return buyshorturl;
}
catch (Exception ex)
{
EventClient.OnEvent(null, $"【代运营朋友圈】 发送异常:{ex.Message} - {ex.StackTrace}");
}
//});
}
if (Class1.Config.Monitor_Interval != 0)
{
Class1.Config.LastSendTime = DateTime.Now;
Util.Save(Class1.Config);
}
EventClient.OnEvent(null, $"【代运营朋友圈】 所有账号发送完毕");
//EventClient.OnEvent(this, $"朋友圈代运营京东转链异常:{ex.Message} - {ex.StackTrace}");
compositeQRCode = string.Empty;
return string.Empty;
}
///// <summary>
///// 执行发送任务
///// </summary>
//private void _ExecuteSend(string objectDesc, string comment)
//{
// try
// {
// if (string.IsNullOrWhiteSpace(objectDesc)) return;
// var clients = Chat.Framework.ChatClient.WXClient.Values.ToList().Where(f => (f.WeixinType == WeixinType.Grpc微信 || f.WeixinType == WeixinType.Hook微信) && f.Status == WxStatus.在线).ToList();
// if (clients.Count != 0)
// {
// foreach (var _item in clients)
// {
// var item = _item;
// //Task.Run(() =>
// //{
// try
// {
// //objectDesc = Regex.Replace(objectDesc, @"videomd5=""(.{32})""", @"videomd5=""" + Util.GetMD5Hash(Guid.NewGuid().ToByteArray()) + @"""");
// //objectDesc = Regex.Replace(objectDesc, @"md5=""(.{32})""", @"md5=""" + Util.GetMD5Hash(Guid.NewGuid().ToByteArray()) + @"""");
// objectDesc = objectDesc.Replace("[活动口令]", Class1.Config.actionLink);
// var json = item.SendCircle(objectDesc);//发送朋友圈的主内容
// if (string.IsNullOrWhiteSpace(json))
// EventClient.OnEvent(this, $"【代运营朋友圈】 => {item.WeixinHao},转发失败");
// else
// EventClient.OnEvent(this, $"【代运营朋友圈】 => {item.WeixinHao},转发成功");
// if (!Class1.Config.isPl)
// {
// var reg = Regex.Match(json.Replace("<![CDATA[", "").Replace("]]>", ""), @"<id>(?<id>\d{15,})</id>");//获取返回的朋友圈id
// if (reg.Success && !string.IsNullOrWhiteSpace(comment))
// {
// var id = reg.Groups["id"].Value;
// var commentStr = string.Empty;
// if (string.IsNullOrWhiteSpace(Class1.Config.appendComment))
// commentStr = string.Join("[分段]", comment);
// else
// commentStr = string.Join("[分段]", comment, Class1.Config.appendComment);
// if (!string.IsNullOrWhiteSpace(commentStr))
// item.SendCircleComment(item.User.Username, id, commentStr.Replace("[活动口令]", Class1.Config.actionLink));
// }
// }
// }
// catch (Exception ex)
// {
// EventClient.OnEvent(this, $"【代运营朋友圈】 发送异常:{ex.Message} - {ex.StackTrace}");
// }
// //});
// }
// if (Class1.Config.Monitor_Interval != 0)
// {
// Class1.Config.LastSendTime = DateTime.Now;
// Util.Save(Class1.Config);
// }
// EventClient.OnEvent(this, $"【代运营朋友圈】 所有账号发送完毕");
// }
// }
// catch (Exception ex)
// {
// EventClient.OnEvent(this, $"【代运营朋友圈】 发送失败:{ex.Message} - {ex.StackTrace}");
// }
//}
/// <summary>
/// 执行发送任务
/// </summary>
public static void _ExecuteSend(string objectDesc, List<string> comments, bool isGoods, string taskId)
{
try
{
if (string.IsNullOrWhiteSpace(objectDesc))
{
return;
}
comments.Add(Class1.Config.appendComment);
var commentStr = string.Join("[分段]", comments);
var clients = Chat.Framework.ChatClient.WXClient.Values.ToList().Where(f => (f.WeixinType == WeixinType.Grpc微信 || f.WeixinType == WeixinType.Hook微信) && f.Status == WxStatus.线).ToList();
if (clients.Count != 0)
{
foreach (var _item in clients)
{
var item = _item;
//Task.Run(() =>
//{
try
{
//objectDesc = Regex.Replace(objectDesc, @"videomd5=""(.{32})""", @"videomd5=""" + Util.GetMD5Hash(Guid.NewGuid().ToByteArray()) + @"""");
//objectDesc = Regex.Replace(objectDesc, @"md5=""(.{32})""", @"md5=""" + Util.GetMD5Hash(Guid.NewGuid().ToByteArray()) + @"""");
objectDesc = objectDesc.Replace("[活动口令]", Class1.Config.actionLink);
var json = item.SendCircle(objectDesc);//发送朋友圈的主内容
if (string.IsNullOrWhiteSpace(json))
EventClient.OnEvent(null, $"【代运营朋友圈】 => {item.WeixinHao},转发失败");
else
EventClient.OnEvent(null, $"【代运营朋友圈】 => {item.WeixinHao},转发成功");
//if (!Class1.Config.isPl)
//{
var reg = Regex.Match(json.Replace("<![CDATA[", "").Replace("]]>", ""), @"<id>(?<id>\d{15,})</id>");//获取返回的朋友圈id
if (reg.Success && !string.IsNullOrWhiteSpace(commentStr))
{
var id = reg.Groups["id"].Value;
EventClient.OnEvent(null, $"【代运营朋友圈】 => {item.WeixinHao},评论内容:{commentStr}");
if (!string.IsNullOrWhiteSpace(commentStr))
{
item.SendCircleComment(item.User.Username, id, commentStr.Replace("[活动口令]", Class1.Config.actionLink));
}
if (isGoods)
{
#region
HttpHelper http = new HttpHelper();
var html = http.GetHtml($"http://goods.api.52cmg.cn/api/WechatMomentsGoods-WechatMoments/RecordSending?taskId={taskId}").Html;
#endregion
}
}
//}
}
catch (Exception ex)
{
EventClient.OnEvent(null, $"【代运营朋友圈】 发送异常:{ex.Message} - {ex.StackTrace}");
}
//});
}
if (Class1.Config.Monitor_Interval != 0)
{
Class1.Config.LastSendTime = DateTime.Now;
Util.Save(Class1.Config);
}
EventClient.OnEvent(null, $"【代运营朋友圈】 所有账号发送完毕");
}
}
catch (Exception ex)
{
EventClient.OnEvent(null, $"【代运营朋友圈】 发送失败:{ex.Message} - {ex.StackTrace}");
}
}
}
catch (Exception ex)
{
EventClient.OnEvent(null, $"【代运营朋友圈】 发送失败:{ex.Message} - {ex.StackTrace}");
}
}
}
}