zoukankan      html  css  js  c++  java
  • C# 106 短信发送

    最近遇到短信验证码发送老是失败,咨询客服,经过反复折腾,是我这边的源码有问题(同事写的,同事写的,同事写的),他重新发了我一份源码,然后成功了!代码如下

    using System;
    using System.Text;
    using System.Net;
    using System.IO;
    
    namespace Commons
    {
        public class Sms106
        {
            private static string _user = "";
            private static string _pwd = "";
    
            public static string sendSms(string mobile, string content)
            {
                //发送验证码
                string postStrTpl = "account={0}&password={1}&mobile={2}&content={3}";
    
                UTF8Encoding encoding = new UTF8Encoding();
                byte[] postData = encoding.GetBytes(string.Format(postStrTpl, _user, _pwd, mobile, content));
    
                HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://sms.106jiekou.com/utf8/openapi.aspx");
                myRequest.Method = "POST";
                myRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                myRequest.ContentLength = postData.Length;
    
                Stream newStream = myRequest.GetRequestStream();
                // Send the data.
                newStream.Write(postData, 0, postData.Length);
                newStream.Flush();
                newStream.Close();
                HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
                if (myResponse.StatusCode == HttpStatusCode.OK)
                {
                    StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
                    string strResult = reader.ReadToEnd();  //100为成功
                    //反序列化upfileMmsMsg.Text
                    //实现自己的逻辑
    
                    return strResult;
                }
    
                return "";
            }
        }
    }

    官网地址:http://www.106jiekou.com/

    个人觉得他们的客服超级给力,值得安利!

  • 相关阅读:
    angularjs基础——控制器
    angularjs基础——变量绑定
    mysql 小数处理
    centos无法联网解决方法
    mysql 按 in 顺序排序
    html5 file 自定义文件过滤
    淘宝、天猫装修工具
    MapGis如何实现WebGIS分布式大数据存储的
    CentOS
    PHP与Python哪个做网站产品好?
  • 原文地址:https://www.cnblogs.com/sunff/p/12970466.html
Copyright © 2011-2022 走看看