Prechádzať zdrojové kódy

搜同款改用aliyun接口

dodo hold 1 rok pred
rodič
commit
4f6e88d71b

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 0 - 0
molilian.api/Properties/PublishProfiles/latest.pubxml.user


+ 4 - 5
molilian.api/Properties/launchSettings.json

@@ -4,7 +4,7 @@
       "commandName": "Project",
       "launchBrowser": true,
       "launchUrl": "swagger",
-      "environmentVariables": {
+      "environmentVariables2": {
         "ASPNETCORE_ENVIRONMENT": "Development",
         "EndPoint": "bj2",
         "NtfyServer": "https://ntfy.yunhui800.com/5Sq9BytXXM5WDY3G",
@@ -14,11 +14,10 @@
         "RedisConfig": "101.200.46.46:6379,password=pKBiS4ka2IpXayIdcx00,defaultDatabase=0,idleTimeout=20000,preheat=3,tryit=2,ssl=false,prefix=webhook",
         "CenterDB": "",
         "CenterRedis": ""
-      }
-    },
-      "environmentVariables2": {
+      },
+      "environmentVariables": {
         "ASPNETCORE_ENVIRONMENT": "Development",
-        "EndPoint": "bj2",
+        "EndPoint": "bj",
         "NtfyServer": "https://ntfy.yunhui800.com/5Sq9BytXXM5WDY3G",
         "ANPush": "",
         "DBType": "MySQL",

+ 64 - 0
molilian.core/Core/aliyun/AliyunCore.cs

@@ -10,6 +10,7 @@ using TencentCloud.Tke.V20180525.Models;
 using static AlibabaCloud.SDK.Ecs20140526.Models.DescribeInstancesResponseBody;
 using static AlibabaCloud.SDK.Ecs20140526.Models.DescribeNetworkInterfacesResponseBody;
 using static AlibabaCloud.SDK.Vpc20160428.Models.DescribeEipAddressesResponseBody.DescribeEipAddressesResponseBodyEipAddresses;
+using AlibabaCloud.SDK.ImageSearch20210501.Models;
 
 namespace molilian.core
 {
@@ -26,6 +27,69 @@ namespace molilian.core
             plus = new AliyunPlus(_account.accessKeyId, _account.accessKeySecret);
         }
 
+
+        public AliyunCore(string accessKeyId, string accessKeySecret)
+        {
+            plus = new AliyunPlus(accessKeyId, accessKeySecret);
+        }
+
+        public SearchByPicResponse SearchByPic(string base64String, string pid)
+        {
+            //account.refpid = "mm_6695915495_3161300068_115818650332";
+            return plus.SearchByPic(base64String, pid);
+        }
+
+        public PromotionQueryDTO picSimilaritem(string pic, string pid, ref PromotionQueryDTO result)
+        {
+            var response = plus.SearchByPic(pic, pid);
+            if (response == null)
+            {
+                result.message = "调用失败";
+                result.reason = "内部错误";
+                return result;
+            }
+
+            result.success = (bool)response.Body.Success;
+            if (!result.success)
+            {
+                result.message = "调用失败";
+                result.reason = $"{response.Body.Code}:{response.Body.Message}";
+                return result;
+            }
+
+
+            List<PromotionQueryItemDTO> arr = [];
+            foreach (var e in response.Body.Data.Auctions)
+            {
+                var item = e.Result;
+
+                PromotionQueryItemDTO newItem = new()
+                {
+                    itemId = item.ItemId,
+                    h5_url = string.IsNullOrEmpty(item.CouponShareUrl) ? item.Url : item.CouponShareUrl,
+                    deeplink_url = string.IsNullOrEmpty(item.DeeplinkCouponShareUrl) ? item.DeeplinkUrl : item.DeeplinkCouponShareUrl,
+                    userType = $"{item.UserType}",
+                    shopTitle = item.ShopTitle,
+                    itemName = item.Title,
+                    pic = item.PicUrl,
+                    price = item.ReservePrice,
+                    promotionPrice = item.PriceAfterCoupon,
+                    couponAmount = $"{item.CouponAmount}",
+                    couponEffectiveStartTime = item.CouponStartTime,
+                    couponEffectiveEndTime = item.CouponEndTime,
+                    sellCountStr = $"{item.Volume}",
+                    provcity = item.Provcity
+                };
+                arr.Add(newItem);
+            }
+
+            result.message = "OK";
+            result.reason = string.Empty;
+            result.PromotionImg = arr;
+            return result;
+        }
+
+
         public QueryAccountBalanceResponse QueryAccountBalance()
         {
             return plus.QueryAccountBalance();

+ 66 - 23
molilian.core/Core/taoke/TaokeOpenCore.cs

@@ -103,6 +103,10 @@ namespace molilian.core
 #if DEBUG
                 timeout = 50000;
 #endif
+
+                result.accountId = account.id;
+                result.accountName = account.name;
+
                 result.proxy_nodename = nodeName;
                 result.proxy_node = proxy?.Address?.Host;
 
@@ -110,35 +114,74 @@ namespace molilian.core
                 cts.CancelAfter(timeout);
 
                 DateTime stime = DateTime.Now;
-                if ("veapi".Equals(account.api) && account.api_id > 0)
-                {
-                    result.proxy_nodename = null;
-                    result.proxy_node = null;
-
-                    var api = VeapiPoolCore.Get(account.api_id);
-                    if (account != null)
-                    {
-                        var core = new VeapiPlus(account.name, api.key, api.sessionKey);
-                        core.picSimilaritem(img, ref result);
 
-                        var ts2 = DateTime.Now - stime;
-                        result.elapsedTime2 = (int)ts2.TotalMilliseconds;
+#if DEBUG
+                account.api_id = 17;
+                account.api = "aliyun";
+                account.refpid = "mm_6695915495_3161300068_115818650332";
+#endif
 
-                        _ = TkLogCore.PromotionImgLogAsync(result);
-                        return new APIResult(new
+                switch (account.api)
+                {
+                    case "veapi":
+                        if (account.api_id > 0)
                         {
-                            result.success,
-                            result.message,
-                            result.reason,
-                            promotionImg = result.PromotionImg
-                        }, APIResultCodeEnum.OK, new JsonSerializerOptions
+                            result.proxy_nodename = null;
+                            result.proxy_node = null;
+
+                            var api = VeapiPoolCore.Get(account.api_id);
+                                var core = new VeapiPlus(account.name, api.key, api.sessionKey);
+                                core.picSimilaritem(img, ref result);
+
+                                var ts2 = DateTime.Now - stime;
+                                result.elapsedTime2 = (int)ts2.TotalMilliseconds;
+
+                                _ = TkLogCore.PromotionImgLogAsync(result);
+                                return new APIResult(new
+                                {
+                                    result.success,
+                                    result.message,
+                                    result.reason,
+                                    promotionImg = result.PromotionImg
+                                }, APIResultCodeEnum.OK, new JsonSerializerOptions
+                                {
+                                    Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
+                                });
+                        }
+                        break;
+                    case "aliyun":
                         {
-                            Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
-                        });
-                    }
+                            result.proxy_nodename = null;
+                            result.proxy_node = null;
+
+                            AliyunCore api;
+                            if (account.api_id == 0)
+                            {
+                                api = new AliyunCore(account.appkey, account.appSecret);
+                            }
+                            else
+                            {
+                                api = new AliyunCore(account.api_id);
+                            }
+                            api.picSimilaritem(img, account.open_pid, ref result);
+
+                            var ts2 = DateTime.Now - stime;
+                            result.elapsedTime2 = (int)ts2.TotalMilliseconds;
+
+                            _ = TkLogCore.PromotionImgLogAsync(result);
+                            return new APIResult(new
+                            {
+                                result.success,
+                                result.message,
+                                result.reason,
+                                promotionImg = result.PromotionImg
+                            }, APIResultCodeEnum.OK, new JsonSerializerOptions
+                            {
+                                Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
+                            });
+                        }
                 }
 
-
                 var apiDelayTask = Task.Delay(500, cts.Token);
                 var apiRequestTask = Task.Run(() =>
                 {

+ 111 - 0
molilian.core/Plus/Aliyun/ImageSearch.cs

@@ -0,0 +1,111 @@
+using AlibabaCloud.OpenApiClient.Models;
+using AlibabaCloud.SDK.ImageSearch20210501.Models;
+using AlibabaCloud.SDK.ImageSearch20210501;
+using Tea;
+using dodohold.core;
+using COSXML.Network;
+using TencentCloud.Scf.V20180416.Models;
+
+
+namespace molilian.core
+{
+
+    public partial class AliyunPlus
+    {
+
+        public SearchByPicResponse SearchByPic(string base64String, string pid)
+        {
+            if (string.IsNullOrEmpty(base64String)) return null;
+            if (string.IsNullOrEmpty(pid)) return null;
+
+            try
+            {
+                byte[] bytes = Convert.FromBase64String(base64String);
+
+                AlibabaCloud.TeaUtil.Models.RuntimeOptions runtime = new();
+                Config config = new()
+                {
+                    AccessKeyId = _app_key,
+                    AccessKeySecret = _app_secret,
+                    Endpoint = "imagesearch.cn-shanghai.aliyuncs.com",
+                    RegionId = "cn-shanghai"
+                };
+                Client client = new(config);
+                SearchByPicAdvanceRequest request = new()
+                {
+                    PicContentObject = new MemoryStream(bytes),
+                    Pid = pid,
+                    Fields = "itemId,Url,CouponShareUrl,DeeplinkUrl,DeeplinkCouponShareUrl,UserType,ShopTitle,Title,PicUrl,ReservePrice,PriceAfterCoupon,CouponAmount,CouponStartTime,CouponEndTime,Volume,Provcity"
+                };
+
+                // 选填,需要返回的字段list。不同的字段用逗号分割。默认 PicUrl,ReservePrice,Title,Url,ZkFinalPrice
+                // request.Fields = "Title,PicUrl,ReservePrice,ZkFinalPrice,UserType,Provcity,Nick,SellerId,Volume,LevelOneCategoryName,CategoryName,CouponTotalCount,CouponRemainCount,CouponStartTime,CouponEndTime,CouponStartFee,CouponAmount,CouponInfo,CommissionRate,CouponShareUrl,Url,ShopTitle";
+                // 选填,图片类目
+                //request.CategoryId = 88888888;
+                // 选填,是否需要进行主体识别。默认true
+                //request.Crop = false;
+
+                // 选填,返回结果的起始位置。取值范围:0-499。默认值:0。
+                //request.Start = 0;
+                // 选填,返回结果的数目。取值范围:1-20。默认值:10。
+                //request.Num = 2;
+
+                // 选填,渠道ID。用于淘宝联盟中的渠道区分。
+                //request.relationId = 1145;
+
+
+                var response = client.SearchByPicAdvance(request, runtime);
+                return response;
+            }
+            catch (TeaException error)
+            {
+                // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+                // 错误 message
+                Console.WriteLine(error.Message);
+                // 诊断地址
+                Console.WriteLine(error.Data["Recommend"]);
+                AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
+
+
+                int.TryParse($"{error.DataResult["statusCode"]}", out int statusCode);
+                SearchByPicResponse response = new();
+                response.Body = new();
+                response.Body.Success = false;
+                response.Body.Code = statusCode;
+                response.Body.Message = $"{error.DataResult["Code"]},{error.DataResult["Message"]}";
+
+
+                LoggerLibrary log = new("SearchByPic", "tea");
+                log.Info(error.Message);
+                _ = log.SaveAsync();
+                return response;
+            }
+            catch (Exception _error)
+            {
+                TeaException error = new TeaException(new Dictionary<string, object>
+                {
+                    { "message", _error.Message }
+                });
+                // 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
+                // 错误 message
+                Console.WriteLine(error.Message);
+                // 诊断地址
+                Console.WriteLine(error.Data["Recommend"]);
+                AlibabaCloud.TeaUtil.Common.AssertAsString(error.Message);
+
+
+                LoggerLibrary log = new("SearchByPic", "error");
+                log.Info(error.Message);
+                log.Info(error.Data["Recommend"].Convert2Json());
+                _ = log.SaveAsync();
+
+
+            }
+
+            return null;
+        }
+
+
+    }
+
+}

+ 1 - 0
molilian.core/molilian.core.csproj

@@ -16,6 +16,7 @@
     <PackageReference Include="AlibabaCloud.OpenApiClient" Version="0.1.12" />
     <PackageReference Include="AlibabaCloud.SDK.BssOpenApi20171214" Version="3.0.2" />
     <PackageReference Include="AlibabaCloud.SDK.Ecs20140526" Version="4.4.8" />
+    <PackageReference Include="AlibabaCloud.SDK.ImageSearch20210501" Version="1.2.3" />
     <PackageReference Include="AlibabaCloud.SDK.Vpc20160428" Version="6.10.4" />
     <PackageReference Include="AlibabaCloud.TeaConsole" Version="0.1.0" />
     <PackageReference Include="AlibabaCloud.TeaUtil" Version="0.1.19" />

Niektoré súbory nie sú zobrazené, pretože je v týchto rozdielových dátach zmenené mnoho súborov