| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- using dodohold.core;
- using Microsoft.AspNetCore.Mvc;
- using System.Diagnostics;
- using System.Text.Json;
- using TencentCloud.Tcm.V20210413.Models;
- namespace molilian.core
- {
- public partial class AlimamaPlus
- {
- public async Task<TkDataDTO> endpoint_aliyun(string content, TkDataDTO result, CancellationToken cancellationToken = default)
- {
- string item_id = content.GetContentPart("item.htm?id=", "");
- if (string.IsNullOrEmpty(item_id))
- {
- _ = new LoggerLibrary("endpoint", "aliyun")
- .Info(content, "response null")
- .SaveAsync();
- result.channel = TkChannelEnum.tb;
- result.link_type = LinkTypeEnum.unknown;
- result.success = false;
- result.message = "放弃转链";
- result.reason = "无效商品id";
- return result;
- }
- var plus = new AliyunPlus(_account.appkey, _account.appSecret);
- var response = await plus.GetProductInfoByIds(item_id, _account.open_pid);
- if (response == null)
- {
- _ = new LoggerLibrary("endpoint", "aliyun")
- .Info(content, "response null")
- .SaveAsync();
- result.channel = TkChannelEnum.tb;
- result.link_type = LinkTypeEnum.unknown;
- result.success = false;
- result.message = "fail";
- result.reason = "接口异常";
- return result;
- }
- result.success = (bool)response.Body.Success;
- if (!result.success)
- {
- result.message = "fail";
- result.reason = $"{response.Body.Code}:{response.Body.Message}";
- _ = new LoggerLibrary("endpoint", "aliyun")
- .Info(content, result.reason)
- .SaveAsync();
- result.channel = TkChannelEnum.tb;
- result.link_type = LinkTypeEnum.unknown;
- result.success = false;
- return result;
- }
- if (response.Body.Data.Auctions.Count == 0)
- {
- _ = new LoggerLibrary("endpoint", "aliyun")
- .Info(content, "response null")
- .SaveAsync();
- result.channel = TkChannelEnum.tb;
- result.link_type = LinkTypeEnum.unknown;
- result.success = false;
- result.message = "result empty";
- result.reason = string.Empty;
- result.subCode = TkSubCodeEnum.NoConvert;
- return result;
- }
- var data = response.Body.Data.Auctions[0].Result;
- result.itemId = data.InputItemId;
- result.couponAmount = (decimal)data.CouponAmount;
- result.couponEffectiveStartTime = data.CouponStartTime;
- result.couponEffectiveEndTime = data.CouponEndTime;
- result.taoToken = string.Empty;
- string url = data.Url;
- if (url.StartsWith("//")) url = $"https:{url}";
- result.shortLinkurl = url;
- result.deeplink_url = AlimamaPlus.GetDeeplink(url);
- result.mktId = data.ItemId;
- result.itemName = data.Title;
- if (decimal.TryParse(data.PriceAfterCoupon, out decimal promotionPrice))
- {
- result.promotionPrice = promotionPrice;
- }
- result.sellerNickName = data.Nick;
- result.shopTitle = data.ShopTitle;
- string picUrl = data.PicUrl;
- if (picUrl.StartsWith("//")) picUrl = $"https:{picUrl}";
- result.pic = picUrl;
- return result;
- }
- }
- }
|