Esempio n. 1
0
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="config">配置</param>
        /// <param name="receivePhone">接收手机号 多个逗号','隔开</param>
        /// <param name="info">内容 短信模板里 填充占位符的值</param>
        /// <returns></returns>
        public static SMSResposeBody SendVCodeSMS(SMSConfig config, string receivePhone, string[] info)
        {
            if (config == null)
                throw new ArgumentNullException("config");
            if (string.IsNullOrWhiteSpace(receivePhone))
                throw new ArgumentNullException("receivePhone");
            if (info == null || info.Count() <= 0)
                throw new ArgumentNullException("info");

            string ret = null;

            CCPRestSDK.CCPRestSDK api = new CCPRestSDK.CCPRestSDK();
            //ip格式如下,不带https://
            bool isInit = api.init(config.RestURL, config.RestPort);
            api.setAccount(config.ACCOUNTSID, config.AUTHTOKEN);
            api.setAppId(config.AppID);
            api.enabeLog(false);

            try
            {
                if (isInit)
                {
                    Dictionary<string, object> retData = api.SendTemplateSMS(receivePhone, config.VCodeTemplateID, info);
                    ret = getDictionaryData(retData);
                }
                else
                {
                    ret = "初始化失败";
                }
            }
            catch (Exception exc)
            {
                throw exc;
            }
            SMSResposeBody body = new JavaScriptSerializer().Deserialize<SMSResposeBody>(ret);
            return body;
        }