public Task EncodeAsync(object instance, Type type, GoRequest request)
        {
            if (!(instance is DingTalkMessage dingTalkMessage))
            {
                return(Task.CompletedTask);
            }

            var messageType = dingTalkMessage.Type.ToString();

            messageType = messageType[0].ToString().ToLower() + messageType.Substring(1);
            var propertyName = messageType;

            var dictionary = new
                             Dictionary <string, object>
            {
                { "msgtype", messageType },
                { propertyName, instance }
            };

            if (instance is IAtMessage atMessage)
            {
                dictionary["at"] = new
                {
                    atMobiles = atMessage.AtMobiles,
                    isAtAll   = atMessage.IsAtAll
                };
            }

            var json = JsonConvert.SerializeObject(dictionary, SerializerSettings);

            request.Body(json, "application/json");

            return(Task.CompletedTask);
        }
Beispiel #2
0
        public Task EncodeAsync(object instance, Type type, GoRequest request)
        {
            if (instance is UserModel user && !string.IsNullOrEmpty(user.Password))
            {
                user.Password = Convert.ToBase64String(Encoding.UTF8.GetBytes(user.Password));

                request.Body(JsonConvert.SerializeObject(user));
            }

            return(Task.CompletedTask);
        }
Beispiel #3
0
            public Task EncodeAsync(object instance, Type type, GoRequest request)
            {
                if (instance == null)
                {
                    return(Task.CompletedTask);
                }

                using (var sw = new StringWriter())
                {
                    _jsonSerializer.Serialize(sw, instance, type);

                    request.Body(sw.ToString(), "application/json");
                }

                return(Task.CompletedTask);
            }