Example #1
0
        /// <summary>
        /// 获取配置实体并解密
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        private List <IWXCorpInfo> GetCorpConfigs <T>(out string corpId, out string corpSecret)
            where T : WXConfigM, IWXCorpInfo
        {
            corpId     = string.Empty;
            corpSecret = string.Empty;

            EG.WeChat.Platform.DA.WXConfigDA pDA = new Platform.DA.WXConfigDA();
            DataTable dt = pDA.GetWXConfig();

            if (dt == null || dt.Rows.Count == 0)
            {
                return(null);
            }
            var plist = CommonFunction.GetEntitiesFromDataTable <T>(dt);

            if (plist.Count == 0)
            {
                return(null);
            }
            corpId     = plist[0].ACID;
            corpSecret = plist[0].ACSECRET;

            var pListOut = plist
                           .Where(p => p.aid != null && !string.IsNullOrEmpty(p.token) && !string.IsNullOrEmpty(p.aeskey))
                           .Select <T, IWXCorpInfo>(p => p as IWXCorpInfo).ToList();

            if (pListOut.Count == 0)
            {
                return(null);
            }
            return(pListOut);
        }
Example #2
0
 /// <summary>
 /// 更新企业号基础配置
 /// </summary>
 public void UpdateCorpConfiguration(int aid, string token, string aeskey)
 {
     this.ExecuteTryCatch(() =>
     {
         EG.WeChat.Platform.DA.WXConfigDA pDA = new Platform.DA.WXConfigDA();
         DataTable dt = pDA.GetWXConfig();
         if (dt == null || dt.Rows.Count == 0)
         {
             EGExceptionOperator.ThrowX <Exception>("缺少企業應用配置信息", EGActionCode.数据库表保存错误);
         }
         var plist = CommonFunction.GetEntitiesFromDataTable <WXConfigM>(dt);
         if (plist.Count == 0)
         {
             EGExceptionOperator.ThrowX <Exception>("缺少企業應用配置信息", EGActionCode.数据库表保存错误);
         }
         var pmodel = plist.Single(p => p.AID == aid && p.ACTYPE == 2);
         if (pmodel == null)
         {
             //Emperor.UtilityLib.CyberUtils.Decrypt("Aes", 256, base.TOKEN, WXConfigDA.FIELD_NAME_TOKEN);
         }
         else
         {
             pmodel.TOKEN  = Emperor.UtilityLib.CyberUtils.Encrypt("Aes", 256, token, WXConfigDA.FIELD_NAME_TOKEN);
             pmodel.AESKEY = Emperor.UtilityLib.CyberUtils.Encrypt("Aes", 256, aeskey, WXConfigDA.FIELD_NAME_AESKEY);
         }
         var ps = new List <WXConfigM>();
         ps.Add(pmodel);
         DataTable dto = CommonFunction.GetDataTableFromEntities <WXConfigM>(ps);
         if (pDA.SetWXConfig(dto))
         {
             WeiXinConfiguration.corpInfos.ForEach((p) =>
             {
                 if (p.aid == aid)
                 {
                     p.token  = token;
                     p.aeskey = aeskey;
                 }
             });
         }
         else
         {
             EGExceptionOperator.ThrowX <Exception>("缺少企業應用配置信息", EGActionCode.数据库表保存错误);
         }
     });
 }