/// <summary>
        /// 设置开发模式,服务器回调
        /// </summary>
        /// <param name="url"></param>
        /// <param name="callback_token"></param>
        /// <returns></returns>
        public int SetDevServiceUrl(string url, string callback_token, string encoding_aeskey,
                                    string callback_encrypt_mode)
        {
            int staus = Login();

            if (staus == (int)HttpStatusCode.OK)
            {
                isLogin = true;

                HttpResponseMessage response = null;
                try
                {
                    _httpClient = new HttpClient(handler);
                    SetHeader();
                    _httpClient.DefaultRequestHeaders.TryAddWithoutValidation(CONTENT_TYPE_H, CONTENT_TYPE);

                    List <KeyValuePair <String, String> > paramList = new List <KeyValuePair <String, String> >();
                    paramList.Add(new KeyValuePair <string, string>("url", "" + url));
                    paramList.Add(new KeyValuePair <string, string>("callback_token", callback_token));
                    paramList.Add(new KeyValuePair <string, string>("encoding_aeskey", encoding_aeskey));
                    paramList.Add(new KeyValuePair <string, string>("callback_encrypt_mode", callback_encrypt_mode));
                    paramList.Add(new KeyValuePair <string, string>("operation_seq", "401119815"));

                    var uri = new Uri(WeChatUrl.DEV_SERVICE_URL + token);
                    //正在设置公众平台回调
                    response = _httpClient.PostAsync(uri,
                                                     new FormUrlEncodedContent(paramList)).Result;

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        //服务器连接成功
                        string result = response.Content.ReadAsStringAsync().Result;

                        PostBackModel xhStatus = JsonConvert.DeserializeObject <PostBackModel>(result);
                        if (xhStatus != null)
                        {
                            return(xhStatus.base_resp.ret);
                        }
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    if (response != null)
                    {
                        response.Dispose();
                    }
                }
            }
            else
            {
            }
            return(-1);
        }
Exemple #2
0
        /// <summary>
        /// 切换开发模式/编辑模式
        /// </summary>
        /// <param name="flag">开启1 关闭0 </param>
        /// <param name="type">开发模式2 编辑模式1 </param>
        /// <returns></returns>
        public int EnabledDev(int flag, int type)
        {
            int staus = Login();

            if (staus == (int)HttpStatusCode.OK)
            {
                isLogin = true;

                HttpResponseMessage response = null;
                try
                {
                    _httpClient = new HttpClient(handler);
                    SetHeader();
                    _httpClient.DefaultRequestHeaders.TryAddWithoutValidation(CONTENT_TYPE_H, CONTENT_TYPE);

                    List <KeyValuePair <String, String> > paramList = new List <KeyValuePair <String, String> >();
                    paramList.Add(new KeyValuePair <string, string>("flag", flag.ToString()));
                    paramList.Add(new KeyValuePair <string, string>("type", type.ToString()));
                    paramList.Add(new KeyValuePair <string, string>("token", token));

                    var uri = new Uri(WeChatUrl.DEV_UPDATE_RUL);
                    response = _httpClient.PostAsync(uri,
                                                     new FormUrlEncodedContent(paramList)).Result;

                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        //连接成功
                        string result = response.Content.ReadAsStringAsync().Result;

                        PostBackModel xhStatus = JsonConvert.DeserializeObject <PostBackModel>(result);
                        if (xhStatus != null)
                        {
                            return(xhStatus.base_resp.ret);
                        }
                    }
                }
                catch (Exception)
                {
                }
                finally
                {
                    if (response != null)
                    {
                        response.Dispose();
                    }
                }
            }
            else
            {
            }
            return(-1);
        }
