/// <summary> /// 创建服务 /// </summary> /// <param name="messageContext">上下文对象</param> public static ResponseService_ConfigurationSupport CreateOrGetService(CustomMessageContext messageContext) { //创建实例 ResponseService_ConfigurationSupport result = ResponseService.CreateOrGetService <ResponseService_ConfigurationSupport>(messageContext) as ResponseService_ConfigurationSupport; return(result); }
public NormalWxResponse SendWeChatMessage(IWxApp official, string openid, string text) { var data = new CustomMessageContext() { MsgType = "text", Text = new CustomMessageContent() { Content = text }, ToUser = openid }; var url = $"https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={this.GetToken(official.AppId, official.Secret)}"; return(url.GetUriJsonContent <NormalWxResponse>((http) => { http.Method = "POST"; http.ContentType = "application/json; encoding=utf-8"; using (var stream = http.GetRequestStream()) { var body = data.SerializeToJson(); var buffers = UTF8Encoding.UTF8.GetBytes(body); stream.Write(buffers, 0, buffers.Length); stream.Flush(); } return http; })); }
/// <summary> /// 创建服务 /// </summary> /// <param name="messageContext">上下文对象</param> /// <param name="createServicFunction">外部方法</param> public static ResponseService_MemorySupport CreateOrGetService(CustomMessageContext messageContext, Func <string, NodeInstanceService> createServicFunction) { //参数检查 if (createServicFunction == null) { throw new ArgumentNullException("createServicFunction"); } //创建实例 ResponseService_MemorySupport result = ResponseService.CreateOrGetService <ResponseService_MemorySupport>(messageContext) as ResponseService_MemorySupport; result.CreateServicFunction = createServicFunction; return(result); }
/// <summary> /// 获取或创建服务实例(线程安全) /// </summary> /// <param name="messageContext">上下文对象</param> /// <returns>服务对象</returns> protected static ResponseService CreateOrGetService <T_ResponseService>(CustomMessageContext messageContext) where T_ResponseService : ResponseService { const string DataName = "ResponseChainInstance"; ResponseService result; /* 需要处理: messageContext.ContextDatas,外部的读写是无限制的。。。 */ lock (locker) { if (messageContext.ContextDatas[DataName] != null && messageContext.ContextDatas[DataName] is ResponseService ) { result = messageContext.ContextDatas[DataName] as ResponseService; } else { //创建 messageContext.ContextDatas[DataName] = result = Activator.CreateInstance <T_ResponseService>(); } } return(result); }
private async Task <Ack> CreateEducationHandler(CreateEducation arg, CustomMessageContext messageContext) { this._logger.LogInformation("Create education handler. {@Payload}, {@MessageContext}", arg, messageContext); return(new Ack()); }