Esempio n. 1
0
        /// <summary>
        /// 发送短信
        /// </summary>
        /// <param name="mobile"></param>
        /// <returns></returns>
        public static bool SendMesssage(string mobile, string Content)
        {
            string url = string.Format("{0}:{1}/inter/sendSingleSMS", EMayConfig.Host, EMayConfig.Port);

            SingMessage entity = new SingMessage()
            {
                content            = Content,
                mobile             = mobile,
                customsmsid        = DateTime.Now.ToString("yyyyMMddHHmmsss"),
                extendedcode       = "",
                requesttime        = DateTime.Now.Ticks,
                timertime          = "",
                requestvalidperiod = EMayConfig.ValidPeriod
            };
            HttpWebResponse response = null;
            string          json     = SerializerJson.SerializeObject(entity);

            byte[] byteArray = EMayConfig.IsCompress ? AESHelper.AESEncrypt(GzipHelper.GZipCompressString(json), EMayConfig.SecretKey) : AESHelper.AESEncrypt(json, EMayConfig.SecretKey);
            byte[] result    = HttpHelper.SendRequestData(url, byteArray, ref response);

            string code = response.GetResponseHeader("result").ToString();

            if (code == "SUCCESS")
            {
                string res = AESHelper.AESDecryptString(result, EMayConfig.SecretKey);
                return(true);
            }
            else
            {
                return(false);
            }
        }
Esempio n. 2
0
        private bool isCompress = false;//是否压缩,默认否


        public SMSResponseBody BatchSend(SMSRequestBody body)
        {
            SMSResponseBody responseBody = new SMSResponseBody();

            string    result   = "";
            Hashtable headerhs = new Hashtable();

            Byte[] byteArray = null;
            string jsondata  = "";
            string url       = "http://" + host + "/inter/sendPersonalitySMS";

            headerhs.Add("appId", appId);
            //jsondata = "{\"smses\":[{\"mobile\":15500000000,\"customSmsId\":null,\"content\":\"【短信签名】短信内容\"},{\"mobile\":15500000001,\"customSmsId\":null,\"content\":\"【短信签名】短信内容\"}],\"timerTime\":\"\",\"extendedCode\":112,\"requestTime\":" + DateTime.Now.Ticks.ToString() + ",\"requestValidPeriod\":30}";
            jsondata = JsonConvertEx.ObjectToJson(body);

            if (isCompress)
            {
                headerhs.Add("gzip", "on");//先压缩成byte再加密
                //byteArray = HttpHelper.postdata(url, AESHelper.AESEncrypt(GzipHelper.GZipCompressString(jsondata), secretKey), headerhs, Encoding.UTF8, secretKey);
            }
            else
            {
                byteArray = HttpHelper.postdata(url, AESHelper.AESEncrypt(jsondata, secretKey), headerhs, Encoding.UTF8, secretKey);
            }

            if (byteArray != null)
            {
                if (isCompress)
                {
                    //result = GzipHelper.DecompressString(AESHelper.AESDecrypt(byteArray, secretKey));
                }
                else
                {
                    result = AESHelper.AESDecryptString(byteArray, secretKey);
                }

                if (result != "")
                {
                    if (result.IndexOf("ERROR") != -1)
                    {
                        responseBody.flag       = false;
                        responseBody.resultCode = result;
                    }
                    else
                    {
                        responseBody.flag       = true;
                        responseBody.resultCode = "";
                        responseBody.smses      = JsonConvertEx.JsonToList <SMSResponseEntity>(result);
                    }

                    return(responseBody);
                }
            }

            AsyncHelper.RunSync <bool>(() => Manager.Instance.WriteLogFile("亿美发送msg出现问题"));
            return(null);
        }