使用SDK短信接口

编写方法如下: 

/// API(短信接收号码,短信模版ID,内容数据) ///
/// 短信接收号码
/// 短信模版ID
/// 内容数据
pub­lic void GoMessage(string pho­neNum­ber, string tem­plateId, string[] con­text)
{
string ret = null;
CCPRestS­DK api = new CCPRestS­DK();
bool isInit = api.init(“app.cloopen.com”, “8883”);//(短信验证码接口地址,端口)
//api.setAccount(“自己申请”, “自己申请”);//(主账号,主账号令牌)
//api.setAppId(“自己申请”);//应用ID

    
        try
        {
            if (isInit)
            {
                Dictionary<string, object> retData = api.SendTemplateSMS(phoneNumber, templateId, context);//(短信接收号码,短信模版ID,内容数据)
                ret = getDictionaryData(retData);
            }
            else
            {
                ret = "初始化失败";
            }
        }
        catch (Exception exc)
        {
            ret = exc.Message;
        }
    }

    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;
    }

使用方法:

pub­lic Action­Re­sult Send­Note()
{
string[] con­text =new string[2];
context[0] = “888888”;
context[1] = “3”;
GoMes­sage(“”, “”, con­text);
return Con­tent();
}

接下来在前台写一个a­jax访问即可

为您推荐

发表评论

电子邮件地址不会被公开。 必填项已用*标注