| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using Microsoft.AspNetCore.Http;
- using Microsoft.AspNetCore.Mvc.Controllers;
- using Microsoft.AspNetCore.Mvc.Filters;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using dodohold.core;
- using Spire.Pdf.Exporting.XPS.Schema;
- using System.Xml.Linq;
- using System.Net;
- using TencentCloud.Mrs.V20200910.Models;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Authentication;
- using Spire.Pdf.Graphics;
- using Google.Protobuf.WellKnownTypes;
- using System.Threading.Channels;
- using TencentCloud.Weilingwith.V20230427.Models;
- using System.Threading;
- using System.Text.Json;
- namespace molilian.core
- {
- public partial class TaokeOpenCore
- {
- static string _test_base64String = string.Empty;
- private static string _end_point;
- static TaokeOpenCore()
- {
- _end_point = Environment.GetEnvironmentVariable("EndPoint");
- }
- public static async Task<APIResult> PromotionQueryAsync(string img, string oaid = "", string ip = "")
- {
- PromotionQueryDTO result = new()
- {
- end_point = _end_point,
- ip = ip,
- oaid = oaid,
- img = img
- };
- if (string.IsNullOrEmpty(img))
- {
- result.success = false;
- result.message = "调用失败";
- result.reason = "无效图片";
- _ = TkLogCore.PromotionImgLogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.reason,
- }, APIResultCodeEnum.OK, new JsonSerializerOptions
- {
- Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
- });
- }
- try
- {
- var account = TkPoolCore.GetOne(TkPoolCore.TkAction.promotionQuery);
- if (account == null)
- {
- result.success = false;
- result.message = "调用失败";
- result.reason = "没有匹配账号";
- _ = TkLogCore.PromotionImgLogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.reason,
- }, APIResultCodeEnum.OK, new JsonSerializerOptions
- {
- Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
- });
- }
- TaobaoOpenPlus taobao = new(account.appkey, account.appSecret, account.open_pid);
- var data = taobao.PromotionQueryRequest(img, oaid);
- if (data.IsError)
- {
- result.success = false;
- result.message = "调用失败";
- result.reason = data.ErrMsg;
- _ = TkLogCore.PromotionImgLogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.reason,
- }, APIResultCodeEnum.OK, new JsonSerializerOptions
- {
- Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
- });
- }
- if (!"0".Equals(data.Status))
- {
- result.success = false;
- result.message = "调用失败";
- result.reason = data.Desc;
- _ = TkLogCore.PromotionImgLogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.reason,
- }, APIResultCodeEnum.OK, new JsonSerializerOptions
- {
- Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
- });
- }
- result.url = data.Url;
- oaid = data.Url.GetContentPart("oaid=", "&");
- string cookies = string.Empty;
- (result.SimilarPromotion, cookies) = await taobao.GetRecommendData(TaobaoOpenPlus.RecommendRequestType.first, oaid, cookies);
- (result.PromotionImg, cookies) = await taobao.GetRecommendData(TaobaoOpenPlus.RecommendRequestType.ori, oaid, cookies);
- result.similarPromotion = result.SimilarPromotion.Convert2Json();
- result.promotionImg = result.PromotionImg.Convert2Json();
- result.success = true;
- result.message = "调用成功";
- _ = TkLogCore.PromotionImgLogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.reason,
- similarPromotion = result.SimilarPromotion,
- promotionImg = result.PromotionImg,
- result.url,
- }, APIResultCodeEnum.OK, new JsonSerializerOptions
- {
- Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
- });
- }
- catch (Exception ex)
- {
- result.success = false;
- result.message = "调用失败";
- result.reason = ex.Message;
- _ = TkLogCore.PromotionImgLogAsync(result);
- return new APIResult(new
- {
- result.success,
- result.message,
- result.reason,
- }, APIResultCodeEnum.OK, new JsonSerializerOptions
- {
- Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
- });
- }
- //try
- //{
- // var account = TkPoolCore.GetOne(TkPoolCore.TkAction.promotionQuery);
- // if (account == null)
- // {
- // result.success = false;
- // result.message = "放弃转链";
- // result.reason = "没有匹配账号";
- // //_ = TkLogCore.CouponLogAsync(result);
- // return new APIResult(new
- // {
- // result.success,
- // message = "没有优惠券",
- // channel = result.channel.ToString(),
- // });
- // }
- // result.accountId = account.id;
- // result.accountName = account.name;
- // alimama = new AlimamaPlus(account);
- // result = await alimama.PromotionQueryAsync(result);
- // if (result.success && result.couponAmount == 0)
- // {
- // result.success = false;
- // result.message = "没有优惠券";
- // result.reason = "没有优惠券";
- // }
- //}
- //catch (Exception ex)
- //{
- // if (ex.Message.Contains("was canceled"))
- // {
- // result.success = false;
- // result.message = "放弃转链";
- // result.reason = "请求超时";
- // }
- // else
- // {
- // _ = new LoggerLibrary("unionCoupon", "tb_error")
- // .Info(ip, oaid)
- // .Info(content)
- // .Info(ex.Message, ex.StackTrace)
- // .SaveAsync();
- // NotifyCore.Notify(new NifyMessage
- // {
- // message = $"【转链异常TB】\n{content}\n\n{ex.Message}\n{ex.StackTrace}",
- // priority = NifyMessagePriority.high,
- // tags = ["red_circle"]
- // });
- // result.success = false;
- // result.message = "放弃转链";
- // result.reason = "转链接口异常";
- // }
- //}
- //_ = TkLogCore.CouponLogAsync(result, alimama);
- //if (!result.success)
- //{
- // return new APIResult(new
- // {
- // result.success,
- // message = "没有优惠券",
- // channel = result?.channel.ToString(),
- // });
- //}
- //int couponAmount = (int)result.couponAmount * 100;
- //return new APIResult(new
- //{
- // result.success,
- // result.message,
- // channel = result?.channel.ToString(),
- // result?.itemId,
- // result?.deeplink_url,
- // result?.pic,
- // result?.couponEffectiveStartTime,
- // result?.couponEffectiveEndTime,
- //});
- }
- }
- }
|