2018-05-22

[C#] Nexmo 的服務寄送 SMS C# Sample.


image

最近因為較寄送簡訊服務,比較一下,這一家最快,所以提供一下給大家 C# Source code.

Source Code:

WebClient wc4 = new WebClient(); string targetAddress4 = "https://rest.nexmo.com/sms/json"; wc4.Encoding = Encoding.UTF8; wc4.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded"; NameValueCollection nc4 = new NameValueCollection(); nc4["api_key"] = YOUR_API_KEY; nc4["api_secret"] = YOUR_API_SECRET; nc4["to"] = mobile; //必填 nc4["from"] = "no2studio"; nc4["text"] = YOUR_CONTENT; //如果你要傳送中文,這一個地方必加,不然會出現很多 ? nc4["type"] = "unicode"; byte[] bResult4 = wc4.UploadValues(targetAddress4, nc4); string result = Encoding.Default.GetString(bResult4); Console.Write(result);

其實重點在 記得中文的話要加入 type=unicode ,然後 如果你還沒有付錢記得 要先去 https://dashboard.nexmo.com/test-numbers 這裡加入測試帳號,不然你怎麼寄送都會被 Non White-listed destination - rejected

--

The bug existed in all possible states. Until I ran the code.

如果這篇文章有幫助到您幫我分享一下,讓我有寫下去的動力...