示例#1
0
        public static string RegisterCode(string phoneNumber, string code, out string response, string id = null)
        {
            response = string.Empty;
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    //auto generate
                    id = GenerateIdentity(phoneNumber);
                }
                PhoneNumber pn = new PhoneNumber(phoneNumber);

                string uri = string.Format("https://v.whatsapp.net/v2/register?cc={0}&in={1}&id={2}&code={3}", pn.CC, pn.Number, id, code);
                response = GetResponse(uri);
                if (response.GetJsonValue("status") == "ok")
                {
                    return response.GetJsonValue("pw");
                }
                return null;
            }
            catch
            {
                return null;
            }
        }
示例#2
0
 public static bool RequestCode(string phoneNumber, out string password, out string request, out string response, string method = "sms", string id = null)
 {
     response = null;
     password = null;
     request = null;
     try
     {
         if (string.IsNullOrEmpty(id))
         {
             //auto-generate
             id = GenerateIdentity(phoneNumber);
         }
         PhoneNumber pn = new PhoneNumber(phoneNumber);
         string token = System.Uri.EscapeDataString(WhatsRegisterV2.GetToken(pn.Number));
         
         request = string.Format("https://v.whatsapp.net/v2/code?cc={0}&in={1}&to={0}{1}&method={2}&mcc={3}&mnc={4}&token={5}&id={6}&lg={7}&lc={8}", pn.CC, pn.Number, method, pn.MCC, pn.MNC, token, id, pn.ISO639, pn.ISO3166);
         response = GetResponse(request);
         password = response.GetJsonValue("pw");
         if (!string.IsNullOrEmpty(password))
         {
             return true;
         }
         return (response.GetJsonValue("status") == "sent");
     }
     catch(Exception e)
     {
         response = e.Message;
         return false;
     }
 }
示例#3
0
        public bool SendGetRequestToken(string number, out string identity, out string waNumber)
        {
            string strPassword = "";
            string strRequest  = "";
            string strResponse = "";

            waParser.PhoneNumber waPhone = new waParser.PhoneNumber(number);
            waNumber = waPhone.Number;
            identity = waRegister.GenerateIdentity(number, String.Empty);

            return(waRegister.RequestCode(waPhone.Number, out strPassword, out strRequest, out strResponse, "sms", identity));
        }
示例#4
0
        public static string RegisterCode(string phoneNumber, string code, out string response, string id = null)
        {
            response = string.Empty;
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    //auto generate
                    id = GenerateIdentity(phoneNumber);
                }
                PhoneNumber pn = new PhoneNumber(phoneNumber);

                Dictionary<string, string> query = new Dictionary<string, string>();
                query.Add("cc", pn.CC);
                query.Add("in", pn.Number);
                query.Add("lg", pn.ISO639);
                query.Add("lc", pn.ISO3166);
                query.Add("id", id);
                query.Add("mistyped", "6");
                query.Add("network_radio_type", "1");
                query.Add("simnum", "1");
                query.Add("s", "");
                query.Add("copiedrc", "1");
                query.Add("hasinrc", "1");
                query.Add("rcmatch", "1");
                query.Add("pid", ((new Random()).Next(9899) + 100).ToString());
                query.Add("rchash", GetRandom(20).ToSHA256String());
                query.Add("anhash", GetRandom(20).ToMD5String());
                query.Add("extexist", "1");
                query.Add("extstate", "1");
                // query.Add("method", "sms");
                query.Add("code", code);

                string uri = BuildUrl(WhatsConstants.WhatsAppRegisterHost, query);
                response = GetResponse(uri);
                if (response.GetJsonValue("status") == "ok")
                {
                    return response.GetJsonValue("pw");
                }
                return null;
            }
            catch
            {
                return null;
            }
        }
示例#5
0
        protected byte[] getAuthBlob()
        {
            byte[] data = null;
            if (this._challengeBytes != null)
            {
                byte[][] keys = KeyStream.GenerateKeys(this.encryptPassword(), this._challengeBytes);

                this.reader.Key = new KeyStream(keys[2], keys[3]);

                this.outputKey = new KeyStream(keys[0], keys[1]);

                PhoneNumber pn = new PhoneNumber(this.phoneNumber);

                List<byte> b = new List<byte>();
                b.AddRange(new byte[] { 0, 0, 0, 0 });
                b.AddRange(WhatsApp.SYSEncoding.GetBytes(this.phoneNumber));
                b.AddRange(this._challengeBytes);
                b.AddRange(WhatsApp.SYSEncoding.GetBytes(Helper.Func.GetNowUnixTimestamp().ToString()));
                b.AddRange(WhatsApp.SYSEncoding.GetBytes(WhatsConstants.UserAgent));
                b.AddRange(WhatsApp.SYSEncoding.GetBytes(String.Format(" MccMnc/{0}001", pn.MCC)));
                data = b.ToArray();

                this._challengeBytes = null;

                this.outputKey.EncodeMessage(data, 0, 4, data.Length - 4);

                this.BinWriter.Key = this.outputKey;
            }

            return data;
        }