Exemple #3
0
        /// <summary>
        /// 登陆微信
        /// </summary>
        /// <returns></returns>
        public int Login()
        {
            if (isLogin)
            {
                return (int)HttpStatusCode.OK;
            }

            HttpResponseMessage response = null;
            //正在登陆微信公众平台...
            try
            {
                _httpClient = new HttpClient(handler);
                SetHeader(); //设置httpClient头

                _httpClient.DefaultRequestHeaders.TryAddWithoutValidation(CONTENT_TYPE_H, CONTENT_TYPE);

                //java DigestUtils.md5Hex(this.loginPwd.getBytes())
                //c#  Md5Helper.Md5Hex(this.loginPwd);

                List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>();
                paramList.Add(new KeyValuePair<string, string>("username", this.loginUser));
                paramList.Add(new KeyValuePair<string, string>("pwd", this.loginPwd));
                //paramList.Add(new KeyValuePair<string, string>("pwd", "d3d40c3dd1acd940d4a98d16d75897fe"));
                paramList.Add(new KeyValuePair<string, string>("imgcode", ""));
                paramList.Add(new KeyValuePair<string, string>("f", "json"));

                var uri = new Uri(WeChatUrl.LOGIN_URL);
                response = _httpClient.PostAsync(uri,
                    new FormUrlEncodedContent(paramList)).Result;

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    //登陆成功
                    string result = response.Content.ReadAsStringAsync().Result;

                    loginBack = JsonConvert.DeserializeObject<PostBackModel>(result);

                    if (loginBack.base_resp.ret == 0)
                    {  //微信验证成功
                        StringBuilder cookie = new StringBuilder();

                        CookieCollection getCookies = handler.CookieContainer.GetCookies(uri);
                        foreach (Cookie c in getCookies)
                        {
                            cookie.Append(c.Name).Append("=")
                                .Append(c.Value).Append(";");
                        }
                        this.cookiestr = cookie.ToString();
                        //正在获取token
                        #region 正在获取token
                        if (!string.IsNullOrWhiteSpace(loginBack.redirect_url))
                        {
                            string[] ss = loginBack.redirect_url.Split('?');
                            string[] ps = null;
                            if (ss.Length == 2)
                            {
                                if (!string.IsNullOrWhiteSpace(ss[1])
                                        && ss[1].IndexOf("&") != -1)
                                    ps = ss[1].Split('&');
                            }
                            else if (ss.Length == 1)
                            {
                                if (!string.IsNullOrWhiteSpace(ss[0])
                                        && ss[0].IndexOf("&") != -1)
                                    ps = ss[0].Split('&');
                            }
                            if (ps != null)
                            {
                                foreach (var p in ps)
                                {
                                    if (string.IsNullOrWhiteSpace(p))
                                        continue;
                                    string[] tk = p.Split('=');
                                    if (!string.IsNullOrWhiteSpace(tk[0])
                                        && "token".Equals(tk[0].Trim().ToLower()))
                                    {
                                        if (!string.IsNullOrEmpty(tk[1]))
                                            token = tk[1].Trim();
                                        break;
                                    }
                                }
                            }
                            //获取token成功..
                        }
                        #endregion

                        //进入首页
                        return Index();
                    }
                    else
                    {  //验证错误
                        string err_msg = loginBack.base_resp.err_msg;
                    }
                }

            }
            catch (Exception e)
            {
                return -1;
            }
            finally
            {
                if (response != null)
                    response.Dispose();
            }
            return 0;
        }
Exemple #4
0
        /// <summary>
        /// 登陆移动网上营业厅
        /// </summary>
        /// <returns></returns>
        public int Login(string validcode)
        {
            if (isLogin)
            {
                return((int)HttpStatusCode.OK);
            }

            HttpResponseMessage response = null;

            //正在登陆微信公众平台...
            try
            {
                _httpClient = new HttpClient(handler);
                SetPostHeader(); //设置httpClient头

                //java DigestUtils.md5Hex(this.loginPwd.getBytes())
                //c#  Md5Helper.Md5Hex(this.loginPwd);

                List <KeyValuePair <String, String> > paramList = new List <KeyValuePair <String, String> >();
                paramList.Add(new KeyValuePair <string, string>("telno", Md5Helper.Md5Hex(this.loginUser)));
                paramList.Add(new KeyValuePair <string, string>("password", Md5Helper.Md5Hex(this.loginPwd)));
                paramList.Add(new KeyValuePair <string, string>("authLevel", "2"));
                paramList.Add(new KeyValuePair <string, string>("validcode", validcode));
                paramList.Add(new KeyValuePair <string, string>("ctype", "1"));
                paramList.Add(new KeyValuePair <string, string>("decode", "1"));
                paramList.Add(new KeyValuePair <string, string>("source", "wsyyt"));

                var uri = new Uri("https://sh.ac.10086.cn/loginex?act=2");
                response = _httpClient.PostAsync(uri,
                                                 new FormUrlEncodedContent(paramList)).Result;

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    //登陆成功
                    string result = response.Content.ReadAsStringAsync().Result;

                    loginBack = JsonConvert.DeserializeObject <PostBackModel>(result);

                    if (loginBack.base_resp.ret == 0)
                    {  //微信验证成功
                        StringBuilder cookie = new StringBuilder();

                        CookieCollection getCookies = handler.CookieContainer.GetCookies(uri);
                        foreach (Cookie c in getCookies)
                        {
                            cookie.Append(c.Name).Append("=")
                            .Append(c.Value).Append(";");
                        }
                        this.cookiestr = cookie.ToString();
                        //正在获取token
                        #region 正在获取token
                        if (!string.IsNullOrWhiteSpace(loginBack.redirect_url))
                        {
                            string[] ss = loginBack.redirect_url.Split('?');
                            string[] ps = null;
                            if (ss.Length == 2)
                            {
                                if (!string.IsNullOrWhiteSpace(ss[1]) &&
                                    ss[1].IndexOf("&") != -1)
                                {
                                    ps = ss[1].Split('&');
                                }
                            }
                            else if (ss.Length == 1)
                            {
                                if (!string.IsNullOrWhiteSpace(ss[0]) &&
                                    ss[0].IndexOf("&") != -1)
                                {
                                    ps = ss[0].Split('&');
                                }
                            }
                            if (ps != null)
                            {
                                foreach (var p in ps)
                                {
                                    if (string.IsNullOrWhiteSpace(p))
                                    {
                                        continue;
                                    }
                                    string[] tk = p.Split('=');
                                    if (!string.IsNullOrWhiteSpace(tk[0]) &&
                                        "token".Equals(tk[0].Trim().ToLower()))
                                    {
                                        if (!string.IsNullOrEmpty(tk[1]))
                                        {
                                            token = tk[1].Trim();
                                        }
                                        break;
                                    }
                                }
                            }
                            //获取token成功..
                        }
                        #endregion

                        //进入首页
                        return(Index());
                    }
                    else
                    {  //验证错误
                        string err_msg = loginBack.base_resp.err_msg;
                    }
                }
            }
            catch (Exception e)
            {
                return(-1);
            }
            finally
            {
                if (response != null)
                {
                    response.Dispose();
                }
            }
            return(0);
        }
