/// <summary> /// 分页返回请求者的所有的订阅列表 /// </summary> public void ListSubscriptions() { // 设置请求对象 ListSubscriptionsRequest request = new ListSubscriptionsRequest { Limit = 10, Offset = 0, }; try { // 发送请求并返回响应 ListSubscriptionsResponse response = smnClient.SendRequest(request); int result = response.SubscriptionCount; Console.WriteLine("{0}", result); Console.ReadLine(); } catch (Exception e) { // 处理异常 Console.WriteLine("{0}", e.Message); } }
/// <summary> /// 消息发布 /// </summary> public void PublishWithMessage() { // 设置请求对象 PublishRequest request = new PublishRequest { TopicUrn = "urn:smn:cn-north-1:cffe4fc4c9a54219b60dbaf7b586e132:create_by_zhangyx_test_csharp", Subject = "hello csharp", Message = "a test messag from csharp sdk" }; try { // 发送请求并返回响应 PublishResponse response = smnClient.SendRequest(request); string result = response.MessageId; Console.WriteLine("{0}", result); Console.ReadLine(); } catch (Exception e) { // 处理异常 Console.WriteLine("{0}", e.Message); } }
/// <summary> /// 创建消息模板 /// </summary> public void CreateMessageTemplate() { // 设置请求对象 CreateMessageTemplateRequest request = new CreateMessageTemplateRequest { MessageTemplateName = "template_create_by_zhangyx_test_csharp", Content = "this year is {year}", Protocol = ProtocolType.SMS, }; try { // 发送请求并返回响应 CreateMessageTemplateResponse response = smnClient.SendRequest(request); string result = response.MessageTemplateId; Console.WriteLine("{0}", result); Console.ReadLine(); } catch (Exception e) { // 处理异常 Console.WriteLine("{0}", e.Message); } }
/// <summary> /// 创建topic /// </summary> public void CreateTopic() { // 设置请求对象 CreateTopicRequest request = new CreateTopicRequest { Name = "create_by_zhangyx_test_csharp3", DisplayName = "testtyc12020016", }; try { // 发送请求并返回响应 CreateTopicResponse response = smnClient.SendRequest(request); string result = response.TopicUrn; Console.WriteLine("{0}", result); Console.ReadLine(); } catch (Exception e) { // 处理异常 Console.WriteLine("{0}", e.Message); } }
/// <summary> /// 发送彩信 /// </summary> public void MmsPublish() { // 生成彩信 图片数据 MmsFrameMessage image = new MmsFrameMessage { FileType = MmsFileType.MMS_IAMGE_JPG, ContentBase64 = FileToBase64("E:/zhangyx/mms/timg.jpg") }; // 生成彩信 音频数据 MmsFrameMessage voice = new MmsFrameMessage { FileType = MmsFileType.MMS_VOICE_MID, ContentBase64 = FileToBase64("E:/zhangyx/mms/town.mid") }; // 生成mms frame数据 MmsFrame mmsFrame = new MmsFrame { Text = "彩信测试", Image = image, Voice = voice }; MmsPublishRequest request = new MmsPublishRequest { Title = "彩信测试1234", Endpoints = new List <string> { "136*****87", "1772*****31" }, SignId = "3e863eac748b417c98795ec3c7f2887c", MmsMessage = new List <MmsFrame> { mmsFrame } }; try { // 发送请求并返回响应 MmsPublishResponse response = smnClient.SendRequest(request); if (response.IsSuccess()) { List <MmsPublishResult> results = response.Result; foreach (MmsPublishResult 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(); } }
/// <summary> /// 发送短信通知验证码 /// </summary> public void SmsPublish() { // 设置请求对象 SmsPublishRequest request = new SmsPublishRequest { // MessageIncludeSignFlag默认为false,SignId必填, // 为true时,可以不传SignId, 但是内容中必须包含签名,如【华为云】您的验证码是:1234,请查收。签名以【】括起来放在内容头部或者尾部 MessageIncludeSignFlag = false, // 短信签名.需要在消息通知服务的自助页面申请签名,申请办理时间约2天 SignId = "6be340e91e5241e4b5d85837e6709104", // 发送手机号码 号码格式 (+)(国家码)(手机号码) Endpoint = "86136*****87", Message = "【华为企业云】您的验证码是:1234567,请查收", //// 可选字段,扩展码,短信状态通知时会返回 //ExtendCode = "extendCodeTest", //// 可选字段,短信发送方号码的扩展字段,仅限可自定义扩展的签名使用 //ExtendSrcId = "123" }; try { // 发送请求并返回响应 SmsPublishResponse response = smnClient.SendRequest(request); string result = response.MessageId; Console.WriteLine("{0}, {1}", result, response.ErrMessage); Console.ReadLine(); } catch (Exception e) { // 处理异常 Console.WriteLine("{0}", e.Message); Console.ReadLine(); } }