[研究][ASP.NET] HiNet 手機 SMS 簡訊發送測試
2019-11-20
2019-12-04 更新
2024-11-20測試成功 (VS2019 + Win2019)
********************************************************************************
2024-11-20補
SnsComServer_v3.4.dll 的最新版是幾版 ?
ChatGPT 說:
根據目前可查詢的資料,SnsComServer_v3.4.dll 是中華電信提供的簡訊發送元件,其最新版本為 3.4。
在 2021 年 7 月,有開發者在使用該元件時,遇到處理器架構不相符的問題,建議將參考的 DLL 版本降級至 3.3 以解決該問題。
然而,未找到有關該元件更新至 3.4 以上版本的資訊。
建議您直接聯繫中華電信或相關服務提供商,以獲取該元件的最新版本資訊。
********************************************************************************
HiNET 簡訊程式庫網址
SnsComServer_v3.4.dll 好像是以前寫信要到的?
********************************************************************************
WebForm 專案
先把 SnsComServer_v3.4.dll 加入參考。


Web.Config
<!--
如需如何設定 ASP.NET 應用程式的詳細資訊,請前往
https://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<appsettings>
<add key="SMSIP" value="簡訊主機IP1, 簡訊主機IP2," />
<add key="SMSPort" value="8001,8001" />
<add key="SMSAccount" value="帳號" />
<add key="SMSPassword" value="密碼" />
</appsettings>
</configuration>
|
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="SMSTest.Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="送出簡訊" /><br />
<asp:Label ID="Label_Message" runat="server"></asp:Label>
</div>
</form>
</body>
</html>
|
Default.aspx.cs
using System;
using System.Configuration;
using System.Security.Cryptography;
namespace SMSTest
{
public partial class Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
string phoneNumber = "0931xxxyyy"; // 手機號碼
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 = "登入失敗。";
}
m_sns.Logout();
}
catch (Exception ex)
{
if (ex != null)
{
Label_Message.Text = ex.Message.ToString();
}
else
{
Label_Message.Text = "不明例外。";
}
}
}
}
}
|
上述在 Visual Studio 2019 環境可正常執行,但 Deploy 到網站後會出錯。IIS 要增加設定才能解決。
(下圖) Click 圖片可看 100% 尺寸。
********************************************************************************
NCC督促電信事業精進商業簡訊風險管控機制,公私協力從源頭堵詐
2024-11-13
所有商業簡訊發送前,內容均須通過檢查,如帶有URL、短網址或電話號碼,經查與企業登錄資料不符或未登錄者,則不予發送。
https://www.ncc.gov.tw/chinese/news_detail.aspx?site_content_sn=8&cate=0&keyword=&is_history=0&pages=0&sn_f=50852
********************************************************************************
編譯出錯
已開始重建...
1>------ 已開始全部重建: 專案: PMSWeb, 組態: Debug Any CPU ------
1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(2203,5): warning MSB3270: 所建置之專案的處理器架構 "MSIL" 與參考 "SnsComServer_v3.4" 的處理器架構 "x86" 不相符。這可能會導致執行階段失敗。請考慮透過組態管理員變更專案的目標處理器架構,使專案與參考之間的處理器架構相對應,或者使用符合專案目標處理器架構之處理器架構的參考相依性。
========== 全部重建: 2 成功、0 失敗、 0 略過 ==========
[研究][ASP.NET]所建置之專案的處理器架構 "MSIL" 與參考 "SnsComServer_v3.4" 的處理器架構 "x86" 不相符。
********************************************************************************
(完)
[研究][WinForm] HiNet 手機 SMS 簡訊發送測試
[研究][ASP.NET] HiNet 手機 SMS 簡訊發送測試