Exemplo n.º 1
0
        public ActionResult Index()
        {
            //ParkCarDerateServices.QueryBySellerIdAndIORecordId("46f54c5e-ada9-4efe-9552-a8560130a960", "6fe28c13-716a-48d1-b1ba-a8ee00061572");
            //string geng = Server.MapPath("~/TempFile/20180526");
            //string savepath = Server.MapPath("~/TempFile/201805263.zip");
            //ZipHelper.ZipFiles(geng, savepath);

            Stopwatch watch = Stopwatch.StartNew();//创建一个监听器

            for (var i = 0; i <= 100; i++)
            {
                TxtLogServices.WriteTxtLogEx("Test", "开始");
                var user = WeiXinAccountService.QueryWXByOpenId("oussCwE6unIvKaG-1wec-B7n3J0Q");
                //DateTime ts2 = DateTime.Now;
                //TimeSpan ts3 = ts1.Subtract(ts2).Duration();
                TxtLogServices.WriteTxtLogEx("Test", "结束");
                Thread.Sleep(10000);

                //DateTime ts1 = DateTime.Now;

                //var user = WeiXinAccountService.QueryWXByOpenId("oussCwE6unIvKaG-1wec-B7n3J0Q");
                ////DateTime ts2 = DateTime.Now;
                ////TimeSpan ts3 = ts1.Subtract(ts2).Duration();
                //TxtLogServices.WriteTxtLogEx("Test", watch.ElapsedMilliseconds.ToString());
                //Thread.Sleep(10000);
            }
            watch.Stop();

            var    redirectUrl    = "http://park.xinfu.info/r/ParkingPayment_Index_moduleid=2^cid=f50a5dee-d098-4100-a370-a7ca017ab4cf";
            string strRedirectUrl = HttpUtility.UrlEncode(redirectUrl);
            //WXApiConfigServices.QueryWXApiConfig
            //WX_ApiConfig confing = WXApiConfigServices.QueryWXApiConfig("83495fa0-611f-497a-9e10-a78c009f66cd");
            string s = string.Empty;

            //cd1e590c-e91e-45f7-b7d6-a75300e652a9^pn=ÔÁB88765
            //byte[] result = WXQRCodeServices.GenerateByteQRCode("http://ykt.bsgoal.net.cn", "cd1e590c-e91e-45f7-b7d6-a75300e652a9", "粤B88765", 430, "");
            //System.IO.MemoryStream ms = new System.IO.MemoryStream(result);
            //System.Drawing.Image img = System.Drawing.Image.FromStream(ms);

            //string filePath = string.Format("/Uploads/QRCode/{0}.{1}", "test111111111", "jpg");
            //string absolutePath = System.Web.HttpContext.Current.Server.MapPath(filePath);
            //img.Save(absolutePath, ImageFormat.Jpeg);

            //DateTime t1 = DateTime.Now.AddMinutes(-10).AddSeconds(-2);
            //DateTime t2 = DateTime.Now;
            //string s = t1.GetParkingDuration(t2);
            //string s = "1   2 34  5566".PlateNumberToUpper();
            //JsonObject obj = new JsonObject();

            //PlatformOrderBLL.ManualRefund(123123, "");
            //string v = XmlConfig.GetValue("PromptAttentionPage");
            //string openid = "odvkywSnlKr8anm3ddoIcredwvN0";
            //string url = "http://wx.qlogo.cn/mmopen/gKlic31XKbJ7BOJyEvicpgpW0ym5rfqGS0ibBSWLVOlDaSm4QZ1vCqEAxKohVtuj3fEn1vHfia6Y4fXEN9zXhxrhuRmMgoELyBll/0";
            //WeiXinBaseInfo.DownloadHeadImg(openid, url);
            //RoutematrixService.GetRoutematrix("113.977295", "22.731472", "113.687295", "22.761472");
            //List<BaseParkinfo> parks = QueryParkingService.QueryParkinfo("22.735069".ToDouble(), "113.988769".ToDouble(), 4000);
            //WX_ApiConfig config = GetApiConfig("moduleid=2^cid=0642cbb1-d55d-4629-855d-a73c0100397b");
            return(View());
        }