示例#6
0
        public static string RequestExist(string phoneNumber, out string response, string id = null)
        {
            response = string.Empty;
            try
            {
                if (String.IsNullOrEmpty(id))
                {
                    id = GenerateIdentity(phoneNumber);
                }
                PhoneNumber pn = new PhoneNumber(phoneNumber);

                string uri = string.Format("https://v.whatsapp.net/v2/exist?cc={0}&in={1}&id={2}", pn.CC, pn.Number, id);
                response = GetResponse(uri);
                if (response.GetJsonValue("status") == "ok")
                {
                    return response.GetJsonValue("pw");
                }
                return null;
            }
            catch
            {
                return null;
            }
        }
        public static bool RequestCode(string phoneNumber, out string password, out string request, out string response, string method = "sms", string id = null)
        {
            response = null;
            password = null;
            request = null;
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    //auto-generate
                    id = GenerateIdentity(phoneNumber);
                }
                PhoneNumber pn = new PhoneNumber(phoneNumber);
                string token = System.Uri.EscapeDataString(WhatsRegisterV2.GetToken(pn.Number));

                byte[] sha256bytes = new byte[20]; new Random().NextBytes(sha256bytes);
                NameValueCollection QueryStringParameters = new NameValueCollection();
                QueryStringParameters.Add("cc", pn.CC);
                QueryStringParameters.Add("in", pn.Number);
                QueryStringParameters.Add("lg", pn.ISO639);
                QueryStringParameters.Add("lc", pn.ISO3166);
                QueryStringParameters.Add("id", id);
                QueryStringParameters.Add("token", token);
                QueryStringParameters.Add("mistyped", "6");
                QueryStringParameters.Add("network_radio_type", "1");
                QueryStringParameters.Add("simnum", "1");
                QueryStringParameters.Add("s", "");
                QueryStringParameters.Add("copiedrc", "1");
                QueryStringParameters.Add("hasinrc", "1");
                QueryStringParameters.Add("rcmatch", "1");
                QueryStringParameters.Add("pid", new Random().Next(100, 9999).ToString());
                QueryStringParameters.Add("rchash", BitConverter.ToString(HashAlgorithm.Create("sha256").ComputeHash(sha256bytes)));
                QueryStringParameters.Add("anhash", BitConverter.ToString(HashAlgorithm.Create("md5").ComputeHash(sha256bytes)));
                QueryStringParameters.Add("extexist", "1");
                QueryStringParameters.Add("extstate", "1");
                QueryStringParameters.Add("mcc", pn.MCC);
                QueryStringParameters.Add("mnc", pn.MNC);
                QueryStringParameters.Add("sim_mcc", pn.MCC);
                QueryStringParameters.Add("sim_mnc", pn.MNC);
                QueryStringParameters.Add("method", method);

                NameValueCollection RequestHttpHeaders = new NameValueCollection();
                RequestHttpHeaders.Add("User-Agent", WhatsConstants.UserAgent);
                RequestHttpHeaders.Add("Accept", "text/json");

                response = GetResponse("https://v.whatsapp.net/v2/code", QueryStringParameters, RequestHttpHeaders);
                // request = String.Format("https://v.whatsapp.net/v2/code?method={0}&in={1}&cc={2}&id={3}&lg={4}&lc={5}&token={6}&sim_mcc=000&sim_mnc=000", method, pn.Number, pn.CC, id, pn.ISO639, pn.ISO3166, token, pn.MCC, pn.MNC);
                // response = GetResponse(request);
                password = response.GetJsonValue("pw");
                if (!string.IsNullOrEmpty(password))
                {
                    return true;
                }
                return (response.GetJsonValue("status") == "sent");
            }
            catch (Exception e)
            {
                response = e.Message;
                return false;
            }
        }
示例#8
0
        public static bool RequestCode(string phoneNumber, out string password, out string request, out string response, string method = "sms", string id = null)
        {
            response = null;
            password = null;
            request = null;
            try
            {
                if (string.IsNullOrEmpty(id))
                {
                    //auto-generate
                    id = GenerateIdentity(phoneNumber);
                }
                PhoneNumber pn = new PhoneNumber(phoneNumber);
                string token = System.Uri.EscapeDataString(WhatsRegisterV2.GetToken(pn.Number, WhatsConstants.Platform ));

                Dictionary<string, string> query = new Dictionary<string, string>();

                query.Add("cc", pn.CC);
                query.Add("in", pn.Number);
                query.Add("lg", pn.ISO639);
                query.Add("lc", pn.ISO3166);
                query.Add("id", id);
                query.Add("token", token);
                query.Add("mistyped", "6");
                query.Add("network_radio_type", "1");
                query.Add("simnum", "1");
                query.Add("s", "");
                query.Add("copiedrc", "1");
                query.Add("hasinrc", "1");
                query.Add("rcmatch", "1");
                query.Add("pid", ((new Random()).Next(9899) + 100).ToString());
                query.Add("rchash", GetRandom(20).ToSHA256String());
                query.Add("anhash", GetRandom(20).ToMD5String());
                query.Add("extexist", "1");
                query.Add("extstate", "1");
                query.Add("mcc", pn.MCC);
                query.Add("mnc", pn.MNC);
                query.Add("sim_mcc", pn.MCC);
                query.Add("sim_mnc", pn.MNC);
                query.Add("method", method);

                string uri = BuildUrl(WhatsConstants.WhatsAppRequestHost, query);
                Console.WriteLine(uri);
                response = GetResponse(uri);
                password = response.GetJsonValue("pw");
                if (!string.IsNullOrEmpty(password))
                {
                    return true;
                }
                return (response.GetJsonValue("status") == "sent");
            }
            catch (Exception e)
            {
                response = e.Message;
                return false;
            }
        }