互億無線 · 文檔中心

短信營銷 - 代碼示例


C#對接短信營銷接口DEMO示例
本文為您提供了C#語言版本的短信營銷接口對接DEMO示例

短信營銷接口文檔 點(diǎn)擊下載

短信營銷接口接入指南 點(diǎn)擊訪問

    string[] strArray = PhoneNO.Split(','); //字符串轉(zhuǎn)數(shù)組
    string uuid = System.Guid.NewGuid().ToString("N");
    DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));//北京所在東八區(qū)
    DateTime endTime = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now);

    MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
    byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes("api_id=" + select3[7].Value + "&api_key=" + select3[8].Value + "&request_id=" + uuid + "×tamp=" + Convert.ToInt64((endTime - startTime).TotalSeconds) + ""));
    StringBuilder sBuilder = new StringBuilder();
    for (int i = 0; i < data.Length; i++)
    {
        sBuilder.Append(data[i].ToString("x2"));//轉(zhuǎn)化為小寫的16進(jìn)制
    }
    
    HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(PostUrl);
    myRequest.Method = "POST";
    myRequest.ContentType = "application/json";

    using (var streamWriter = new StreamWriter(myRequest.GetRequestStream()))
    {
        string json = new JavaScriptSerializer().Serialize(new
        {
            api_id = select3[7].Value,
            signature = sBuilder.ToString(),
            timestamp = Convert.ToInt64((endTime - startTime).TotalSeconds),
            request_id = uuid,
            product_id = 1018,
            phone = strArray,
            sign_name = "簽名名稱",
            content = Name
        });

        streamWriter.Write(json);
    }

    var response = (HttpWebResponse)myRequest.GetResponse();

    if (response.StatusCode == HttpStatusCode.OK)
    {
        StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
        string res = reader.ReadToEnd();
    }
    else
    {
        //訪問失敗
    }

現(xiàn)在注冊,即享新用戶禮包!

在線咨詢
電話咨詢

服務(wù)熱線:

4008 808 898

服務(wù)熱線(工作時(shí)間):

4008 808 898

業(yè)務(wù)咨詢(非工作時(shí)間):

售后咨詢(非工作時(shí)間):

驗(yàn)證碼已發(fā)送到您的手機(jī),請查收!

輸入驗(yàn)證碼后,點(diǎn)擊“開通體驗(yàn)賬戶”按鈕可立即開通體驗(yàn)賬戶。

收不到短信驗(yàn)證碼?
互億無線不提供接碼服務(wù),接碼用戶請勿點(diǎn)擊開通按鈕。
×