Esempio n. 1
0
        public void SmsBatchPublishWithDiffMessage()
        {
            SmsPublishMessage smsPublishMessage1 = new SmsPublishMessage()
            {
                MessageIncludeSignFlag = false,
                // 短信签名,需要在消息通知服务的自助页面申请签名,申请办理时间约2天
                SignId   = "3fe9fae14729495990cf1a3218fe2aca",
                Endpoint = "86136*****87",
                Message  = "你好,您的验证码是:12345679,请查收"
            };

            SmsPublishMessage smsPublishMessage2 = new SmsPublishMessage()
            {
                // MessageIncludeSignFlag默认为false,SignId必填,
                // 为true时,可以不传SignId, 但是内容中必须包含签名,如【华为云】您的验证码是:1234,请查收。签名以【】括起来放在内容头部或者尾部
                MessageIncludeSignFlag = true,
                // 短信签名,需要在消息通知服务的自助页面申请签名,申请办理时间约2天
                Endpoint = "86186****875",
                Message  = "【华为云华南测试】你好,您的验证码是:1234567,请查收"
            };

            List <SmsPublishMessage> smsMessages = new List <SmsPublishMessage>
            {
                smsPublishMessage1,
                smsPublishMessage2
            };
            SmsBatchPublishWithDiffMessageRequest request = new SmsBatchPublishWithDiffMessageRequest()
            {
                SmsMessages = smsMessages
            };

            try
            {
                // 发送请求并返回响应
                SmsBatchPublishWithDiffMessageResponse response = smnClient.SendRequest(request);
                if (response.IsSuccess())
                {
                    List <SmsBatchPublishWithDiffMessageResult> results = response.Result;
                    foreach (SmsBatchPublishWithDiffMessageResult result in results)
                    {
                        Console.WriteLine("messageId={0}, endpoint={1}, code={2}, message={3}",
                                          result.MessageId, result.Endpoint, result.Code, result.Message);
                    }
                }
                else
                {
                    Console.WriteLine("code={0}, message={1}, statusCode={2}",
                                      response.ErrCode, response.ErrMessage, response.StatusCode);
                }
                Console.ReadLine();
            }
            catch (Exception e)
            {
                // 处理异常
                Console.WriteLine("{0}", e.Message);
                Console.ReadLine();
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 根据内容批量发送通知类短信
        /// </summary>
        public void SmsBatchPublishWithDiffMessage()
        {
            SmsPublishMessage smsPublishMessage1 = new SmsPublishMessage()
            {
                MessageIncludeSignFlag = false,
                // 短信签名,需要在消息通知服务的自助页面申请签名,申请办理时间约2天
                SignId   = "6be340e91e5241e4b5d85837e6709104",
                Endpoint = "86136****587",
                Message  = "你好,您的验证码是:12345672,请查收",
                //// 可选字段,扩展码,短信状态通知时会返回
                //ExtendCode = "extendCodeTest3",
                //// 可选字段,短信发送方号码的扩展字段,仅限可自定义扩展的签名使用
                //ExtendSrcId = "123"
            };

            SmsPublishMessage smsPublishMessage2 = new SmsPublishMessage()
            {
                // MessageIncludeSignFlag默认为false,SignId必填,
                // 为true时,可以不传SignId, 但是内容中必须包含签名,如【华为云】您的验证码是:1234,请查收。签名以【】括起来放在内容头部或者尾部
                MessageIncludeSignFlag = true,
                // 短信签名,需要在消息通知服务的自助页面申请签名,申请办理时间约2天
                Endpoint = "86136******587",
                Message  = "【华为企业云】你好,您的验证码是:12345671,请查收"
            };

            List <SmsPublishMessage> smsMessages = new List <SmsPublishMessage>
            {
                smsPublishMessage1,
                smsPublishMessage2
            };
            SmsBatchPublishWithDiffMessageRequest request = new SmsBatchPublishWithDiffMessageRequest()
            {
                SmsMessages = smsMessages
            };

            try
            {
                // 发送请求并返回响应
                SmsBatchPublishWithDiffMessageResponse response = smnClient.SendRequest(request);
                if (response.IsSuccess())
                {
                    List <SmsBatchPublishWithDiffMessageResult> results = response.Result;
                    foreach (SmsBatchPublishWithDiffMessageResult result in results)
                    {
                        Console.WriteLine("messageId={0}, endpoint={1}, code={2}, message={3}",
                                          result.MessageId, result.Endpoint, result.Code, result.Message);
                    }
                }
                else
                {
                    Console.WriteLine("code={0}, message={1}, statusCode={2}",
                                      response.ErrCode, response.ErrMessage, response.StatusCode);
                }
                Console.ReadLine();
            }
            catch (Exception e)
            {
                // 处理异常
                Console.WriteLine("{0}", e.Message);
                Console.ReadLine();
            }
        }