找過幾家國有企業短信sp供應商,效果比我想象的要差不少,因而直接在網絡上找提供相似服務的短信供應商。發現有不少這樣的民營sp短信供應商的服務都是經過網銀或者支付寶進行購買。這又讓我擔憂是騙錢的。說實在的挺苦惱的,甚至有朋友建議直接買個幾百元的低端多普達,在windows mobile 內寫一個自動發送短信的功能充當短信貓。後來苦苦尋覓中我發現了 悠逸企業短信平臺(申明:無任何廣告嫌疑!)能夠購買一百元1000條手機短信並且註冊後能夠先試用10條短信。將10條試用完後,我用信用卡經過其網站購買了100元短信。心想若是被騙了,這樣損失也不會很大。詳細步驟以下:ui
1
public
static
bool
SendMobileMsg(
string
msgContent, List
<
string
>
destListPhones)
2
{
3
try
4
{
5
bool
result
=
false
;
6
string
strPhones
=
string
.Join(
"
;
"
, destListPhones.ToArray());
7
strPhones
+=
"
;
"
;
8
var encoding
=
System.Text.Encoding.GetEncoding(
"
GB2312
"
);
9
10
string
postData
=
string
.Format(
"
uid=用戶名&pwd=密碼&mobile={0};&msg={1}&dtime=
"
, strPhones, msgContent);
11
12
byte
[] data
=
encoding.GetBytes(postData);
13
14
//
定義 WebRequest
15
HttpWebRequest myRequest
=
16
(HttpWebRequest)WebRequest.Create(
"
http://www.smsadmin.cn/smsmarketing/wwwroot/api/post_send/
"
);
17
18
myRequest.Method
=
"
POST
"
;
19
myRequest.ContentType
=
"
application/x-www-form-urlencoded
"
;
20
myRequest.ContentLength
=
data.Length;
21
22
Stream newStream
=
myRequest.GetRequestStream();
23
24
//
發送數據
25
newStream.Write(data,
0
, data.Length);
26
newStream.Close();
27
28
//
獲得 Response
29
HttpWebResponse myResponse
=
(HttpWebResponse)myRequest.GetResponse();
30
StreamReader reader
=
new
StreamReader(myResponse.GetResponseStream(), Encoding.Default);
31
string
content
=
reader.ReadToEnd();
32
33
if
(content.Substring(
0
,
1
)
==
"
0
"
)
34
result
=
true
;
35
else
36
{
37
if
(content.Substring(
0
,
1
)
==
"
2
"
)
//
餘額不足
38
{
39
//
"手機短信餘額不足";
40
//
TODO
41
}
42
else
43
{
44
//短信發送失敗的
其餘緣由,請參看官方API
45
}
46
result
=
false
;
47
}
48
49
return
result;
50
}
51
catch
52
{
53
return
false
;
54
}
55
56
}