Exemple #5
0
        /// <summary>
        /// 登陆微信
        /// </summary>
        /// <returns></returns>
        public int Login()
        {
            if (isLogin)
            {
                return((int)HttpStatusCode.OK);
            }

            HttpResponseMessage response = null;

            //正在登陆微信公众平台...
            try
            {
                _httpClient = new HttpClient(handler);
                SetHeader(); //设置httpClient头

                _httpClient.DefaultRequestHeaders.TryAddWithoutValidation(CONTENT_TYPE_H, CONTENT_TYPE);

                //java DigestUtils.md5Hex(this.loginPwd.getBytes())
                //c#  Md5Helper.Md5Hex(this.loginPwd);

                List <KeyValuePair <String, String> > paramList = new List <KeyValuePair <String, String> >();
                paramList.Add(new KeyValuePair <string, string>("username", this.loginUser));
                paramList.Add(new KeyValuePair <string, string>("pwd", this.loginPwd));
                //paramList.Add(new KeyValuePair<string, string>("pwd", "d3d40c3dd1acd940d4a98d16d75897fe"));
                paramList.Add(new KeyValuePair <string, string>("imgcode", ""));
                paramList.Add(new KeyValuePair <string, string>("f", "json"));

                var uri = new Uri(WeChatUrl.LOGIN_URL);
                response = _httpClient.PostAsync(uri,
                                                 new FormUrlEncodedContent(paramList)).Result;

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    //登陆成功
                    string result = response.Content.ReadAsStringAsync().Result;

                    loginBack = JsonConvert.DeserializeObject <PostBackModel>(result);

                    if (loginBack.base_resp.ret == 0)
                    {  //微信验证成功
                        StringBuilder cookie = new StringBuilder();

                        CookieCollection getCookies = handler.CookieContainer.GetCookies(uri);
                        foreach (Cookie c in getCookies)
                        {
                            cookie.Append(c.Name).Append("=")
                            .Append(c.Value).Append(";");
                        }
                        this.cookiestr = cookie.ToString();
                        //正在获取token
                        #region 正在获取token
                        if (!string.IsNullOrWhiteSpace(loginBack.redirect_url))
                        {
                            string[] ss = loginBack.redirect_url.Split('?');
                            string[] ps = null;
                            if (ss.Length == 2)
                            {
                                if (!string.IsNullOrWhiteSpace(ss[1]) &&
                                    ss[1].IndexOf("&") != -1)
                                {
                                    ps = ss[1].Split('&');
                                }
                            }
                            else if (ss.Length == 1)
                            {
                                if (!string.IsNullOrWhiteSpace(ss[0]) &&
                                    ss[0].IndexOf("&") != -1)
                                {
                                    ps = ss[0].Split('&');
                                }
                            }
                            if (ps != null)
                            {
                                foreach (var p in ps)
                                {
                                    if (string.IsNullOrWhiteSpace(p))
                                    {
                                        continue;
                                    }
                                    string[] tk = p.Split('=');
                                    if (!string.IsNullOrWhiteSpace(tk[0]) &&
                                        "token".Equals(tk[0].Trim().ToLower()))
                                    {
                                        if (!string.IsNullOrEmpty(tk[1]))
                                        {
                                            token = tk[1].Trim();
                                        }
                                        break;
                                    }
                                }
                            }
                            //获取token成功..
                        }
                        #endregion

                        //进入首页
                        return(Index());
                    }
                    else
                    {  //验证错误
                        string err_msg = loginBack.base_resp.err_msg;
                    }
                }
            }
            catch (Exception e)
            {
                return(-1);
            }
            finally
            {
                if (response != null)
                {
                    response.Dispose();
                }
            }
            return(0);
        }
