Пример #1
0
 /// <summary>
 /// GetAccessToken
 /// </summary>
 /// <param name="code"></param>
 /// <returns></returns>
 private static string GetAccessToken(string code)
 {
     try
     {
         var    JSON = Lib.GoogleLib.GetConfigGoogle(Constants.GG_JSON_FILE);
         string d    = "code=" + code +
                       "&client_id=" + JSON.web.client_id +
                       "&client_secret=" + JSON.web.client_secret +
                       "&redirect_uri=" + (Constants.SERVER_TYPE == "REAL" ? JSON.web.redirect_uris[1] : JSON.web.redirect_uris[0]) +
                       "&grant_type=authorization_code";
         string url = JSON.web.token_uri + "";
         Logs.SaveLog("GetAccessToken: " + url +
                      "\r\nPost Data: " + d);
         string data = UtilClass.SendPost(d, url);
         Logs.SaveLog("TokenGG: " + data);
         //{ "access_token": "ya29.Glv2BYPsIns3p7MiUsvhz109tCR9zv3yOoZG_KZO3eynI_-ltDbnl43zqt6IAk17_KSkoVknBQwAakNe33m0CNvXznpW3pcC325vXKSc_i3Y93EoyEqDuPoYg1bj", "token_type": "Bearer", "expires_in": 3600, "refresh_token": "1/UxchQTnopGju7bDezDV-Djeye_bixXZETaHTpvhjAcc", "scope": "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/plus.me", "id_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IjlhMzNiNWVkYjQ5ZDA4NjdhODY3MmQ5NTczYjFlMGQyMzc1ODg2ZTEifQ.eyJhenAiOiI5ODMzNzM3OTg3NzctNGc1MWk2ODBvcThncTBwajFvdG5mZXNqcXNlMXZzcDAuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI5ODMzNzM3OTg3NzctNGc1MWk2ODBvcThncTBwajFvdG5mZXNqcXNlMXZzcDAuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDY1MzM3ODA3OTU5OTI1MTgwODgiLCJlbWFpbCI6ImRldnByb2R1Y3Rpb24udm5AZ21haWwuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImF0X2hhc2giOiJfbHNENkRnYXVmZTlIdkxwYWotLW93IiwiZXhwIjoxNTM0MDAxOTY0LCJpc3MiOiJhY2NvdW50cy5nb29nbGUuY29tIiwiaWF0IjoxNTMzOTk4MzY0fQ.udQXANtLAIzdY85Gn-KoSKUNBGVBnbwVKuEFeZTILJclzFPxoWcpiOvbvpD6KyCz0b8moQnZTSNZCeQ7uU-YZMWPy9Jr225Pqo5DbOIAfeVfpm8AhJxuKCw8euhxe3LRDxq37ABsx782ayXpV_07wgnoE5jBcNS_BjYGHA9e9yAMyJ5uWNmN5Y9WSbfl6fw03wDVenX--Qi4IDtj-3ClJ2s6nqZ9i1kcPKGJPXMLQvXKQRkkh3k335Z-k2Y-CG5kjtBHA7Mfdkf2H5cgvY-I6Ck_qPUR_O2AnZ3uTWzND7-E6cjoRAcY9OB1ye0vnAe1kovU3H2ojd2RcNViZfZm_w" }
         dynamic Token       = JObject.Parse(data);
         string  accessToken = Token.access_token + "";
         return(accessToken);
     }
     catch (Exception ex)
     {
         Logs.SaveError("Error AccessToken: " + ex);
         throw new Exception(ex.Message);
     }
 }
Пример #2
0
        public static void SendEmail(string subject, string message, string userTo)
        {
            try
            {
                subject = UtilClass.RemoveSign4VietnameseString(subject);
                userTo  = userTo.ToLower();
                //Generate Message
                if (userName.Count() == 0)
                {
                    return;
                }
                var    mailMessage  = new MimeMailMessage();
                string smtpUserName = userName[UtilClass.GetRandomNumber(0, userName.Count() - 1)];
                mailMessage.From = new MimeMailAddress(smtpUserName);
                mailMessage.To.Add(userTo);
                mailMessage.IsBodyHtml = true;
                mailMessage.Subject    = subject;
                mailMessage.Body       = message;

                //Create Smtp Client
                var mailer = new MimeMailer(host, port);
                mailer.User               = smtpUserName;
                mailer.Password           = password;
                mailer.SslType            = port == 587 ? SslMode.None: SslMode.Ssl; //SslMode.Ssl;
                mailer.AuthenticationMode = AuthenticationType.Base64;

                //Set a delegate function for call back
                mailer.SendCompleted += compEvent;
                mailer.SendMailAsync(mailMessage);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
        }
Пример #3
0
        public static void SendMessage(string phone, string message)
        {
            if (!string.IsNullOrEmpty(phone))
            {
                string msgSent = UtilClass.RemoveSign4VietnameseString(message);//HttpUtility.UrlEncode(message);

                string url = "http://rest.esms.vn/MainService.svc/json/SendMultipleMessage_V4_get?Phone=" + phone + "&Content=" + msgSent + "&ApiKey=" + ApiKey + "&SecretKey=" + SecretKey + "&SmsType=" + SmsType + "&brandname=" + brandName;
                //string SmsType = "4";
                //string url = string.Format("http://rest.esms.vn/MainService.svc/json/SendMultipleMessage_V4_get?Phone={0}&Content={1}&ApiKey={2}&SecretKey={3}&SmsType={4}",phone, msgSent, ApiKey, SecretKey, SmsType);
                try
                {
                    Logs.SaveLog("Send SMS Message: " + url);
                    string result = Web.WebRequest(Web.Method.GET, url, "");
                    Logs.SaveLog("Message result: " + result);
                }
                catch (Exception ex)
                {
                    Logs.SaveError("ERROR Send SMS Message: " + ex);
                }
            }
        }