Пример #1
0
        /// <summary>
        /// 注册消息处理委托
        /// </summary>
        /// <param name="msgType">消息类型</param>
        /// <param name="func"></param>
        public static ResultMo RegisteProcessor<TRecMsg>(string msgType, Func<TRecMsg, WxBaseReplyMsg> func)
            where TRecMsg : WxBaseRecMsg, new()
        {
            var key = msgType.ToLower();
            if (processorDirs.ContainsKey(key))
                return new ResultMo(ResultTypes.ObjectExsit, "已存在相同的消息处理类型!");

            var handler = new WxMsgProcessor<TRecMsg> { ProcessFunc = func };
            return processorDirs.TryAdd(key, handler)
                ? new ResultMo()
                : new ResultMo(ResultTypes.ObjectExsit, "注册消息处理句柄失败!");
        }
Пример #2
0
        internal override WxMsgProcessor GetBasicMsgProcessor(string msgType, string eventName)
        {
            switch (msgType.ToLower())
            {
            case "event":
                return(GetBasicEventMsgProcessor(eventName));

            case "text":
                return(textPro ?? (textPro = new WxMsgProcessor <WxTextRecMsg> {
                    RecInsCreater = () => new WxTextRecMsg(), ProcessFunc = ProcessTextMsg
                }));

            case "image":
                return(imagePro ?? (imagePro = new WxMsgProcessor <WxImageRecMsg> {
                    RecInsCreater = () => new WxImageRecMsg(), ProcessFunc = ProcessImageMsg
                }));

            case "voice":
                return(voicePro ?? (voicePro = new WxMsgProcessor <WxVoiceRecMsg> {
                    RecInsCreater = () => new WxVoiceRecMsg(), ProcessFunc = ProcessVoiceMsg
                }));

            case "video":
                return(videoPro ?? (videoPro = new WxMsgProcessor <WxVideoRecMsg> {
                    RecInsCreater = () => new WxVideoRecMsg(), ProcessFunc = ProcessVideoMsg
                }));

            case "shortvideo":
                return(shortVideoPro ?? (shortVideoPro = new WxMsgProcessor <WxVideoRecMsg> {
                    RecInsCreater = () => new WxVideoRecMsg(), ProcessFunc = ProcessShortVideoMsg
                }));

            case "location":
                return(locationPro ?? (locationPro = new WxMsgProcessor <WxLocationRecMsg> {
                    RecInsCreater = () => new WxLocationRecMsg(), ProcessFunc = ProcessLocationMsg
                }));

            case "link":
                return(linkPro ?? (linkPro = new WxMsgProcessor <WxLinkRecMsg> {
                    RecInsCreater = () => new WxLinkRecMsg(), ProcessFunc = ProcessLinkMsg
                }));
            }
            return(null);
        }
Пример #3
0
        private WxMsgProcessor GetBasicEventMsgProcessor(string eventName)
        {
            switch (eventName)
            {
            case "subscribe":
                return(subEventPro ?? (subEventPro = new WxMsgProcessor <WxSubScanRecEventMsg> {
                    RecInsCreater = () => new WxSubScanRecEventMsg(), ProcessFunc = ProcessSubscribeEventMsg
                }));

            case "unsubscribe":
                return(unsubEventPro ?? (unsubEventPro = new WxMsgProcessor <WxSubScanRecEventMsg> {
                    RecInsCreater = () => new WxSubScanRecEventMsg(), ProcessFunc = ProcessUnsubscribeEventMsg
                }));

            case "scan":
                return(scanEventPro ?? (scanEventPro = new WxMsgProcessor <WxSubScanRecEventMsg> {
                    RecInsCreater = () => new WxSubScanRecEventMsg(), ProcessFunc = ProcessScanEventMsg
                }));

            case "location":
                return(locationEventPro ?? (locationEventPro = new WxMsgProcessor <WxLocationRecEventMsg> {
                    RecInsCreater = () => new WxLocationRecEventMsg(), ProcessFunc = ProcessLocationEventMsg
                }));

            case "click":
                return(clickEventPro ?? (clickEventPro = new WxMsgProcessor <WxClickRecEventMsg> {
                    RecInsCreater = () => new WxClickRecEventMsg(), ProcessFunc = ProcessClickEventMsg
                }));

            case "view":
                return(viewEventPro ?? (viewEventPro = new WxMsgProcessor <WxViewRecEventMsg> {
                    RecInsCreater = () => new WxViewRecEventMsg(), ProcessFunc = ProcessViewEventMsg
                }));
            }
            return(null);
        }