/// <summary> /// Get请求 得到响应字符串 /// </summary> /// <param name="url">请求地址</param> /// <returns></returns> public T GetXml <T>(string url) { var res = Get(url).Content; if (string.IsNullOrEmpty(res)) { return(default(T)); } return(_xmlProvider.Deserialize <T>(res, _encoding)); }
/// <summary> /// Get请求 得到响应字符串 /// </summary> /// <param name="url">请求地址</param> /// <returns></returns> public T GetXml <T>(string url) where T : class, new() { var res = GetString(url); if (string.IsNullOrEmpty(res)) { return(default(T)); } return(_xmlProvider.Deserialize <T>(res, _encoding)); }
/// <summary> /// 处理用户消息 /// </summary> /// <param name="webChatAuthConfig"></param> /// <param name="wxConfig"></param> /// <param name="xml"></param> /// <param name="errCode">错误码</param> public WebChatMessage ProcessRequest(WebChatAuthConfig webChatAuthConfig, WxConfig wxConfig, string xml, int?errCode = null) { WebChatMessage refundReponse = null; try { if (!string.IsNullOrEmpty(Auth(webChatAuthConfig, wxConfig))) { throw new BusinessException("签名错误", HttpStatus.Err.Id); } refundReponse = _xmlProvider.Deserialize <WebChatMessage>(xml); if (refundReponse == null) { throw new BusinessException("参数错误", HttpStatus.Err.Id); } } catch (Exception ex) { _logger.LogError("接受用户信息错误:", ex.ExtractAllStackTrace()); } return(refundReponse); }
/// <summary> /// 处理用户消息 /// </summary> /// <param name="webChatAuthConfig"></param> /// <param name="wxConfig"></param> /// <param name="xml"></param> /// <param name="errCode">错误码</param> public WebChatMessage ProcessRequest(WebChatAuthConfig webChatAuthConfig, WxConfig wxConfig, string xml, int?errCode = null) { WebChatMessage refundReponse = null; try { if (!string.IsNullOrEmpty(Auth(webChatAuthConfig, wxConfig))) { throw new BusinessException("签名错误"); } refundReponse = _xmlProvider.Deserialize <WebChatMessage>(xml); if (refundReponse == null) { throw new BusinessException("参数错误"); } } catch (System.Exception e) { _logService.Error("接受用户信息错误:", e); } return(refundReponse); }
/// <summary> /// 指定短信列表发送短信 /// </summary> /// <param name="phoneNumbers">手机号</param> /// <param name="templateCode">短信模板</param> /// <param name="content">内容</param> /// <param name="loseAction">失败回调函数</param> /// <returns></returns> public bool Send(List <string> phoneNumbers, string templateCode, object content, Action <SendSmsLoseDto> loseAction = null) { Dictionary <string, string> commonParam = Util.BuildCommonParam(_smsConfig.AccessKey); commonParam.Add("Action", "SendSms"); commonParam.Add("Version", "2017-05-25"); commonParam.Add("RegionId", "cn-hangzhou"); commonParam.Add("PhoneNumbers", phoneNumbers.ConvertListToString(',')); commonParam.Add("SignName", _smsConfig.SignName); commonParam.Add("TemplateCode", templateCode); commonParam.Add("TemplateParam", _jsonProvider.Serializer(content)); string sign = Util.CreateSign(commonParam, _smsConfig.EncryptionKey); commonParam.Add("Signature", sign); RestRequest request = new RestRequest(Method.GET); foreach (var key in commonParam.Keys) { request.AddQueryParameter(key, commonParam[key]); } var response = _restClient.Execute(request); SendSmsResponse result = _xmlProvider.Deserialize <SendSmsResponse>(response.Content); if (result.Code == "OK") { return(true); } loseAction?.Invoke(new SendSmsLoseDto() { PhoneList = phoneNumbers, Msg = "短信发送失败", SubMsg = response.Content, Code = result.Code }); return(false); }