网易云信短信接口发送代码

时间:2016/9/26 15:22:00来源:互联网 作者:flyso 点击: 2439 次

public class YunSms

    {

        public static bool Send(string mobile, string content = "", int templateid = 8467)

        {

            bool r = false;

            string AppKey = "xxx";

            string AppSecret = "xxx";

            string t1 = Dates.timeStamp().ToString();

            string Nonce = Fun.GetShortNo;

            string cs = Security.Sha1(AppSecret + Nonce + t1);

            Hashtable ht = new Hashtable();

            ht["AppKey"] = AppKey;

            ht["CurTime"] = t1;

            ht["CheckSum"] = cs;

            ht["Nonce"] = Nonce;

            string smsret = "";

            if (string.IsNullOrEmpty(content))

            {

                smsret = Remote.GetPostResult("https://api.netease.im/sms/sendcode.action", "mobile=" + mobile, ht);


            }

            else

            {

                if (content.IndexOf("\"") == -1)

                {

                    content = "\"" + content + "\"";

                }

                smsret = Remote.GetPostResult("https://api.netease.im/sms/sendtemplate.action", 

"templateid=" + templateid + "&mobiles=[\"" + mobile + "\"]&params=[" + content + "]", ht);

            }

            //Log.Write(smsret, "smsret");

            YunSmsRet sr = Json.ParseFromJson<YunSmsRet>(smsret);

            //Log.Write(sr.code, "sr.code");

            if (sr.code == 200)

            {

                r = true;

            }

            return r;

        }


        public static bool verifycode(string mobile, string code)

        {

            bool r = false;

            string AppKey = "xxx";

            string AppSecret = "xxx";

            string t1 = Dates.timeStamp().ToString();

            string Nonce = Fun.GetShortNo;

            string cs = Security.Sha1(AppSecret + Nonce + t1);

            Hashtable ht = new Hashtable();

            ht["AppKey"] = AppKey;

            ht["CurTime"] = t1;

            ht["CheckSum"] = cs;

            ht["Nonce"] = Nonce;

            string smsret = Remote.GetPostResult("https://api.netease.im/sms/verifycode.action", 

"mobile=" + mobile + "&code=" + code, ht);

            //Log.Write(smsret, "smsret");

            YunSmsRet sr = Json.ParseFromJson<YunSmsRet>(smsret);

            //Log.Write(sr.code, "sr.code");

            if (sr.code == 200)

            {

                r = true;

            }

            return r;

        }


    }


Copyright © 2005 - 2016 flyso.cn. 飞搜 版权所有 鄂ICP备11002783号-3