Ejemplo n.º 1
0
        /// <summary>
        /// 获取微信所有联系人
        /// </summary>
        /// <param name="wxAccount"></param>
        /// <returns></returns>
        /// https://wx2.qq.com/cgi-bin/mmwebwx-bin/webwxgetcontact
        /// ?lang=zh_CN
        /// &pass_ticket=9%252FuIrFpoM6CCrYsAV7mzDF0aFkHiXGlotDlmHbQokhM%253D
        /// &r=1501480039623
        /// &seq=0
        /// &skey=@crypt_77e833b9_e705acd2a3250d78bdbb1137d87afad5
        public static HttpTaskParams GetContactAllParams(string host, WxAccount wxAccount)
        {
            string url = string.Format("{0}?lang=zh_CN&pass_ticket={1}&r={2}&seq=0&skey={3}",
                                       WxHttpApi.GetCommonUrl(host, WxHttpApi.URL_WX_CONTACT_ALL),
                                       encoding(wxAccount.PassTicket),
                                       TimeUtil.CurrentTimeMillis(),
                                       encoding(wxAccount.Skey));

            return(HttpTaskParams.NewGet(url));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 获取登录跳转链接
        /// </summary>
        /// <param name="redirectUri"></param>
        /// <returns></returns>
        /// url->https://wx.qq.com/cgi-bin/mmwebwx-bin/webwxnewloginpage
        /// ?ticket=AV0lBiU3dZOD5hBV9bpyx9b9@qrticket_0
        /// &uuid=4dUx4jLLIA==
        /// &lang=zh_CN
        /// &scan=1499308941";
        public static HttpTaskParams GetLoginRedirectUriParams(string redirectUri)
        {
            string url = string.Format("{0}&fun={1}&version={2}&lang={3}", redirectUri, "new", "v2", "zh_CN");

            if (WxHttpApi.IsHttpScheme())
            {
                url = Regex.Replace(url, WxHttpApi.URL_SCHEME_HTTPS, WxHttpApi.URL_SCHEME_HTTP);
            }

            return(HttpTaskParams.NewGet(url));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 获取登录uid相关请求参数
        /// </summary>
        /// <returns></returns>
        /// url->https://login.wx.qq.com/jslogin
        /// ?appid=wx782c26e4c19acffb
        /// &redirect_uri=https%3A%2F%2Fwx.qq.com%2Fcgi-bin%2Fmmwebwx-bin%2Fwebwxnewloginpage
        /// &fun=new
        /// &lang=zh_CN
        /// &_=1499308667244
        public static HttpTaskParams GetLoginUidParams()
        {
            HttpTaskParams htp = HttpTaskParams.NewGet(WxHttpApi.GetLoginUrl(WxHttpApi.URL_LOGIN_UID));

            htp.AddStringParam("appid", "wx782c26e4c19acffb");
            htp.AddStringParam("fun", "new");
            htp.AddStringParam("lang", "zh_CN");
            htp.AddStringParam("_", TimeUtil.CurrentTimeMillis().ToString());
            htp.AddStringParam("redirect_uri", WxHttpApi.URL_WX_JS_LOGIN_REDIRECT_URI);
            return(htp);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取二维码扫描结果请求
        /// </summary>
        /// <param name="uid"></param>
        /// <param name="tip"></param>
        /// <returns></returns>
        /// url->https://login.wx.qq.com/cgi-bin/mmwebwx-bin/login
        /// ?loginicon=true
        /// &uuid=Ifv-J92fbw==
        /// &tip=0&
        /// r=-366287686&
        /// _=1499309823465
        public static HttpTaskParams GetLoginScanParams(string uid, string tip)
        {
            HttpTaskParams htp = HttpTaskParams.NewGet(WxHttpApi.GetLoginUrl(WxHttpApi.URL_LOGIN_QRCODE_SCAN_CHECK));

            htp.AddStringParam("uuid", uid);
            htp.AddStringParam("tip", tip);
            htp.AddStringParam("loginicon", "true");
            long millis = TimeUtil.CurrentTimeMillis();

            htp.AddStringParam("r", ((millis / 1000)).ToString());//时间戳取反
            htp.AddStringParam("_", millis.ToString());
            return(htp);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 获取同步检查参数
        /// </summary>
        /// <param name="account"></param>
        /// <param name="deviceId"></param>
        /// <param name="wxSyncKey"></param>
        /// <returns></returns>
        /// https://webpush.wx2.qq.com/cgi-bin/mmwebwx-bin/synccheck
        /// ?r=1501480039641
        /// &skey=%40crypt_77e833b9_e705acd2a3250d78bdbb1137d87afad5&sid=TlG7spFxhWig3TpY
        /// &uin=243082945
        /// &deviceid=e835949820036438
        /// &synckey=1_653730215%7C2_653730255%7C3_653730169%7C1000_1501462441
        /// &_=1501479916949
        public static HttpTaskParams GetSyncCheckParams(string host, WxAccount wxAccount, WxSyncKey wxSyncKey)
        {
            HttpTaskParams htp = HttpTaskParams.NewGet(WxHttpApi.GetWebPushUrl(host, WxHttpApi.URL_WX_MSG_CHECK));

            htp.AddStringParam("skey", wxAccount.Skey);
            htp.AddStringParam("uin", wxAccount.Uin);
            htp.AddStringParam("sid", wxAccount.Sid);
            htp.AddStringParam("deviceid", wxAccount.DeviceId);
            htp.AddStringParam("synckey", WxReqUtil.GetSyncKey2String(wxSyncKey));
            long millis = TimeUtil.CurrentTimeMillis();

            htp.AddStringParam("r", millis.ToString());
            htp.AddStringParam("_", (millis / 1000).ToString());//时间戳取反
            return(htp);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 获取二维码图片请求
        /// </summary>
        /// <param name="uid"></param>
        /// <returns></returns>
        /// url->https://login.weixin.qq.com/qrcode/Ifv-J92fbw==
        public static HttpTaskParams GetLoginQrCodeParams(string uid)
        {
            string url = string.Format("{0}/{1}", WxHttpApi.GetLoginUrl(WxHttpApi.URL_LOGIN_QRCODE), uid);//uid不能encoding

            return(HttpTaskParams.NewGet(url));
        }
Ejemplo n.º 7
0
        public static string DownloadImage(string url, string floder, string starttxt = "")
        {
            if (!string.IsNullOrWhiteSpace(url))
            {
                try
                {
                    var format = ImageUtil.GetImageFormat(url);
                    if (format == ValidImageFormatEnum.NONE)
                    {
                        format = ValidImageFormatEnum.PNG;
                    }

                    var md5Str = starttxt + MD5Helper.GetCustomMD5(url);
                    lock (md5Str)
                    {
                        string fileName;
                        switch (format)
                        {
                        case ValidImageFormatEnum.JPEG:
                            fileName = md5Str + ".jpeg";

                            break;

                        case ValidImageFormatEnum.JPG:
                            fileName = md5Str + ".jpg";
                            break;

                        case ValidImageFormatEnum.PNG:
                            fileName = md5Str + ".png";
                            break;

                        default:
                            return(string.Empty);
                        }

                        var imagefloder = ApplicationManager.Instance.ApplicationData.CommonFloder + "\\Images\\" + floder;
                        if (!System.IO.Directory.Exists(imagefloder))
                        {
                            System.IO.Directory.CreateDirectory(imagefloder);
                        }
                        var tempfloder = ApplicationManager.Instance.ApplicationData.CommonFloder + "\\Temps\\" + floder;
                        if (!System.IO.Directory.Exists(tempfloder))
                        {
                            System.IO.Directory.CreateDirectory(tempfloder);
                        }

                        var imagefile    = imagefloder + "\\" + fileName;
                        var tmbimagefile = tempfloder + "\\" + fileName;

                        if (ImageUtil.IsImageExistes(imagefile))
                        {
                            // 正常显示图片才需要处理缩略图
                            if (string.IsNullOrWhiteSpace(starttxt) && !ImageUtil.IsImageExistes(tmbimagefile))
                            {
                                var bmp = new Bitmap(imagefile);
                                SaveClipImage(bmp, tmbimagefile);
                                bmp.Dispose();
                            }

                            return(fileName);
                        }

                        // 本地路径时不进行Http下载
                        if (!(new string(url.Take(0, 4).ToCharArray()).StartsWith("http")))
                        {
                            return(string.Empty);
                        }

                        var taskParams = HttpTaskParams.NewGet(url);
                        var httpTask   = new HttpTask(taskParams);
                        var bytes      = httpTask.ExecuteBytes();
                        if (bytes != null)
                        {
                            using (var ms = new MemoryStream(bytes))
                            {
                                bool issave = false;
                                var  bmp    = new Bitmap(ms);
                                try
                                {
                                    if (!File.Exists(imagefile))
                                    {
                                        bmp.Save(imagefile);
                                    }
                                    issave = true;
                                }
                                catch { }
                                if (!issave)
                                {
                                    SaveBytesToImage(bytes, imagefile);
                                }

                                SaveClipImage(bmp, tmbimagefile);
                            }
                            return(fileName);
                        }
                    }
                }
                catch { }
            }

            return(string.Empty);
        }