AdolphYang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

理论:

yuntongxun.com有8元得免费短信
调用短信接口大量发送短信,对于短信模板进行审核,重要短信模板没有非法信息就可以通过
模板短信--Rest API
短信运营商提供的接口,其实就是http接口,把要发送的手机号\模板短信id通过http协议发送这个接口(发给运营商,运营商去发请求)
API--体验及SDK下载--短信验证码--Demo下载--Rest Server Demo--下载NET--CCPRestSDK.dll

TestRestServer.csProj--Program.cs

protected void Page_Load(object sender, EventArgs e)
{
string ret = null;
CCPRestSDK.CCPRestSDK api = new CCPRestSDK.CCPRestSDK();
bool isInit = api.init("sandboxapp.cloopen.com", "8883");
api.setAccount(主帐号, 主帐号令牌);
api.setAppId(应用ID);
try
{
if (isInit)
{
Dictionary<string, object> retData = api.SendTemplateSMS(短信接收号码, 短信模板id, 内容数据);
ret = getDictionaryData(retData);
}
else
{
ret = "初始化失败";
}
}
catch (Exception exc)
{
ret = exc.Message;
}
finally
{
Response.Write(ret);
}
}

private string getDictionaryData(Dictionary<string, object> data)
{
string ret = null;
foreach (KeyValuePair<string, object> item in data)
{
if (item.Value != null && item.Value.GetType() == typeof(Dictionary<string, object>))
{
ret += item.Key.ToString() + "={";
ret += getDictionaryData((Dictionary<string, object>)item.Value);
ret += "};";
}
else
{
ret += item.Key.ToString() + "=" + (item.Value == null ? "null" : item.Value.ToString()) + ";";
}
}
return ret;
}
}
testRestServer.csProj

 

//ret=statusCode=000000;statusMsg=成功;data={TemplateSMS={dateCreated=20150531193711;smsMessageSid=201505311937105998598;};};

项目任务:
注册时短信获取验证码;
虚拟班级内群发短信活动通知(各位同学,今天{0}点班级举办线上活动,请准备参加)

 

 示例:

 

namespace testRestApi
{
    class Program
    {
        static void Main(string[] args)
        {
            string ret = null;

            CCPRestSDK.CCPRestSDK api = new CCPRestSDK.CCPRestSDK();
            //ip格式如下,不带https://
            bool isInit = api.init("sandboxapp.cloopen.com", "8883");
            api.setAccount("aaf98f894cc66b36014cd0ecba8a05e3", "8a6553e3d8db434a816add4eacba8fd8");
            api.setAppId("aaf98f894cc66b36014cd0ed2d5f05e5");

            try
            {
                if (isInit)
                {
                    Dictionary<string, object> retData = api.SendTemplateSMS("188623011XX","1", new string[] { "8888","2" });
                    ret = getDictionaryData(retData);
                }
                else
                {
                    ret = "初始化失败";
                }
            }
            catch (Exception exc)
            {
                ret = exc.Message;
            }
            finally
            {
                Console.WriteLine(ret);
            }
            Console.ReadKey();
        }

        private static string getDictionaryData(Dictionary<string, object> data)
        {
            string ret = null;
            foreach (KeyValuePair<string, object> item in data)
            {
                if (item.Value != null && item.Value.GetType() == typeof(Dictionary<string, object>))
                {
                    ret += item.Key.ToString() + "={";
                    ret += getDictionaryData((Dictionary<string, object>)item.Value);
                    ret += "};";
                }
                else
                {
                    ret += item.Key.ToString() + "=" + (item.Value == null ? "null" : item.Value.ToString()) + ";";
                }
            }
            return ret;
        }
    }
}
testRestApi.csProj

 

posted on 2015-11-10 16:20  AdolphYang  阅读(732)  评论(0编辑  收藏  举报