/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <returns></returns> public static WxJsonResult Send(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST) { return(Send <WxJsonResult>(accessToken, urlFormat, data, sendType)); }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="sendType"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <param name="checkValidationResult"></param> /// <param name="jsonSetting"></param> /// <returns></returns> public static WxJsonResult Send(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = CO2NET.Config.TIME_OUT, bool checkValidationResult = false, JsonSetting jsonSetting = null) { return(Send <WxJsonResult>(accessToken, urlFormat, data, sendType, timeOut, checkValidationResult, jsonSetting)); }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <returns></returns> public static async Task <WxJsonResult> SendAsync(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT) { return(await SendAsync <WxJsonResult>(accessToken, urlFormat, data, sendType, timeOut)); }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null。在POST方式中将被转为JSON字符串提交</param> /// <param name="sendType">发送类型,POST或GET,默认为POST</param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <param name="checkValidationResult">验证服务器证书回调自动验证</param> /// <param name="jsonSetting">JSON字符串生成设置</param> /// <returns></returns> public static async Task <T> SendAsync <T>(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT, bool checkValidationResult = false, JsonSetting jsonSetting = null ) { try { var url = string.IsNullOrEmpty(accessToken) ? urlFormat : string.Format(urlFormat, accessToken.AsUrlData()); switch (sendType) { case CommonJsonSendType.GET: return(await Get.GetJsonAsync <T>(url)); case CommonJsonSendType.POST: SerializerHelper serializerHelper = new SerializerHelper(); var jsonString = serializerHelper.GetJsonString(data, jsonSetting); using (MemoryStream ms = new MemoryStream()) { var bytes = Encoding.UTF8.GetBytes(jsonString); await ms.WriteAsync(bytes, 0, bytes.Length); ms.Seek(0, SeekOrigin.Begin); return (await Post.PostGetJsonAsync <T>(url, null, ms, timeOut : timeOut, checkValidationResult : checkValidationResult)); } default: throw new ArgumentOutOfRangeException("sendType"); } } catch (ErrorJsonResultException ex) { ex.Url = urlFormat; throw; } }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="timeOut"></param> /// <param name="checkValidationResult"></param> /// <param name="jsonSetting"></param> /// <returns></returns> public static QyJsonResult Send(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT, bool checkValidationResult = false, JsonSetting jsonSetting = null) { return(Innocellence.Weixin.CommonAPIs.CommonJsonSend.Send <QyJsonResult>(accessToken, urlFormat, data, sendType, timeOut, checkValidationResult, jsonSetting)); }
public static T Send <T>(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT, bool checkValidationResult = false /*, JsonSetting jsonSetting = null*/) { return(Senparc.Weixin.CommonAPIs.CommonJsonSend.Send <T>(accessToken, urlFormat, data, sendType, timeOut, checkValidationResult /*, jsonSetting*/)); }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="timeOut"></param> /// <returns></returns> public static QyJsonResult Send(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT) { return(Send <QyJsonResult>(accessToken, urlFormat, data, sendType, timeOut)); }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="sendType"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <param name="checkValidationResult"></param> /// <param name="jsonSetting"></param> /// <returns></returns> //[Obsolete("此方法已过期,请使用Senparc.Weixin.CommonAPIs.CommonJsonSend.Send()方法")] public static WxJsonResult Send(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT, bool checkValidationResult = false, JsonSetting jsonSetting = null /*, int retry40001ErrorTimes = 0*/) { WxJsonResult result = null; try { result = Senparc.Weixin.CommonAPIs.CommonJsonSend.Send(accessToken, urlFormat, data, sendType, timeOut, checkValidationResult, jsonSetting); } //catch (ErrorJsonResultException ex) //{ // if (ex.JsonResult.errcode == ReturnCode.获取access_token时AppSecret错误或者access_token无效 /*40001*/) // { // if (retry40001ErrorTimes == 0) // { // result = Send(accessToken, urlFormat, data, sendType, timeOut, checkValidationResult, // jsonSetting, retry40001ErrorTimes + 1); // } // else if (retry40001ErrorTimes == 1) // { // } // } //} catch { throw; } return(result); }
public static async Task <WishJsonResult> SendAsync(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT, bool checkValidationResult = false, JsonSetting jsonSetting = null) { return(await Wl.Wish.CommonAPIs.CommonJsonSend.SendAsync <WishJsonResult>(accessToken, urlFormat, data, sendType, timeOut, checkValidationResult, jsonSetting)); }
/// <summary> /// 发送数据 /// </summary> /// <param name="accessToken"></param> /// <param name="urlFormat"></param> /// <param name="data"></param> /// <param name="sendType"></param> /// <param name="timeOut"></param> /// <param name="checkValidationResult"></param> /// <param name="jsonSetting"></param> /// <returns></returns> public static AliJsonResult Send(string accessToken, string urlFormat, object data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT, bool checkValidationResult = false, JsonSetting jsonSetting = null) { AliJsonResult result = null; try { result = Com.Alibaba.CommonAPIs.CommonJsonSend.Send(accessToken, urlFormat, data, sendType, timeOut, checkValidationResult, jsonSetting); } catch (Exception) { throw; } return(result); }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat">用accessToken参数填充{0}</param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="callBack"></param> /// <param name="sendType"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <param name="checkValidationResult"></param> /// <param name="jsonSetting"></param> /// <returns></returns> public static T Send <T>(string accessToken, string urlFormat, object data, Action <string> callBack, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT, bool checkValidationResult = false, JsonSerializerSettings jsonSetting = null) { //TODO:此方法可以设定一个日志记录开关 try { var url = string.IsNullOrEmpty(accessToken) ? urlFormat : string.Format(urlFormat, accessToken.AsUrlData()); switch (sendType) { case CommonJsonSendType.GET: return(Get.GetJson <T>(url, callBack)); case CommonJsonSendType.POST: SerializerHelper serializerHelper = new SerializerHelper(); var jsonString = serializerHelper.GetJsonString(data, jsonSetting); using (MemoryStream ms = new MemoryStream()) { var bytes = Encoding.UTF8.GetBytes(jsonString); ms.Write(bytes, 0, bytes.Length); ms.Seek(0, SeekOrigin.Begin); return(Post.PostGetJson <T>(url, null, null, ms, timeOut: timeOut, checkValidationResult: checkValidationResult)); } //TODO:对于特定的错误类型自动进行一次重试,如40001(目前的问题是同样40001会出现在不同的情况下面) default: throw new ArgumentOutOfRangeException("sendType"); } } catch (ErrorJsonResultException ex) { ex.Url = urlFormat; throw; } }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="sendType"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <param name="jsonSetting"></param> /// <returns></returns> public static WxJsonResult Send(string accessToken, string urlFormat, object data, Action <string> callBack, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = Config.TIME_OUT, bool checkValidationResult = false, JsonSerializerSettings jsonSetting = null) { return(Send <WxJsonResult>(accessToken, urlFormat, data, callBack, sendType, timeOut)); }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="timeOut"></param> /// <returns></returns> public static T Send <T>(string accessToken, string urlFormat, string jsonString, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = 10000) { var url = string.IsNullOrEmpty(accessToken) ? urlFormat : string.Format(urlFormat, accessToken); switch (sendType) { case CommonJsonSendType.GET: return(Senparc.Weixin.HttpUtility.Get.GetJson <T>(url)); case CommonJsonSendType.POST: //Senparc.Weixin.Helpers.SerializerHelper serializerHelper = new Senparc.Weixin.Helpers.SerializerHelper(); //var jsonString = serializerHelper.GetJsonString(data); using (MemoryStream ms = new MemoryStream()) { var bytes = Encoding.UTF8.GetBytes(jsonString); ms.Write(bytes, 0, bytes.Length); ms.Seek(0, SeekOrigin.Begin); return(Senparc.Weixin.HttpUtility.Post.PostGetJson <T>(url, null, ms, timeOut: timeOut)); } default: throw new ArgumentOutOfRangeException("sendType"); } }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="timeOut"></param> /// <returns></returns> public static WxJsonResult Send(string accessToken, string urlFormat, string data, CommonJsonSendType sendType = CommonJsonSendType.POST, int timeOut = 10000) { return(Send <WxJsonResult>(accessToken, urlFormat, data, sendType, timeOut)); }
/// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="sendType"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <param name="jsonSetting"></param> /// <returns></returns> //public static WxJsonResult Send<T>(string accessToken, string urlFormat, T data, CommonJsonSendType sendType = CommonJsonSendType.POST) where T : IModel //{ // return SendAsync<WxJsonResult, T>(accessToken, urlFormat, data, sendType); //} /// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat">用accessToken参数填充{0}</param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="sendType"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <param name="checkValidationResult"></param> /// <param name="jsonSetting"></param> /// <returns></returns> //public static async Task<T> SendAsync<T, K>(string accessToken, string urlFormat, K data, CommonJsonSendType sendType = CommonJsonSendType.POST) where T : IModel where K : IModel //{ // //TODO:此方法可以设定一个日志记录开关 // var url = string.IsNullOrEmpty(accessToken) ? urlFormat : string.Format(urlFormat, accessToken); // switch (sendType) // { // case CommonJsonSendType.GET: // T getT = default; // await Actor.Public.GetAsync(url, m => // { // getT = m.JsonToModel<T>(); // }); // return getT; // case CommonJsonSendType.POST: // T postT = default(T); // StringContent content = new StringContent(data.ModelToJson()); // await Actor.Public.PostAsync(url, content, m => // { // postT = m.JsonToModel<T>(); // }); // return postT; // //TODO:对于特定的错误类型自动进行一次重试,如40001(目前的问题是同样40001会出现在不同的情况下面) // default: // throw new ArgumentOutOfRangeException("sendType"); // } //} #endregion #region 异步方法 /// <summary> /// 向需要AccessToken的API发送消息的公共方法 /// </summary> /// <param name="accessToken">这里的AccessToken是通用接口的AccessToken,非OAuth的。如果不需要,可以为null,此时urlFormat不要提供{0}参数</param> /// <param name="urlFormat"></param> /// <param name="data">如果是Get方式,可以为null</param> /// <param name="sendType"></param> /// <param name="timeOut">代理请求超时时间(毫秒)</param> /// <param name="checkValidationResult">验证服务器证书回调自动验证</param> /// <param name="jsonSetting"></param> /// <returns></returns> public static async Task <WxJsonResult> SendAsync <T>(string accessToken, string urlFormat, T data, CommonJsonSendType sendType = CommonJsonSendType.POST) where T : IModel { return(await SendAsync <WxJsonResult, T>(accessToken, urlFormat, data, sendType)); }