-
Notifications
You must be signed in to change notification settings - Fork 0
/
CsharpSmsApiSample.cs
64 lines (57 loc) · 2.09 KB
/
CsharpSmsApiSample.cs
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
62
63
64
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
/*
* 说明:
* 以下代码展示的是非sdk下的调用,只是为了方便用户测试而提供的样例代码,用户也可自行编写。
* 正式环境建议使用sdk进行调用以提高效率,sdk中包含了使用样例
*/
namespace ShomopSdkTest
{
class Program
{
static void Main(string[] args)
{
string json = ("{" +
" 'apikey':'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'," + // 修改为您的apikey
" 'submits':[{" +
" 'mobile':'132xxxxxxxx'," + // 修改为您要发送的手机号
" 'message':'【亿佰云通讯】您的验证码是:1234'" + // 修改为您要发送的内容,内容必须和某个模板匹配
" }]" +
"}"
).Replace('\'', '"');
Console.WriteLine(PostCURL("https://xxxxxxxx/api/sms/batchSubmit", json));
}
public static string PostCURL(string url, string postData)
{
byte[] dataArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/json";
request.ContentLength = dataArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(dataArray, 0, dataArray.Length);
dataStream.Close();
StreamReader reader = null;
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
String res = reader.ReadToEnd();
return res;
}
catch (SystemException e)
{
return (e.Message + e.ToString());
}
finally
{
reader.Close();
}
}
}
}