Esempio n. 1
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;
        }
Esempio n. 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;
        }