aliyun / aliyun-openapi-net-sdk

Alibaba Cloud SDK for .NET
https://www.nuget.org/profiles/aliyun-openapi-sdk
Other
542 stars 625 forks source link

邮件推送获取无效地址信息接口调用失败 #382

Closed mib23 closed 4 years ago

mib23 commented 4 years ago

代码如下:

public static void GetInvalidMailList(DateTime startDate, DateTime endDate)
{
    IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", AliyunAccessKeyID, AliyunAccessKeySecret);
    IAcsClient client = new DefaultAcsClient(profile);
    var request = new QueryInvalidAddressRequest
    {
        StartTime = startDate.ToString("yyyy-MM-dd"),
        EndTime = endDate.ToString("yyyy-MM-dd"),
        Version = "2015-11-23",
    };
    try
    {                
        var httpResponse = client.GetAcsResponse(request);
    }
    catch (Exception ex)
    {
        Logger.Default.Error("无效邮件查询异常, Exception:", ex);
    }
}

提示:输入字符串的格式不正确。

如果去掉代码中的“Version = "2015-11-23",”,报:ServiceUnavailable。

但是我在 OpenAPI Explorer 中调试又是可以的,搞不懂了。 https://api.aliyun.com/?spm=a2c4g.11186623.2.9.6ded12fdCr7CAw#/?product=dm&version=2015-11-23&api=QueryInvalidAddress&params={%22RegionId%22:%22default%22,%22StartTime%22:%222020-08-25%22,%22EndTime%22:%222020-08-31%22}&tab=DEBUG&lang=CSHARP

liaoyustudent commented 4 years ago

你好,可以更新一下aliyun-net-sdk-dm 和 aliyun-net-sdk-core 的版本,version可以不填,会有默认的。

mib23 commented 4 years ago

无论是 1.5.8 https://github.com/aliyun/aliyun-openapi-net-sdk/tree/release_version_1.5.8 还是 master https://github.com/aliyun/aliyun-openapi-net-sdk/tree/master 下最新的代码, 都试过了,一样的问题。

liaoyustudent commented 4 years ago

你好,NUGET上的DM包似乎不是官方的,可能是被个人占用了。你可以从github上下载DM的代码本地引用,或者用Core的通用请求方式,给你提供下代码试一下。

IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", Environment.GetEnvironmentVariable("ACCESS_KEY_ID"), Environment.GetEnvironmentVariable("ACCESS_KEY_SECRET"));

            DefaultAcsClient client = new DefaultAcsClient(profile);

            var request = new CommonRequest();
            request.Method = Aliyun.Acs.Core.Http.MethodType.GET;
            request.Product = "Dm";
            request.Action = "QueryInvalidAddress";
            request.Version = "2015-11-23";
            request.AddQueryParameters("StartTime", "2020-09-02");
            request.AddQueryParameters("EndTime", "2020-09-03");

            var res = client.GetCommonResponse(request);
mib23 commented 4 years ago

我这边下载代码调试了,主要有2个问题。 image

问题1:API返回的结果中 NextStart 是 string, QueryInvalidAddressResponse.cs 58行确是 int?

public int? NextStart
{
    get
    {
        return nextStart;
    }
    set 
    {
        nextStart = value;
    }
}

问题2:API返回的结果中 data 是小写, QueryInvalidAddressResponseUnmarshaller.cs 39行开始,“Data”是大写,导致转换失败

List<QueryInvalidAddressResponse.QueryInvalidAddress_MailDetail> queryInvalidAddressResponse_data = new List<QueryInvalidAddressResponse.QueryInvalidAddress_MailDetail>();
for (int i = 0; i < context.Length("QueryInvalidAddress.Data.Length"); i++) {
    QueryInvalidAddressResponse.QueryInvalidAddress_MailDetail mailDetail = new QueryInvalidAddressResponse.QueryInvalidAddress_MailDetail();
    mailDetail.LastUpdateTime = context.StringValue("QueryInvalidAddress.Data["+ i +"].LastUpdateTime");
    mailDetail.UtcLastUpdateTime = context.LongValue("QueryInvalidAddress.Data["+ i +"].UtcLastUpdateTime");
    mailDetail.ToAddress = context.StringValue("QueryInvalidAddress.Data["+ i +"].ToAddress");

    queryInvalidAddressResponse_data.Add(mailDetail);
}
liaoyustudent commented 4 years ago

您好,SDK是根据产品方的配置自动生成的,如果解析或者字段定义上有问题。建议您可以提一个工单,会有专门的人帮您解决问题。

mib23 commented 4 years ago

好的,谢谢~