Exemplo n.º 2
0
 public override void OnExecuting()
 {
     try
     {
         user = WeiXinAccountService.QueryWXByOpenId(OpenId);
         if (user == null || (WxUserState)user.FollowState == WxUserState.UnAttention)
         {
             bool IsNewAdd = user == null;
             user = WxUserInfo.GetWxUserBaseInfo(config, OpenId);
             if (user == null)
             {
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", "拉取微信用户信息失败,OPENID:{0}", OpenId);
                 return;
             }
             user.OpenID      = OpenId;
             user.UserType    = 0;
             user.FollowState = (int)WxUserState.Attention;
             user.CompanyID   = config.CompanyID;
             bool result = false;
             if (IsNewAdd)
             {
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", "RegisterAccount");
                 result = WeiXinAccountService.RegisterAccount(user);
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", string.Format("RegisterAccount Result:{0}", result ? "1" : "0"));
             }
             else
             {
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", "EditWXInfo");
                 result = WeiXinAccountService.EditWXInfo(user);
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", string.Format("EditWXInfo Result:{0}", result ? "1" : "0"));
             }
             if (result)
             {
                 user = WeiXinAccountService.QueryWXByOpenId(OpenId);
             }
             string resultDes = result ? "成功" : "失败";
             TxtLogServices.WriteTxtLogEx("WeiXinConversation", "保存微信用户信息{0},OPENID:{1}", resultDes, OpenId);
         }
         else
         {
             //每7天或头像为空时更新一次微信用户信息
             if (user.LastSubscribeDate < DateTime.Now.AddDays(-7) || string.IsNullOrWhiteSpace(user.Headimgurl))
             {
                 WX_Info newUser = WxUserInfo.GetWxUserBaseInfo(config, OpenId);
                 if (newUser == null)
                 {
                     TxtLogServices.WriteTxtLogEx("WeiXinConversation", "更新时拉取微信用户信息失败,OPENID:{0}", OpenId);
                     return;
                 }
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", "Update");
                 newUser.AccountID = user.AccountID;
                 newUser.OpenID    = OpenId;
                 newUser.UserType  = 0;
                 newUser.CompanyID = config.CompanyID;
                 bool result = WeiXinAccountService.EditWXInfo(newUser);
                 TxtLogServices.WriteTxtLogEx("WeiXinConversation", string.Format("Update Result:{0}", result ? "1" : "0"));
             }
         }
     }
     catch (Exception ex) {
         ExceptionsServices.AddExceptions(ex, string.Format("创建微信账号或者更新微信账号信息失败,OPENID:{0}", OpenId), LogFrom.WeiXin);
         TxtLogServices.WriteTxtLogEx("WeiXinConversation", ex);
     }
 }
