C#实现如何使用短信平台自动通知用户实例
目前市面上的第三方短信服务平台数量十分庞大,并能为企业提供三网合一的短信接口,这些服务商通过整合短信发送服务,简单的打包成为API和SDK接口提供给企业,企业只需要在自己公司的平台上接入这些接口就可以实现,短信平台自动发送的功能,企业接入这些短信平台接口的流程十分简单,方式也不复杂。
使用中昱维信第三方平台接口
平台通过第三方公司提供接口实现短信群发,以下为中昱维信的短信群发示例:
var client = new RestClient("https://vip.veesing.com/smsApi/group【原URL 台湾大带宽服务器http://www.558idc.com/tw.html复制请保留原URL】63;appId=35LC8QJRI2YR&appKey=YKU2JJCN4KD9BEHN&phone=18302999492&content=【中昱维信】您的短信群发功能已开通,请在3个工作日之内至平台进行企业认证!"); //构建post请求 var request = new RestRequest(Method.POST); //设置请求头部参数 request.AddHeader("cache-control", "no-cache"); request.AddHeader("Connection", "keep-alive"); request.AddHeader("Content-Length", "0"); request.AddHeader("Accept-Encoding", "gzip, deflate"); request.AddHeader("Host", "vip.veesing.com"); request.AddHeader("Postman-Token", "77d8b8d3-7fe6-4dee-a157-f42701ee4cbe,04f24c10-e7da-4ca7-9729-e6e727770c9f"); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Accept", "*/*"); request.AddHeader("User-Agent", "PostmanRuntime/7.19.0"); IRestResponse response = client.Execute(request); Console.WriteLine(response); Console.ReadKey();
平台通过第三方公司提供接口实现短信群发,以下为中昱维信的短信验证示例:
var client = new RestClient("https://vip.veesing.com/smsApi/verifyCode?appId=35LC8QJRI2YR&appKey=YKU2JJCN4KD9BEHN&phone=18302999492&templateId=540&variables=1234"); var request = new RestRequest(Method.POST); request.AddHeader("cache-control", "no-cache"); request.AddHeader("Connection", "keep-alive"); request.AddHeader("Content-Length", "0"); request.AddHeader("Accept-Encoding", "gzip, deflate"); request.AddHeader("Host", "vip.veesing.com"); request.AddHeader("Postman-Token", "77d8b8d3-7fe6-4dee-a157-f42701ee4cbe,04f24c10-e7da-4ca7-9729-e6e727770c9f"); request.AddHeader("Cache-Control", "no-cache"); request.AddHeader("Accept", "*/*"); request.AddHeader("User-Agent", "PostmanRuntime/7.19.0");
C#调用第三方平台实现发送验证码
private void button2_Click(object sender, EventArgs e) { if (textBox1.Text == "" || textBox1.Text.Length != 11)//手机号输入框 { MessageBox.Show("请输入正确的手机号码"); } else { //生成一个随机数 四位的 Random random = new Random(); int value = random.Next(1000, 10000);//用rad生成大于等于1000,小于等于9999的随机数; string suijishu = value.ToString(); //转化为字符串; shu = suijishu; var client = new ZhenziSmsClient("https://sms_developer.zhenzikj.com", "你的appId", "你的appSecret"); var parameters = new Dictionary<string, string>(); parameters.Add("message", "尊敬的用户:您的验证码为 " + suijishu); parameters.Add("number", textBox1.Text); //parameters.Add("clientIp", "792.168.2.222"); //parameters.Add("messageId", ""); var result = client.Send(parameters); string v = result.ToString().Substring(8, 1); if (v == "0") { MessageBox.Show("短信发送成功"); timer1.Start(); } else { MessageBox.Show("短信验证码发送失败"); } } }
下面是计时器timer1的代码:
int i = 60; private void timer1_Tick(object sender, EventArgs e) { if (i == 0) { timer1.Stop(); button2.Text = "获取验证码"; button2.Enabled = true; } else { i--; button2.Text = i.ToString (); button2.Enabled = false; } }
登录按钮的具体代码:
public static string shu; if (shu == textBox2.Text)//验证码输入框 { MessageBox.Show("登录成功"); } else { MessageBox.Show("登录失败"); }
到此这篇关于C#实现如何使用短信平台自动通知用户实例的文章就介绍到这了,更多相关C# 短信自动通知用户 内容请搜索海外IDC网以前的文章或继续浏览下面的相关文章希望大家以后多多支持海外IDC网!