部分核心代码如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
String number = this .phone.Text; System.Net.WebClient client = new System.Net.WebClient(); //System.Net.Webclient类从特定的URL请求文件 client.Credentials = System.Net.CredentialCache.DefaultCredentials; //获取或设置发送到主机并用于对请求进行身份验证的网 络凭据。 String userName = this .userName.Text; //获取用户名即短信宝帐户 String pass = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile( this .passWord.Text, "MD5" ); //短信宝帐户密码经md5加密 String content = System.Web.HttpUtility.UrlEncode( this .content.Text,System.Text.Encoding.UTF8); //短信发送内容并进行 urlencode编码 byte [] result = client.DownloadData( "http://api.smsbao.com/sms?u=" +userName+ "&p=" +pass+ "&m=" +number+ "&c=" +content);// 向远程网址发送请求并获取返回值保存至字节数组 String sres = Encoding.UTF8.GetString(result); /*将返回结果转换成字符串*/ switch (sres) { case "0" : { MessageBox.Show( "发送成功!" ); break ; } case "30" : { MessageBox.Show( "密码错误!" ); break ; } case "40" : { MessageBox.Show( "账号不存在!" ); break ; } case "41" : { MessageBox.Show( "余额不足!" ); break ; } case "42" : { MessageBox.Show( "帐号过期!" ); break ; } case "43" : { MessageBox.Show( "IP地址限制!" ); break ; } case "50" : { MessageBox.Show( "内容含有敏感词!" ); break ; } case "51" : { MessageBox.Show( "手机号码不正确!" ); break ; } case "-1" : { MessageBox.Show( "手机号码不正确或缺少参数!" ); break ; } default : { MessageBox.Show(sres); break ; } } |