Exemplo n.º 3
0
        public ActionResult Index(string id, string code, string state)
        {
            try
            {
                ClearSystemCache();
                WX_ApiConfig config = GetApiConfig(id);
                if (config == null || string.IsNullOrWhiteSpace(config.AppId) || string.IsNullOrWhiteSpace(config.AppSecret) ||
                    string.IsNullOrWhiteSpace(config.Domain) || string.IsNullOrWhiteSpace(config.SystemName))
                {
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取微信基础信息失败" }));
                }
                if (!config.Status)
                {
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "该公众账号暂停使用,请稍后再试!" }));
                }
                Session["CurrLoginWeiXinApiConfig"] = config;
                if (string.IsNullOrEmpty(id))
                {
                    id = "ParkingPayment_Index";
                }
                if (Request.UserAgent != null && !Request.UserAgent.ToLower().Contains("micromessenger"))
                {
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "请在微信中打开" }));
                }
                if (string.IsNullOrEmpty(state))
                {
                    var redirectUri = config.Domain;
                    if (string.IsNullOrWhiteSpace(redirectUri))
                    {
                        return(RedirectToAction("Index", "ErrorPrompt", new { message = "获取域名配置信息失败" }));
                    }
                    if (redirectUri != null)
                    {
                        redirectUri = redirectUri.IndexOf("http://", StringComparison.Ordinal) < 0 ? string.Format("http://{0}", redirectUri) : redirectUri;
                        redirectUri = string.Format("{0}/r/{1}", redirectUri, id);
                    }
                    TxtLogServices.WriteTxtLogEx("RedirectHandle", "获取微信OpenId请求redirectUri:{0}", redirectUri);
                    string url = WxAdvApi.GetAuthorizeUrl(config.AppId, redirectUri, "1", OAuthScope.snsapi_base);
                    TxtLogServices.WriteTxtLogEx("RedirectHandle", "获取微信OpenId请求url:{0}", url);
                    return(Redirect(url));
                }
                TxtLogServices.WriteTxtLogEx("RedirectHandle", "state不为空进入,id:{0}, code:{1}, state:{2}", id, code, state);
                if (string.IsNullOrEmpty(code))
                {
                    return(RedirectToAction("Index", "ErrorPrompt", new { message = "微信获取授权失败,请重新进入或请联系管理员" }));
                }

                var accessToken = WxAdvApi.GetAccessToken(config.AppId, config.AppSecret, code);
                TxtLogServices.WriteTxtLogEx("RedirectHandle", "调用微信的AccessToken接口:openid:{0}, access_token:{1}", accessToken.openid, accessToken.access_token);
                var    user = WeiXinAccountService.QueryWXByOpenId(accessToken.openid);
                string s    = user == null ? "user is null" : "user is not null";
                TxtLogServices.WriteTxtLogEx("RedirectHandle", s);
                if (user != null)
                {
                    TxtLogServices.WriteTxtLogEx("RedirectHandle", "关注状态:{0}", ((WxUserState)user.FollowState).GetDescription());
                }
                if (user == null || (WxUserState)user.FollowState == WxUserState.UnAttention)
                {
                    return(RedirectAttentionPage(config.CompanyID, "请先关注公众账号"));
                }
                //添加登陆
                Response.Cookies.Add(new HttpCookie("SmartSystem_WeiXinOpenId", accessToken.openid));
                TxtLogServices.WriteTxtLogEx("RedirectHandle", "获取OpenId成功:openid:{0}", accessToken.openid);
                //登录APP
                string     openId = accessToken.openid;
                string     sToken = "";
                VerifyCode verify = wxApi.getThirdLogin(openId, openId); //第三方登录
                TxtLogServices.WriteTxtLogEx("RedirectHandle", "APP用户自动登录,id:{0},Status:{1} ", openId, verify.Status);
                if (verify.Status == 1)
                {
                    TxtLogServices.WriteTxtLogEx("RedirectHandle", "APP用户自动登录成功,id:{0},Status:{1} ", openId, verify.Result);

                    sToken       = verify.Result;
                    AppUserToken = sToken; //渠道TOKEN了
                    //    //获取用户的信息
                    //    ClassLibrary1.PurseData.UserInfo appUser = wxApi.getUserInfo(sToken);
                    //    if (appUser != null && appUser.Status == 1)
                    //    {

                    //        TxtLogServices.WriteTxtLogEx("RedirectHandle", "APP用户,获取用户信息成功,id:{0},Status:{1} ", openId, appUser.Result.Phone);
                    //        AppUserPhone = appUser.Result.Phone;
                    //    }
                    //    else
                    //    {
                    //        TxtLogServices.WriteTxtLogEx("RedirectHandle", "APP用户,获取用户信息失败,id:{0},Status:{1} ", openId, appUser.Status);
                    //    }
                }
                else if (verify.Status == 2)
                {
                    TxtLogServices.WriteTxtLogEx("RedirectHandle", "APP用户自动登录失败,未绑定,id:{0},Status:{1} ", openId, verify.Result);
                    //未绑定
                    AppUserToken = "-1";
                }
                else
                {
                    //其他都是失败
                    AppUserToken = "";
                    sToken       = "";
                    TxtLogServices.WriteTxtLogEx("RedirectHandle", "APP用户自动登录失败,id:{0},Status:{1} ", openId, verify.Result);
                }

                return(Redir(id, accessToken.openid));
            }
            catch (MyException ex) {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "id:" + id, ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = ex.Message }));
            }
            catch (Exception ex)
            {
                ExceptionsServices.AddExceptionToDbAndTxt("WeiXinPageError", "RedirectHandle方法处理异常", ex, LogFrom.WeiXin);
                return(RedirectToAction("Index", "ErrorPrompt", new { message = "跳转链接失败" }));
            }
        }