コード例 #1
0
ファイル: BaseReply.cs プロジェクト: Tar-Palantir/TPS-Project
        public static BaseReply ConvertReply(IDictionary<string, string> dicParams, Reply reply)
        {
            if (!dicParams.ContainsKey("ToUserName")) throw new Exception("没有获取到ToUserName");
            if (!dicParams.ContainsKey("FromUserName")) throw new Exception("没有获取到FromUserName");

            if (reply == null)
            {
                return null;
            }

            BaseReply returnReply;
            switch (reply.Message.Type)
            {
                case (int)EnumReplyType.TextReply:
                    returnReply = new TextReply { Content = reply.Message.Content };
                    break;
                case (int)EnumReplyType.ArticleReply:
                    returnReply = new ArticleReply
                    {
                        Articles = JsonConvert.DeserializeObject<List<ArticleReplyItem>>(reply.Message.Content)
                    };
                    break;
                default:
                    return null;
            }

            returnReply.FromUserName = dicParams["ToUserName"];
            returnReply.ToUserName = dicParams["FromUserName"];
            return returnReply;
        }
コード例 #2
0
ファイル: CReceive.cs プロジェクト: Tar-Palantir/TPS-Project
        private string GetResponseForText(Account currentAccount, Dictionary<string, string> dicParams)
        {
            if (!dicParams.ContainsKey("ToUserName")) throw new Exception("没有获取到ToUserName");
            if (!dicParams.ContainsKey("FromUserName")) throw new Exception("没有获取到FromUserName");
            if (!dicParams.ContainsKey("Content")) throw new Exception("没有获取到Content");

            var replyRepository = new ReplyRepository();
            Reply reply = replyRepository.GetReply(currentAccount.ID, dicParams["Content"], EnumKeyType.Keyword);

            BaseReply returnReply;
            switch (reply.Message.Type)
            {
                case (int)EnumReplyType.TextReply:
                    returnReply = new TextReply { Content = reply.Message.Content };
                    break;
                case (int)EnumReplyType.ArticleReply:
                    returnReply = new ArticleReply
                    {
                        Articles = JsonConvert.DeserializeObject<List<ArticleReplyItem>>(reply.Message.Content)
                    };
                    break;
                default:
                    return null;
            }

            returnReply.FromUserName = dicParams["ToUserName"];
            returnReply.ToUserName = dicParams["FromUserName"];

            return returnReply.GetXmlString();
        }