Пример #1
0
        /// <summary>
        /// 发送接口请求
        /// </summary>
        /// <param name="req"></param>
        /// <param name="funcFormat"></param>
        /// <returns></returns>
        private static async Task <TResp> SendAsync <TResp>(WechatBaseReq <TResp> req, Func <HttpResponseMessage, Task <TResp> > funcFormat)
            where TResp : WechatBaseResp, new()
        {
            if (funcFormat == null)
            {
                throw new ArgumentNullException(nameof(funcFormat), "接口响应格式化方法不能为空!");
            }

            if (req.app_config == null)
            {
                throw new NotImplementedException("微信接口请求配置信息为空,请设置!");
            }

            var client = WechatPlatformHelper.HttpClientProvider?.Invoke();
            var resp   = await(client == null ? ((OssHttpRequest)req).SendAsync() : client.SendAsync(req));

            return(await funcFormat(resp));
        }
Пример #2
0
 /// <summary>
 /// 发送接口请求
 /// 注: 使用internal内部限定,减少外部引用时命名空间的引入
 /// </summary>
 /// <param name="req"></param>
 /// <returns></returns>
 internal static Task <TResp> ExecuteAsync <TResp>(this WechatBaseReq <TResp> req)
     where TResp : WechatBaseResp, new()
 {
     req.address_url = string.Concat(WechatPlatformHelper.ApiHost, req.GetApiPath());
     return(SendAsync(req, JsonFormat <TResp>));
 }