//using common.Dto;
//using Newtonsoft.Json;
//using System;
//using System.Collections.Generic;
//using System.IO;
//using System.Net;
//using System.Text.Json;

//namespace Sufang.Common
//{
//    /// <summary>
//    /// 创蓝短信帮助类
//    /// </summary>
//    public class SMSHelper
//    {
//        private string apiAccount;

//        private string apiPassword;

//        private string postUrl;

//        /// <summary>
//        /// 创蓝发送短构造函数
//        /// <para>accountType参数：CODE=验证码账号,NOTIFY=通知账号</para>
//        /// <para>smsType参数：SEND=验证码短信接口,VARIABLE=变量短信接口,BALANCE=余额查询接口</para>
//        /// </summary>
//        /// <param name="accountType">CODE=验证码账号,NOTIFY=通知账号</param>
//        /// <param name="smsType">SEND=验证码短信接口,VARIABLE=变量短信接口,BALANCE=余额查询接口</param>
//        public SMSHelper(string accountType = "CODE", string smsType = "SEND")
//        {
//            switch (accountType) 
//            {
//                case "CODE"://验证码账号
//                    this.apiAccount = ConfigExtensions.Configuration["SMS:ApiAccount"];
//                    this.apiPassword = ConfigExtensions.Configuration["SMS:ApiPassword"];
//                    break;
//                case "NOTIFY"://通知账号
//                    this.apiAccount = ConfigExtensions.Configuration["SMS:NotifyApiAccount"];
//                    this.apiPassword = ConfigExtensions.Configuration["SMS:NotifyApiPassword"];
//                    break;
//            }
            
//            switch (smsType)
//            {
//                case "SEND"://验证码短信
//                    this.postUrl = ConfigExtensions.Configuration["SMS:PostUrl"];
//                    break;
//                case "VARIABLE"://变量短信
//                    this.postUrl = ConfigExtensions.Configuration["SMS:VariableUrl"];
//                    break;
//                case "BALANCE"://短信余额查询
//                    this.postUrl = ConfigExtensions.Configuration["SMS:BalanceQueryUrl"];
//                    break;
//            }

//        }
//        public SMSHelper(string apiAccount, string apiPassword, string postUrl)
//        {
//            this.apiAccount = apiAccount;
//            this.apiPassword = apiPassword;
//            this.postUrl = postUrl;
//        }