Exemple #6
0
        /// <summary>
        /// 登陆移动网上营业厅
        /// </summary>
        /// <returns></returns>
        public int Login(string validcode)
        {
            if (isLogin)
            {
                return (int)HttpStatusCode.OK;
            }

            HttpResponseMessage response = null;
            //正在登陆微信公众平台...
            try
            {
                _httpClient = new HttpClient(handler);
                SetPostHeader(); //设置httpClient头

                //java DigestUtils.md5Hex(this.loginPwd.getBytes())
                //c#  Md5Helper.Md5Hex(this.loginPwd); 

                List<KeyValuePair<String, String>> paramList = new List<KeyValuePair<String, String>>();
                paramList.Add(new KeyValuePair<string, string>("telno", Md5Helper.Md5Hex(this.loginUser)));
                paramList.Add(new KeyValuePair<string, string>("password", Md5Helper.Md5Hex(this.loginPwd)));
                paramList.Add(new KeyValuePair<string, string>("authLevel", "2"));
                paramList.Add(new KeyValuePair<string, string>("validcode", validcode));
                paramList.Add(new KeyValuePair<string, string>("ctype", "1"));
                paramList.Add(new KeyValuePair<string, string>("decode", "1"));
                paramList.Add(new KeyValuePair<string, string>("source", "wsyyt"));

                var uri = new Uri("https://sh.ac.10086.cn/loginex?act=2");
                response = _httpClient.PostAsync(uri,
                    new FormUrlEncodedContent(paramList)).Result;

                if (response.StatusCode == HttpStatusCode.OK)
                {
                    //登陆成功
                    string result = response.Content.ReadAsStringAsync().Result;

                    loginBack = JsonConvert.DeserializeObject<PostBackModel>(result);

                    if (loginBack.base_resp.ret == 0)
                    {  //微信验证成功
                        StringBuilder cookie = new StringBuilder();

                        CookieCollection getCookies = handler.CookieContainer.GetCookies(uri);
                        foreach (Cookie c in getCookies)
                        {
                            cookie.Append(c.Name).Append("=")
                                .Append(c.Value).Append(";");
                        }
                        this.cookiestr = cookie.ToString();
                        //正在获取token
                        #region 正在获取token
                        if (!string.IsNullOrWhiteSpace(loginBack.redirect_url))
                        {
                            string[] ss = loginBack.redirect_url.Split('?');
                            string[] ps = null;
                            if (ss.Length == 2)
                            {
                                if (!string.IsNullOrWhiteSpace(ss[1])
                                        && ss[1].IndexOf("&") != -1)
                                    ps = ss[1].Split('&');
                            }
                            else if (ss.Length == 1)
                            {
                                if (!string.IsNullOrWhiteSpace(ss[0])
                                        && ss[0].IndexOf("&") != -1)
                                    ps = ss[0].Split('&');
                            }
                            if (ps != null)
                            {
                                foreach (var p in ps)
                                {
                                    if (string.IsNullOrWhiteSpace(p))
                                        continue;
                                    string[] tk = p.Split('=');
                                    if (!string.IsNullOrWhiteSpace(tk[0])
                                        && "token".Equals(tk[0].Trim().ToLower()))
                                    {
                                        if (!string.IsNullOrEmpty(tk[1]))
                                            token = tk[1].Trim();
                                        break;
                                    }
                                }
                            }
                            //获取token成功.. 
                        }
                        #endregion

                        //进入首页
                        return Index();
                    }
                    else
                    {  //验证错误
                        string err_msg = loginBack.base_resp.err_msg;
                    }
                }

            }
            catch (Exception e)
            {
                return -1;
            }
            finally
            {
                if (response != null)
                    response.Dispose();
            }
            return 0;
        }