zhao_js
2023-11-28 4d2bb20eecf42af8c0b29fda38b02df0f6c9895d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using Newtonsoft.Json;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Text;
using YouZanSDKStandard.Api.Response;
 
namespace YouZanSDKStandard.Api
{
    public class YouZanUploadeImg
    {
        /// <summary>
        /// 图片上传有赞
        /// </summary>
        /// <param name="accessToken"></param>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public static UploadImageResponse UploadImage(string accessToken, string filePath)
        {
            var client = new RestClient($"https://open.youzanyun.com/api/youzan.materials.storage.platform.img.upload/3.0.0?access_token={accessToken}");
            client.Timeout = -1;
            var request = new RestRequest(Method.POST);
            request.AddFile("image", filePath);
            IRestResponse response = client.Execute(request);
            if (response.Content != null && response.Content != "")
            {
                UploadImageResponse topRsp = JsonConvert.DeserializeObject<UploadImageResponse>(response.Content);
                return topRsp;
            }
            return null;
        }
    }
}