//        /// <summary>
//        /// 发送短信
//        /// </summary>
//        /// <param name="phone">接收方电话号码</param>
//        /// <param name="number">验证码</param>
//        /// <returns>短信发送结果</returns>
//        public string SendSMS(long phone, int number)
//        {
//            String msg = string.Format("您的短信验证码为【{0}】，请在5分钟内输入提交。", number); // 模板要经过审核，不可修改
//            string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//            string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, phone, msg);
//            return doPostMethodToObj(this.postUrl, "{" + jsonBody + "}"); // 发送成功的返回值类似于：{"code":"0","msgId":"20052214491300202002000008902598","time":"20200522144913","errorMsg":""}
//        }
//        /// <summary>
//        /// 件造发货短信
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号,1=物流公司名称,2=物流单号,3=H5订单详情地址</param>
//        /// <returns>返回JSON</returns>
//        public SmsDTO SendDeliverySMS(params string[] param)
//        {
//            try
//            {
//                // 模板要经过审核，不可修改
//                String msg = "【云造科技】您购买的商品已通过{0}寄出，运单号{1}，请注意查收！可点击下方链接查看：{2}，或搜索并关注【件造】公众号中查看订单状态。";
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"msg\":\"{2}\",\"params\":\"{3}\",\"report\":\"true\"";
//                var strParams = string.Empty;
//                foreach (var item in param)
//                {
//                    strParams += strParams == "" ? item : ("," + item);
//                }
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, string.Format(msg, "{$var}", "{$var}", "{$var}"), strParams);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = string.Format(msg, param[1], param[2], param[3]);
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }
//        /// <summary>
//        /// 发送提现审核不通过的短信
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号,1=申请日期,2=详情页面链接</param>
//        /// <returns></returns>
//        public SmsDTO SendWithdrawAuditFailSMS(params string[] param)
//        {
//            try
//            {
//                String msg = string.Format("您{0}的提现申请未通过审核，请点击链接查看详情。{1}", param[1], param[2]); // 模板要经过审核，不可修改
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, param[0], msg);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = msg;
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }
//        /// <summary>
//        /// 发送提现审核通过的短信
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号,1=申请日期</param>
//        /// <returns></returns>
//        public SmsDTO SendWithdrawAuditSuccessSMS(params string[] param)
//        {
//            try
//            {
//                String msg = string.Format("您{0}的提现申请已审核通过，将于72小时内到账您指定账户，具体到账时间以银行通知为准。", param[1]); // 模板要经过审核，不可修改
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, param[0], msg);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = msg;
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }
//        /// <summary>
//        /// 商户产品下架
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号,1=商户名称,2=产品组名称</param>
//        /// <returns></returns>
//        public SmsDTO SendMerchantPutProductSMS(params string[] param)
//        {
//            try
//            {
//                String msg = string.Format("尊敬【{0}】您好！速纺平台已经将【{1}】从平台上下架，对应产品或商品也将同步下架，请您及时登录App进行相应处理，具体情况可咨询您的代理商或者平台客服，平台客服电话400-9955-965。", param[1], param[2]); // 模板要经过审核，不可修改
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, param[0], msg);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = msg;
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }
//        /// <summary>
//        /// 代理商产品下架
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号,1=代理商名称,2=产品组名称</param>
//        /// <returns></returns>
//        public SmsDTO SendAgentPutProductSMS(params string[] param)
//        {
//            try
//            {
//                String msg = string.Format("尊敬【{0}】您好！速纺平台已经将【{1}】从平台上下架，请您及时进行相应处理，具体情况可咨询平台客服，平台客服电话400-9955-965。", param[1], param[2]); // 模板要经过审核，不可修改
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, param[0], msg);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = msg;
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }
//        /// <summary>
//        /// 代理商修改产品价
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号,1=代理商名称,2=产品组名称</param>
//        /// <returns></returns>
//        public SmsDTO SendAgent_EditProductPrice_SMS(params string[] param)
//        {
//            try
//            {
//                String msg = string.Format("尊敬【{0}】您好！速纺平台已经调整【{1}】的代理商供应价格，请您及时进行相应处理，具体情况可咨询平台客服，平台客服电话400-9955-965。", param[1], param[2]); // 模板要经过审核，不可修改
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, param[0], msg);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = msg;
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }
//        /// <summary>
//        /// 商户修改产品价
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号,1=代理商名称,2=产品名称</param>
//        /// <returns></returns>
//        public SmsDTO SendMerchant_EditProductPrice_SMS(params string[] param)
//        {
//            try
//            {
//                String msg = string.Format("尊敬【{0}】您好！您的代理商已经调整【{1}】供应价格，请您及时登录App进行相应处理，具体情况可咨询您的代理商或者平台客服，平台客服电话400-9955-965。", param[1], param[2]); // 模板要经过审核，不可修改
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, param[0], msg);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = msg;
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }
//        /// <summary>
//        /// 给转账人发送汇款银行信息
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号,1=开户名称,2=开户银行,3=汇款账号</param>
//        /// <returns></returns>
//        public SmsDTO Send_RecipientBankInfo_SMS(params string[] param)
//        {
//            try
//            {
//                String msg = string.Format("开户名称：{0}，开户银行：{1}，转账汇款账号：{2}，汇款时请核对信息是否准确，谢谢合作！", param[1], param[2], param[3]); // 模板要经过审核，不可修改
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, param[0], msg);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = msg;
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }
//        /// <summary>
//        /// 发送账号余额不足提醒
//        /// </summary>
//        /// <param name="param">参数数组(0=手机号</param>
//        /// <returns></returns>
//        public SmsDTO Send_ApiAcountMoneyWarn_SMS(params string[] param)
//        {
//            try
//            {
//                String msg = "账户金额即将不足，为避免影响生产进度，请及时充值，汇款时请核对信息是否准确，谢谢合作！"; // 模板要经过审核，不可修改
//                string postJsonTpl = "\"account\":\"{0}\",\"password\":\"{1}\",\"phone\":\"{2}\",\"report\":\"true\",\"msg\":\"{3}\"";
//                string jsonBody = string.Format(postJsonTpl, this.apiAccount, this.apiPassword, param[0], msg);
//                var resultJSON = doPostMethodToObj(this.postUrl, "{" + jsonBody + "}");
//                var smsResultInfo = JsonConvert.DeserializeObject<SmsDTO>(resultJSON);
//                smsResultInfo.SmsMsg = msg;
//                return smsResultInfo;
//            }
//            catch (Exception ex)
//            {
//                return new SmsDTO() { Code = "-5", ErrorMsg = "内部异常：" + ex.Message, SmsMsg = " " };
//            }
//        }

//        private string doPostMethodToObj(string url, string jsonBody)
//        {
//            string result = String.Empty;
//            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
//            httpWebRequest.ContentType = "application/json";

//            httpWebRequest.Method = "POST";
//            // Create NetworkCredential Object
//            NetworkCredential admin_auth = new NetworkCredential("username", "password");
//            // Set your HTTP credentials in your request header
//            httpWebRequest.Credentials = admin_auth;
//            // callback for handling server certificates
//            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
//            using (StreamWriter streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
//            {
//                streamWriter.Write(jsonBody);
//                streamWriter.Flush();
//                streamWriter.Close();
//                HttpWebResponse httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
//                using (StreamReader streamReader = new StreamReader(httpResponse.GetResponseStream()))
//                {

//                    result = streamReader.ReadToEnd();

//                }
//            }
//            return result;
//        }
//    }
//}
