Example #1
0
        /// <summary>
        /// The ReadJson
        /// </summary>
        /// <param name="reader">The reader<see cref="JsonReader"/></param>
        /// <param name="objectType">The objectType<see cref="Type"/></param>
        /// <param name="existingValue">The existingValue<see cref="object"/></param>
        /// <param name="serializer">The serializer<see cref="JsonSerializer"/></param>
        /// <returns>The <see cref="object"/></returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue,
                                        JsonSerializer serializer)
        {
            if (reader.TokenType == JsonToken.Null)
            {
                return(null);
            }
            var jObject = JObject.Load(reader);
            var target  = default(CustomMessageSendApiResultBase);
            //获取type属性
            var type = jObject.Property("msgtype");

            if (type != null && type.Count > 0)
            {
                var typeValue = type.Value.ToString();
                var msgType   = (MessageTypes)Enum.Parse(typeof(MessageTypes), typeValue);


                switch (msgType)
                {
                case MessageTypes.text:
                    target = new TextMessage();
                    break;

                case MessageTypes.image:
                    target = new ImageMessage();
                    break;

                case MessageTypes.voice:
                    target = new VoiceMessage();
                    break;

                case MessageTypes.video:
                    target = new VideoMessage();
                    break;

                case MessageTypes.music:
                    target = new MusicMessage();
                    break;

                case MessageTypes.news:
                    target = new NewsMessage();
                    break;

                case MessageTypes.mpnews:
                    target = new MpNewsMessage();
                    break;

                case MessageTypes.wxcard:
                    target = new WxCardMessage();
                    break;

                default:
                    throw new NotSupportedException("不支持此类型:" + msgType);
                }
            }

            serializer.Populate(jObject.CreateReader(), target);
            return(target);
        }
Example #2
0
 /// <summary>
 ///     发送图片消息
 /// </summary>
 /// <param name="message"></param>
 /// <returns></returns>
 public ApiResult SendImageMessage(ImageMessage message)
 {
     return(Send(message));
 }