[研究][WinForm] HiNet 手機 SMS 簡訊發送測試
2024-11-29SnsComServer_v3.4.dll 是中華電信提供的簡訊發送元件,其最新版本為 3.4。
若遇到處理器架構不相符的問題,建議將參考的 DLL 版本降級至 3.3 以解決該問題。
********************************************************************************
HiNET 簡訊程式庫網址
SnsComServer_v3.4.dll 好像是以前寫信要到的?
********************************************************************************WebForm 專案
先把 SnsComServer_v3.3.dll 或 SnsComServer_v3.4.dll 加入參考。
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8" />
</startup>
<appSettings>
<add key="SMSIP" value="IP位置" />
<add key="SMSPort" value="埠號" />
<add key="SMSAccount" value="帳號" />
<add key="SMSPassword" value="密碼" />
</appSettings>
</configuration>
|
Form1.cs
using System;
using System.Configuration;
using System.Security.Cryptography;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string phoneNumber = "手機號碼10碼";
try
{
RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider();
string smsip = (string)ConfigurationManager.AppSettings["SMSIP"];
string smsport = (string)ConfigurationManager.AppSettings["SMSPort"];
string account = (string)ConfigurationManager.AppSettings["SMSAccount"];
string passwd = (string)ConfigurationManager.AppSettings["SMSPassword"];
CHT.SNSCOMSERVER.SnsComObject3 m_sns = new CHT.SNSCOMSERVER.SnsComObject3();
m_sns.InitRemoteServer(smsip, smsport, account, passwd);
int nResult = m_sns.Login();
if (nResult == 0)//登入成功
{
//傳送手機號碼, 訊息內容
nResult = m_sns.SubmitMessage(null, phoneNumber, "簡訊測試", 1440);
//若發訊成功,則更新至狀態查詢測試的兩個欄位,以便進一步查詢發送結果。
if (nResult == 0)
{
label_Message.Text = "簡訊發送成功。";
}
else
{
label_Message.Text = "簡訊發送失敗。";
}
}
else
{
label_Message.Text = "登入失敗。"; |
(完)
[研究][WinForm] HiNet 手機 SMS 簡訊發送測試
[研究][ASP.NET] HiNet 手機 SMS 簡訊發送測試

沒有留言:
張貼留言