Ejemplo n.º 1
0
        /// <summary>
        /// 发送同内容的多条短信
        /// </summary>
        /// <param name="content">短信内容</param>
        /// <param name="mobile_list">目标手机号列表</param>
        /// <param name="rid">记录ID, 用于返回结果后的后续处理, 非必填</param>
        /// <param name="filter_nonnumber">是否过滤手机号中包含的非数字字符</param>
        /// <returns>发送结果</returns>
        public override SMSResponseList send(string content, List <string> mobile_list, string rid, bool filter_nonnumber)
        {
            if (service_key.isNull())
            {
                return(SMSResponseList.errorNotInitialized());
            }
            if (content.isNull())
            {
                return(SMSResponseList.custom(9900, "传入内容不能为空"));
            }
            var sb_mobile = new StringBuilder();

            foreach (var item in mobile_list)
            {
                var mob = item;
                if (filter_nonnumber)
                {
                    mob = mob.getOnlyNumber();
                }
                if (!mob.isPhoneNumber())
                {
                    continue;
                }
                if (sb_mobile.Length > 0)
                {
                    sb_mobile.Append(",");
                }
                sb_mobile.Append(mob.Trim());
            }
            if (sb_mobile.Length <= 0)
            {
                return(SMSResponseList.custom(9901, "手机号传入有误"));
            }
            var sb = new StringBuilder();

            sb.Append("apikey=");
            sb.Append(service_key);
            sb.Append("&mobile=");
            sb.Append(sb_mobile.ToString());
            sb.Append("&text=");
            sb.Append(HttpUtility.UrlEncode(string.Format("【{0}】{1}", sign, content)));
            if (!rid.isNull())
            {
                sb.Append("&uid=" + rid);
            }
            var response = post(Urls.urlSMSList(), sb.ToString());

            return(getResponseList(response));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发送同内容的多条短信
        /// </summary>
        /// <param name="template_id">模板ID</param>
        /// <param name="pm">模板参数</param>
        /// <param name="mobile_list">目标手机号列表</param>
        /// <param name="rid">记录ID, 用于返回结果后的后续处理, 非必填</param>
        /// <param name="filter_nonnumber">是否过滤手机号中包含的非数字字符</param>
        /// <returns>发送结果</returns>
        public override SMSResponseList sendTemplate(long template_id, Dictionary <string, string> pm, List <string> mobile_list, string rid, bool filter_nonnumber)
        {
            if (service_key.isNull())
            {
                return(SMSResponseList.errorNotInitialized());
            }
            var sb_mobile = new StringBuilder();

            foreach (var item in mobile_list)
            {
                var mob = item;
                if (filter_nonnumber)
                {
                    mob = item.getOnlyNumber();
                }
                if (!mob.isPhoneNumber())
                {
                    continue;
                }
                if (sb_mobile.Length > 0)
                {
                    sb_mobile.Append(",");
                }
                sb_mobile.Append(mob.Trim());
            }
            if (sb_mobile.Length <= 0)
            {
                return(SMSResponseList.custom(9901, "手机号传入有误"));
            }
            var sb = new StringBuilder();

            sb.Append("apikey=");
            sb.Append(service_key);
            sb.Append("&mobile=");
            sb.Append(sb_mobile.ToString());
            sb.Append("&tpl_id=" + template_id);
            sb.Append("&tpl_value=" + HttpUtility.UrlEncode(serializeTemplateParam(pm)));
            if (!rid.isNull())
            {
                sb.Append("&uid=" + rid);
            }
            var response = post(Urls.urlSMSTemplateList(), sb.ToString());

            return(getResponseList(response));
        }