Browse Source

添加百度短网址接口API

yuzhengyang 6 years ago
parent
commit
9567bef739

+ 3 - 0
Azylee.Utils/Azylee.YeahWeb/Azylee.YeahWeb.csproj

@@ -41,6 +41,9 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="BaiDuWebAPI\dwz\DwzRequestModel.cs" />
+    <Compile Include="BaiDuWebAPI\dwz\DwzResponseModel.cs" />
+    <Compile Include="BaiDuWebAPI\dwz\DwzTool.cs" />
     <Compile Include="BaiDuWebAPI\GPSAPI\GPSInfoModel.cs" />
     <Compile Include="BaiDuWebAPI\GPSAPI\GPSInfoWebModel.cs" />
     <Compile Include="BaiDuWebAPI\GPSAPI\GPSPointWebModel.cs" />

+ 18 - 0
Azylee.Utils/Azylee.YeahWeb/BaiDuWebAPI/dwz/DwzRequestModel.cs

@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Azylee.YeahWeb.BaiDuWebAPI.dwz
+{
+    /// <summary>
+    /// 短网址请求模型
+    /// </summary>
+    public class DwzRequestModel
+    {
+        /// <summary>
+        /// 长网址
+        /// </summary>
+        public string  url { get; set; }
+    }
+}

+ 35 - 0
Azylee.Utils/Azylee.YeahWeb/BaiDuWebAPI/dwz/DwzResponseModel.cs

@@ -0,0 +1,35 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Azylee.YeahWeb.BaiDuWebAPI.dwz
+{
+    /// <summary>
+    /// 短网址响应结果模型
+    /// </summary>
+    public class DwzResponseModel
+    {
+        /// <summary>
+        /// 0:正常返回短网址,
+        /// -1:短网址生成失败,
+        /// -2:长网址不合法,
+        /// -3:长网址存在安全隐患,
+        /// -4:长网址插入数据库失败,
+        /// -5:长网址在黑名单中,不允许注册
+        /// </summary>
+        public int Code { get; set; }
+        /// <summary>
+        /// 短网址
+        /// </summary>
+        public string ShortUrl { get; set; }
+        /// <summary>
+        /// 长网址(原网址)
+        /// </summary>
+        public string LongUrl { get; set; }
+        /// <summary>
+        /// 错误信息
+        /// </summary>
+        public string ErrMsg { get; set; }
+    }
+}

+ 38 - 0
Azylee.Utils/Azylee.YeahWeb/BaiDuWebAPI/dwz/DwzTool.cs

@@ -0,0 +1,38 @@
+using Azylee.Jsons;
+using Azylee.YeahWeb.HttpUtils;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net;
+using System.Text;
+
+namespace Azylee.YeahWeb.BaiDuWebAPI.dwz
+{
+    public static class DwzTool
+    {
+        /// <summary>
+        /// 短网址生成接口
+        /// </summary>
+        /// <param name="token">由数字和字母组成的32位字符</param>
+        /// <param name="url">长网址</param>
+        /// <returns></returns>
+        public static DwzResponseModel Create(string token,string url )
+        {
+            try
+            {
+                string address = $"https://dwz.cn/admin/v2/create";
+                CookieCollection cookie = new CookieCollection();
+                DwzRequestModel data = new DwzRequestModel();
+                Dictionary<string, string> header = new Dictionary<string, string>();
+                data.url = url;
+                header.Add("Token", token);
+
+                string rs = HttpToolPlus.PostJson(address, ref cookie, data, Encoding.UTF8, header);
+                DwzResponseModel obj = Json.String2Object<DwzResponseModel>(rs);
+                if (obj != null) return obj;
+            }
+            catch { }
+            return null; 
+        }
+    }
+}

+ 8 - 4
Azylee.Utils/Tests/Test.YeahWeb/Program.cs

@@ -1,5 +1,7 @@
 using Azylee.Core.DataUtils.DateTimeUtils;
 using Azylee.Core.IOUtils.ImageUtils;
+using Azylee.Jsons;
+using Azylee.YeahWeb.BaiDuWebAPI.dwz;
 using Azylee.YeahWeb.BaiDuWebAPI.GPSAPI;
 using Azylee.YeahWeb.TencentWebAPI.PictureAI;
 using System;
@@ -14,16 +16,18 @@ namespace Test.YeahWeb
     {
         static void Main(string[] args)
         {
-            PictureScener.GetInfo(1107006764,(int)TimeStampTool.Get(), "fa577ce340859f9fe",);
+            var rs = DwzTool.Create("", "http://www.baidu.com");
+            Console.WriteLine(Json.Object2String(rs));
+            //PictureScener.GetInfo(1107006764,(int)TimeStampTool.Get(), "",);
 
-            //if (GPSConverter.DeviceGPSToBaiduGPS("iAe652kYOgleRHUYQkW1E8MIHEptnMb5", 120.379235583333, 36.19172925, out double x, out double y))
+            //if (GPSConverter.DeviceGPSToBaiduGPS("", 120.379235583333, 36.19172925, out double x, out double y))
             //{
             //    Console.WriteLine($"120.379235583333 - 36.19172925");
             //    Console.WriteLine($"{x} - {y}");
             //}
 
-          
-            //GPSInfoWebModel model = GPSInfoTool.GetInfo("iAe652kYOgleRHUYQkW1E8MIHEptnMb5", 40.039669, 252.129464);
+
+            //GPSInfoWebModel model = GPSInfoTool.GetInfo("", 40.039669, 252.129464);
             //if (model != null)
             //{
             //    GPSInfoModel info = model.ToGPSInfoModel();

+ 4 - 0
Azylee.Utils/Tests/Test.YeahWeb/Test.YeahWeb.csproj

@@ -52,6 +52,10 @@
       <Project>{88dc61fa-95f0-41b7-9d7d-ab0f3cbd169c}</Project>
       <Name>Azylee.Core</Name>
     </ProjectReference>
+    <ProjectReference Include="..\..\Azylee.Jsons\Azylee.Jsons.csproj">
+      <Project>{DE3AB999-96D3-4A53-A9F2-7409138D0333}</Project>
+      <Name>Azylee.Jsons</Name>
+    </ProjectReference>
     <ProjectReference Include="..\..\Azylee.YeahWeb\Azylee.YeahWeb.csproj">
       <Project>{ccf7a654-b442-4db1-bb3b-0f8014c3237f}</Project>
       <Name>Azylee.YeahWeb</Name>