开发者社区> 问答> 正文

阿里云短信C#最新sdk报The XML you provided did not validate against our published schema, cause by "DirectSMS" Element.

参考官方例子
SDK是1.3.8,是昨天才发布的
但却报The XML you provided did not validate against our published schema, cause by "DirectSMS" Element.
代码如下:

        public static bool Send(AliyunReqParams model)
        {
            bool result = true;

            //初始化Client
            IMNS client = new MNSClient(model.AccessKeyId, model.SecretAccessKey, model.EndPoint);
            //获取主题引用
            Topic topic = client.GetNativeTopic(model.TopicName);
            //生成SMS消息属性
            MessageAttributes messageAttributes = new MessageAttributes();
            BatchSmsAttributes batchSmsAttributes = new BatchSmsAttributes();
            //SMSSignName
            batchSmsAttributes.FreeSignName = model.FreeSignName;
            //SMSTemplateCode
            batchSmsAttributes.TemplateCode = model.TemplateCode;
            //(如果短信模板中定义了参数)设置短信模板中的参数,发送短信时,会进行替换
            Dictionary<string, string> param = new Dictionary<string, string>();
            if (!string.IsNullOrEmpty(model.SmsParam))
            {
                param = JsonConvert.DeserializeObject<Dictionary<string, string>>(model.SmsParam);
            }
            //设置短信接收者手机号码
            batchSmsAttributes.AddReceiver(model.RecNum, param);
            messageAttributes.BatchSmsAttributes = batchSmsAttributes;
            PublishMessageRequest request = new PublishMessageRequest();
            request.MessageAttributes = messageAttributes;
            //设置SMS消息体(必须)
            //注:目前暂时不支持消息内容为空,需要指定消息内容,不为空即可。
            request.MessageBody = "smsmessage";
            try
            {
                //发布SMS消息
                PublishMessageResponse resp = topic.PublishMessage(request);
            }
            catch (Exception ex)
            {
                LogHerlper.Log.WriteError("发送短信错误",ex);
                result = false;
            }

            return result;
        }

展开
收起
云是啥 2017-05-16 10:27:25 3693 0
1 条回答
写回答
取消 提交回答
  • 换成1.3.7SDK,问题解决

    2019-07-17 21:10:38
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
阿里云云原生 Serverless 技术实践营 PPT 演讲 立即下载
阿里云产品十月刊 立即下载
基于阿里云构建博学谷平台实时湖仓 立即下载