首页

C#短信发送示例源码

c#

2020-9-10

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace SendSMS
{
    public partial class Form1 : Form
    {

        private string url = "http://utf8.sms.webchinese.cn/?";
        private string strUid = "Uid=";
        private string strKey = "&key=*******************";///"&key=*******************"; //这里*代表秘钥,由于从长有点麻烦,就不在窗口上输入了
        private string strMob = "&smsMob=";
        private string strContent = "&smsText=";

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (txtUerName.Text.ToString().Trim() != "" && txtAttnNum.Text.ToString().Trim() != "" &&txtContent.Text.ToString() != null) 
            {
                url = url   strUid   txtUerName.Text   strKey   strMob   txtAttnNum.Text   strContent   txtContent.Text;
                string Result = GetHtmlFromUrl(url);

                MessageBox.Show(Result);
             }
         }

        public string GetHtmlFromUrl(string url)
        {
            string strRet = null;
            if (url == null || url.Trim().ToString() == "")
            {
                return strRet;
            }
            string targeturl = url.Trim().ToString();
            try
            {
                HttpWebRequest hr = (HttpWebRequest)WebRequest.Create(targeturl);
                hr.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
                hr.Method = "GET";
                hr.Timeout = 30 * 60 * 1000;
                WebResponse hs = hr.GetResponse();
                Stream sr = hs.GetResponseStream();
                StreamReader ser = new StreamReader(sr, Encoding.Default);
                strRet = ser.ReadToEnd();
            }
            catch (Exception ex)
            {
                strRet = null;
            }
            return strRet;
         }
    }
}

资源下载此资源下载价格为3D币(VIP免费),请先
资源文件列表
SendSMS/SendSMS/App.config , 187
SendSMS/SendSMS/bin/Debug/SendSMS.exe , 11264
SendSMS/SendSMS/bin/Debug/SendSMS.exe.config , 187
SendSMS/SendSMS/bin/Debug/SendSMS.pdb , 22016
SendSMS/SendSMS/bin/Debug/SendSMS.vshost.exe , 23168
SendSMS/SendSMS/bin/Debug/SendSMS.vshost.exe.config , 187
SendSMS/SendSMS/bin/Debug/SendSMS.vshost.exe.manifest , 490
SendSMS/SendSMS/Form1.cs , 2213
SendSMS/SendSMS/Form1.Designer.cs , 5888
SendSMS/SendSMS/Form1.resx , 5817
SendSMS/SendSMS/obj/Debug/DesignTimeResolveAssemblyReferences.cache , 865
SendSMS/SendSMS/obj/Debug/DesignTimeResolveAssemblyReferencesInput.cache , 6987
SendSMS/SendSMS/obj/Debug/SendSMS.csproj.FileListAbsolute.txt , 624
SendSMS/SendSMS/obj/Debug/SendSMS.csproj.GenerateResource.Cache , 977
SendSMS/SendSMS/obj/Debug/SendSMS.exe , 11264
SendSMS/SendSMS/obj/Debug/SendSMS.Form1.resources , 180
SendSMS/SendSMS/obj/Debug/SendSMS.pdb , 22016
SendSMS/SendSMS/obj/Debug/SendSMS.Properties.Resources.resources , 180
SendSMS/SendSMS/obj/Debug/TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs , 0
SendSMS/SendSMS/obj/Debug/TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs , 0
SendSMS/SendSMS/obj/Debug/TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs , 0
SendSMS/SendSMS/Program.cs , 519
SendSMS/SendSMS/Properties/AssemblyInfo.cs , 1338
SendSMS/SendSMS/Properties/Resources.Designer.cs , 2866
SendSMS/SendSMS/Properties/Resources.resx , 5612
SendSMS/SendSMS/Properties/Settings.Designer.cs , 1094
SendSMS/SendSMS/Properties/Settings.settings , 249
SendSMS/SendSMS/SendSMS.csproj , 3794
SendSMS/SendSMS.sln , 990
SendSMS/SendSMS.v12.suo , 13312
没有账号? 忘记密码?

社交账号快速登录