예제 #1
0
        internal static WeixinXml GetWeixinXml(string weixinXml)
        {
            WeixinXml xml = new WeixinXml();

            xml.ReadXmlFromFile(weixinXml);
            return(xml);
        }
예제 #2
0
        internal WeixinSettings(WeixinXml xml)
        {
            AppId = xml.Weixin.AppId;
            LogRawMessage = xml.Weixin.LogRawMessage;
            WeixinPath = Path.GetDirectoryName(xml.FullPath);
            UseLogOnRight = xml.Weixin.UseLogOnRight;

            WeixinNormalConfig normalConfig = xml.Weixin.Normal;
            if (normalConfig != null)
            {
                Mode = WeixinMode.Normal;
                OpenId = normalConfig.OpenId;
                fAppSecret = normalConfig.Secret;
                fToken = normalConfig.Token;
                MessageMode = normalConfig.MessageMode;
                EncodingAESKey = normalConfig.EncodingAESKey;
                fTemplateMessages = normalConfig.TemplateMessages;
                PaymentConfigItem pay = normalConfig.Pay;
                if (pay != null)
                {
                    fUsePay = true;
                    fMchId = pay.MchId;
                    fPayKey = pay.Key;
                    fDeviceInfo = pay.DeviceInfo;
                    fDeviceIp = pay.DeviceIp;
                    fPayNotifyUrl = UriUtil.CombineUri(pay.NotifyBaseUrl, pay.NotifyUrl).ToString();
                }
                WeixinServiceConfigItem service = normalConfig.Service;
                if (service != null)
                {
                    fEnableService = service.Enabled;
                    fWeixinAccount = service.WeixinAccount;
                }
                else
                    fEnableService = false;

                if (MessageMode != MessageMode.Normal)
                    TkDebug.AssertArgumentNullOrEmpty(EncodingAESKey,
                        "当消息是混合或者安全模式时,请配置EncodingAESKey的内容", xml);
            }
            else if (xml.Weixin.CorpApps != null)
            {
                Mode = WeixinMode.Corporation;
                fCorpApps = xml.Weixin.CorpApps;
                TkDebug.Assert(fCorpApps.Count > 0,
                    "至少需要配置一个tk:CorpApp节点", xml);
                CorpSecretConfig corpSecret = xml.Weixin.CorpSecret;
                TkDebug.AssertNotNull(corpSecret, "需要配置tk:CorpSecret节点", xml);
                fCorpUserManagerSecret = corpSecret.UserManager;
                fCorpMenuSecret = corpSecret.Menu;
                if (string.IsNullOrEmpty(fCorpMenuSecret))
                    fCorpMenuSecret = fCorpUserManagerSecret;
                OpenId = AppId;
            }
            else
                TkDebug.ThrowImpossibleCode(xml);
            fCurrent = this;
        }
 public void AppStarting(object application, BaseAppSetting appsetting,
     BaseGlobalVariable globalVariable)
 {
     string path = Path.Combine(appsetting.XmlPath, "weixin.xml");
     if (File.Exists(path))
     {
         WeixinXml xml = new WeixinXml();
         xml.ReadXmlFromFile(path);
         WeixinSettings.Current = new WeixinSettings(xml);
         if (WeixinSettings.Current.Mode == WeixinMode.Normal)
         {
             AccessToken.LoadToken();
             JsAccessToken.LoadToken();
         }
         else
         {
             CorpAccessTokenList.LoadToken();
         }
     }
 }
예제 #4
0
        public void AppStarting(object application, BaseAppSetting appsetting,
                                BaseGlobalVariable globalVariable)
        {
            string path = Path.Combine(appsetting.XmlPath, "weixin.xml");

            if (File.Exists(path))
            {
                WeixinXml xml = new WeixinXml();
                xml.ReadXmlFromFile(path);
                WeixinSettings.Current = new WeixinSettings(xml);
                if (WeixinSettings.Current.Mode == WeixinMode.Normal)
                {
                    AccessToken.LoadToken();
                    JsAccessToken.LoadToken();
                }
                else
                {
                    CorpAccessTokenList.LoadToken();
                }
            }
        }
예제 #5
0
        internal WeixinSettings(WeixinXml xml)
        {
            AppId         = xml.Weixin.AppId;
            LogRawMessage = xml.Weixin.LogRawMessage;
            WeixinPath    = Path.GetDirectoryName(xml.FullPath);
            UseLogOnRight = xml.Weixin.UseLogOnRight;

            WeixinNormalConfig normalConfig = xml.Weixin.Normal;

            if (normalConfig != null)
            {
                Mode              = WeixinMode.Normal;
                OpenId            = normalConfig.OpenId;
                fAppSecret        = normalConfig.Secret;
                fToken            = normalConfig.Token;
                MessageMode       = normalConfig.MessageMode;
                EncodingAESKey    = normalConfig.EncodingAESKey;
                fTemplateMessages = normalConfig.TemplateMessages;
                PaymentConfigItem pay = normalConfig.Pay;
                if (pay != null)
                {
                    fUsePay       = true;
                    fMchId        = pay.MchId;
                    fPayKey       = pay.Key;
                    fDeviceInfo   = pay.DeviceInfo;
                    fDeviceIp     = pay.DeviceIp;
                    fPayNotifyUrl = UriUtil.CombineUri(pay.NotifyBaseUrl, pay.NotifyUrl).ToString();
                }
                WeixinServiceConfigItem service = normalConfig.Service;
                if (service != null)
                {
                    fEnableService = service.Enabled;
                    fWeixinAccount = service.WeixinAccount;
                }
                else
                {
                    fEnableService = false;
                }

                if (MessageMode != MessageMode.Normal)
                {
                    TkDebug.AssertArgumentNullOrEmpty(EncodingAESKey,
                                                      "当消息是混合或者安全模式时,请配置EncodingAESKey的内容", xml);
                }
            }
            else if (xml.Weixin.CorpApps != null)
            {
                Mode      = WeixinMode.Corporation;
                fCorpApps = xml.Weixin.CorpApps;
                TkDebug.Assert(fCorpApps.Count > 0,
                               "至少需要配置一个tk:CorpApp节点", xml);
                CorpSecretConfig corpSecret = xml.Weixin.CorpSecret;
                TkDebug.AssertNotNull(corpSecret, "需要配置tk:CorpSecret节点", xml);
                fCorpUserManagerSecret = corpSecret.UserManager;
                fCorpMenuSecret        = corpSecret.Menu;
                if (string.IsNullOrEmpty(fCorpMenuSecret))
                {
                    fCorpMenuSecret = fCorpUserManagerSecret;
                }
                OpenId = AppId;
            }
            else
            {
                TkDebug.ThrowImpossibleCode(xml);
            }
            fCurrent = this;
        }