Ejemplo n.º 1
0
        private static void AddCache()
        {
            var  startTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
            long timeStamp = (long)(DateTime.Now - startTime).TotalSeconds;

            LocalCacheManager.Add("dynamic", new { userid = "*****@*****.**", pwd = "123456", uid = "jiangy", exp_in = timeStamp });
        }
Ejemplo n.º 2
0
        public static void Register()
        {
            IWeChatAppService         appService    = AutofacManager.Resolve <IWeChatAppService>();
            IApplicationConfigService configService = AutofacManager.Resolve <IApplicationConfigService>();
            var config = configService.ListApplicationConfig()
                         .FirstOrDefault(m => m.ConfigType.ToLower() == Constants.WECHAT.ToLower() && m.ConfigKey.ToLower() == Constants.CORP_ID.ToLower());

            LocalCacheManager.Add(Constants.CORP_ID, config.ConfigValue);

            List <WeChatAppConfig> apps = appService.ListApps();

            apps.ForEach(app =>
            {
                WeChatManager.RegisterWorkApp(config.ConfigValue, app.SecretValue, app.AppName);
            });
        }
Ejemplo n.º 3
0
        public void Initialize()
        {
            LocalCacheManager.Add(Constants.CORP_ID, "wx2e8cc6975a5fa1ce");
            var connstr = "server=.;database=dev;uid=sa;pwd=123456";
            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterType <WeChatAppService>().As <IWeChatAppService>();
            builder.RegisterType <ApplicationConfigService>().As <IApplicationConfigService>();
            builder.RegisterType <MemberService>().As <IMemberService>();
            builder.RegisterType <WeChatAppRepository>().As <IWeChatAppRepository>();
            builder.RegisterType <ApplicationConfigRepository>().As <IApplicationConfigRepository>();
            builder.RegisterType <CorpAppService>().As <ICorpAppService>();
            builder.RegisterInstance(EFContext.CreateForEFDesignTools(connstr));
            container = builder.Build();
            Register();
            AddCache();
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 消费临时code 换取微信应用信息
 /// </summary>
 /// <param name="code">临时授权码code</param>
 /// <param name="appcode">应用code</param>
 /// <param name="returnUrl">返回url</param>
 /// <returns></returns>
 public ActionResult ConsumeCode(string code, string appcode, string returnUrl = null)
 {
     try
     {
         User user = null;
         if (string.IsNullOrEmpty(appcode))
         {
             throw new ArgumentNullException(nameof(appcode));
         }
         var app         = _currentService.GetApp(appcode);
         var accessToken = AccessTokenContainer.GetToken(corpId, app.SecretValue);
         var result      = OAuth2Api.GetUserId(accessToken, code);
         if (!string.IsNullOrEmpty(result.OpenId))
         {
             //成员未关注该企业微信
             throw new Exception("成员未关注该企业微信");
         }
         else if (!string.IsNullOrEmpty(result.UserId))
         {
             //通过企业微信usesrid 换 业务系统账号密码
             user = _accountService.FindUserByWxUserID(result.UserId);
             if (user == null)
             {
                 //微信用户未绑定对应业务系统账号
                 return(RedirectToAction("login", "account", new { returnUrl, appcode, workUserId = result.UserId }));
             }
             else
             {
                 var nonceStr = Guid.NewGuid().ToString().Replace("-", "");
                 LocalCacheManager.Add(nonceStr, user);
                 //微信网页授权成功 准备获取企业应用授权
                 return(RedirectToAction("worklogin", "account", new { nonce = nonceStr, appcode, returnUrl }));
             }
         }
         else
         {
             throw new Exception(result.errmsg);
         }
     }
     catch (Exception ex)
     {
         return(RedirectToAction("error", "home", new { errmsg = ex.Message, appcode }));
     }
 }
Ejemplo n.º 5
0
 public void LocalCacheManager_Add_IsNotNull()
 {
     LocalCacheManager.Add("test", 1212);
     Console.WriteLine(LocalCacheManager.Get <int>("test"));
 }