互亿无线 · 文档中心

短信营销 - 代码示例


C#对接短信营销接口DEMO示例
本文为您提供了C#语言版本的短信营销接口对接DEMO示例

短信营销接口文档 点击下载

短信营销接口接入指南 点击访问

    string[] strArray = PhoneNO.Split(','); //字符串转数组
    string uuid = System.Guid.NewGuid().ToString("N");
    DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));//北京所在东八区
    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"));//转化为小写的16进制
    }
    
    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
    {
        //访问失败
    }

现在注册,即享新用户礼包!

在线咨询
电话咨询

服务热线:

4008 808 898

服务热线(工作时间):

4008 808 898

业务咨询(非工作时间):

售后咨询(非工作时间):

验证码已发送到您的手机,请查收!

输入验证码后,点击“开通体验账户”按钮可立即开通体验账户。

收不到短信验证码?
互亿无线不提供接码服务,接码用户请勿点击开通按钮。
×