Senparc.Weixin.MP SDK 微信公众平台开发--自定义菜单相关
public virtual IResponseMessageBase OnImageRequest(RequestMessageImage requestMessage);
public virtual IResponseMessageBase OnLinkRequest(RequestMessageLink requestMessage);
public virtual IResponseMessageBase OnLocationRequest(RequestMessageLocation requestMessage);
public virtual IResponseMessageBase OnTextRequest(RequestMessageText requestMessage);
public virtual IResponseMessageBase OnVoiceRequest(RequestMessageVoice requestMessage);
public virtual IResponseMessageBase OnVideoRequest(RequestMessageVideo requestMessage);
上面的是输入框的请求返回。
public virtual IResponseMessageBase OnEvent_ClickRequest(RequestMessageEvent_Click requestMessage);
public virtual IResponseMessageBase OnEvent_ViewRequest(RequestMessageEvent_View requestMessage);
public virtual IResponseMessageBase OnEvent_EnterRequest(RequestMessageEvent_Enter requestMessage);
public virtual IResponseMessageBase OnEvent_LocationRequest(RequestMessageEvent_Location requestMessage);
public virtual IResponseMessageBase OnEvent_SubscribeRequest(RequestMessageEvent_Subscribe requestMessage);
public virtual IResponseMessageBase OnEvent_UnsubscribeRequest(RequestMessageEvent_Unsubscribe requestMessage);
public virtual IResponseMessageBase OnEvent_ScanRequest(RequestMessageEvent_Scan requestMessage)
public virtual IResponseMessageBase OneEvent_MassSendJobFinisRequest(RequestMessageEvent_MassSendJobFinish requestMessage)
这里是菜单按钮的事件返回。
我们可以直接重写这两个方法。其中OnExecuting会在所有消息处理方法(如OnTextRequest,OnVoiceRequest等)执行之前执行,这个过程中,我们可以把CancelExecute设为true,来中断后面所有方法的执行(包括OnExecuted),例如:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
public override void OnExecuting() { if (RequestMessage.FromUserName == "olPjZjsXuQPJoV0HlruZkNzKc91E" ) { CancelExcute = true ; //终止此用户的对话 //如果没有下面的代码,用户不会收到任何回复,因为此时ResponseMessage为null //添加一条固定回复 var responseMessage = CreateResponseMessage<ResponseMessageText>(); responseMessage.Content = "Hey!你已经被拉黑啦!" ; ResponseMessage = responseMessage; //设置返回对象 } } |
如果OnExecuting中没有中断,当例如OnTextRequest方法执行完毕之后(或执行了默认方法),OnExecuted()方法将会触发,我们也可以对应地重写。要注意的是,在OnExecuted()方法内,ResponseMessage已经被赋了返回值。