亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C#怎么實(shí)現(xiàn)手機(jī)短信發(fā)送功能

 更新時(shí)間:2015年12月03日 10:39:16   作者:J灬葉小超  
為了個(gè)人信息的安全,很多網(wǎng)站都有短信發(fā)送的功能,究竟是怎么實(shí)現(xiàn)的呢?對(duì)于個(gè)人站長(zhǎng)來(lái)說(shuō)的話(huà),通過(guò)使用sms短信通知api接口相對(duì)比較簡(jiǎn)單,下面小編給大家介紹具體實(shí)現(xiàn)過(guò)程,對(duì)c#怎么實(shí)現(xiàn)手機(jī)短信發(fā)送功能感興趣的朋友一起學(xué)習(xí)吧

為了個(gè)人信息的安全,很多網(wǎng)站都有短信發(fā)送的功能,究竟是怎么實(shí)現(xiàn)的呢?對(duì)于個(gè)人站長(zhǎng)來(lái)說(shuō)的話(huà),通過(guò)使用SMS短信通API接口相對(duì)比較劃算和簡(jiǎn)單。那怎么實(shí)現(xiàn)呢,步驟如下:

1. 從網(wǎng)上(http://sms.webchinese.cn/)申請(qǐng)賬號(hào),記住用戶(hù)名,密碼會(huì)發(fā)到手機(jī)上,這僅是登陸密碼。注冊(cè)后會(huì)送5條短信、和3條彩信的發(fā)送量。

2.查看SMS短信通API下行接口(http://sms.webchinese.cn/api.shtml),然后獲取秘鑰,其實(shí)就是加密后的登錄密碼。開(kāi)始敲代碼,相關(guān)代碼如下:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
namespace Y_PostSms
{
  public class YMethod
  {
    private string THE_UID = ""; //用戶(hù)名
    private string THE_KEY = ""; //接口秘鑰
    /// <summary>返回UTF-8編碼發(fā)送接口地址</summary>
    /// <param name="receivePhoneNumber">目的手機(jī)號(hào)碼(多個(gè)手機(jī)號(hào)請(qǐng)用半角逗號(hào)隔開(kāi))</param>
    /// <param name="receiveSms">短信內(nèi)容,最多支持400個(gè)字,普通短信70個(gè)字/條,長(zhǎng)短信64個(gè)字/條計(jì)費(fèi)</param>
    /// <returns></returns>
    public string GetPostUrl(string smsMob, string smsText)
    {
      string postUrl = "http://utf8.sms.webchinese.cn/?Uid=" + THE_UID + "&key=" + THE_KEY + "&smsMob=" + smsMob + "&smsText=" + smsText;
      return postUrl;
    }
    /// <summary> 發(fā)送短信,得到返回值</summary>
    public string PostSmsInfo(string url)
    {
      //調(diào)用時(shí)只需要把拼成的URL傳給該函數(shù)即可。判斷返回值即可
      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;
    }
    /// <summary>確認(rèn)返回信息 </summary>
    public string GetResult(string strRet)
    {
      int result = 0;
      try
      {
        result = int.Parse(strRet);
        switch (result)
        {
          case -1:
            strRet = "沒(méi)有該用戶(hù)賬戶(hù)";
            break;
          case -2:
            strRet = "接口密鑰不正確,不是賬戶(hù)登陸密碼";
            break;
          case -21:
            strRet = "MD5接口密鑰加密不正確";
            break;
          case -3:
            strRet = "短信數(shù)量不足";
            break;
          case -11:
            strRet = "該用戶(hù)被禁用";
            break;
          case -14:
            strRet = "短信內(nèi)容出現(xiàn)非法字符";
            break;
          case -4:
            strRet = "手機(jī)號(hào)格式不正確";
            break;
          case -41:
            strRet = "手機(jī)號(hào)碼為空";
            break;
          case -42:
            strRet = "短信內(nèi)容為空";
            break;
          case -51:
            strRet = "短信簽名格式不正確,接口簽名格式為:【簽名內(nèi)容】";
            break;
          case -6:
            strRet = "IP限制";
            break;
          default:
            strRet = "發(fā)送短信數(shù)量:" + result;
            break;
        }
      }
      catch (Exception ex)
      {
        strRet = ex.Message;
      }
      return strRet;
    }
  }
} 

3. 找在線(xiàn)客服開(kāi)通發(fā)送權(quán)限,填寫(xiě)好簽名,效果圖如下:

通過(guò)以上圖文并茂的方式給大家介紹了C#怎么實(shí)現(xiàn)手機(jī)短信發(fā)送功能,希望大家喜歡。

相關(guān)文章

最新評(píng)論