Exemple #1
0
        protected virtual IDictionary <string, string> GenerateParameters(Options.IAppOption app, PushingSenderSettings settings)
        {
            var center = PushingServiceCenter.GetInstance(this.GetRegion(app));

            var dictionary = new Dictionary <string, string>()
            {
                //推送方式(高级推送)
                { "Action", "Push" },

                //以下是公共参数部分
                { "Format", "JSON" },
                { "RegionId", center.Alias },
                { "Version", "2016-08-01" },
                { "AccessKeyId", this.GetCertificate(app).Name },
                { "SignatureMethod", "HMAC-SHA1" },
                { "SignatureVersion", "1.0" },
                { "SignatureNonce", ((ulong)Zongsoft.Common.Randomizer.GenerateInt64()).ToString() },
                { "Timestamp", Utility.GetTimestamp() },

                //以下是推送接口特定参数
                { "AppKey", app.Code },
                { "PushType", settings.Type.ToString().ToUpperInvariant() },
                { "DeviceType", settings.DeviceType.ToString().ToUpperInvariant() },
                { "Target", settings.TargetType.ToString().ToUpperInvariant() },
            };

            if (settings.Expiry > 0)
            {
                dictionary["StoreOffline"] = "true";
                dictionary["ExpireTime"]   = DateTime.UtcNow.AddMinutes(settings.Expiry).ToString("s") + "Z";
            }

            return(dictionary);
        }
Exemple #2
0
        private ICertificate GetCertificate(Options.IAppOption app)
        {
            var certificate = app?.Certificate;

            if (string.IsNullOrWhiteSpace(certificate))
            {
                certificate = _configuration?.Certificate;
            }

            if (string.IsNullOrWhiteSpace(certificate))
            {
                return(Aliyun.Configuration.Instance.Certificates.Default);
            }

            return(Aliyun.Configuration.Instance.Certificates.Get(certificate));
        }
Exemple #3
0
 private ServiceCenterName GetRegion(Options.IAppOption app)
 {
     return(app?.Region ?? _configuration?.Region ?? Aliyun.Configuration.Instance.Name);
 }