public int RefundPrepayCard(decimal refundAmount, int soSysNo, string tNumber, string refundKey) { SZPointAllianceRequestMessage request = new SZPointAllianceRequestMessage() { RefundAmount = refundAmount, RefundDescription = string.Empty, RefundKey = refundKey, RefundType = PointAllianceRefundType.PrepaidCard, SOSysNo = soSysNo, TNumber = tNumber }; int result = -1; try { SZPointAllianceResponseMessage response = Refund(request); result = response.Result; if (result == 2) { throw new BizException(response.Message); } } catch (Exception e) { throw new BizException(e.Message); } return(result); }
private SZPointAllianceResponseMessage InitRequest(SZPointAllianceRequestMessage message) { string requestUrl = string.Empty; string requestType = string.Empty; if (message.RefundType == PointAllianceRefundType.Point) { requestType = "退积分"; throw new InvalidOperationException("退积分尚未实现"); } else { requestType = "退预付卡"; requestUrl = AppSettingHelper.SZPointAlliance_RefundPrepaidCard; } string param = BuildParameter(message); WriteLog(string.Format("调用方:{0}|请求URL:{1}?{2}", "神州运通", requestUrl, param), string.Format("神州运通--{0}--请求日志", requestType)); HttpWebRequest webRequest = CreateRequestProxy(requestUrl); string mes = string.Empty; byte[] paramBuffer = Encoding.UTF8.GetBytes(param); using (Stream stream = webRequest.GetRequestStream()) { stream.Write(paramBuffer, 0, paramBuffer.Length); } try { WebResponse response = webRequest.GetResponse(); using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream)) { mes = reader.ReadToEnd(); } } if (mes != null) { //在xml文件的开头有隐藏的非法字符,需要过滤 mes = System.Text.RegularExpressions.Regex.Replace(mes.Trim(), "^[^<]", string.Empty); } SZPointAllianceResponseMessage res = SerializationUtility.XmlDeserialize <SZPointAllianceResponseMessage>(mes); return(res); } finally { WriteLog(string.Format("调用方:{0}|请求URL:{1}?{2}|返回信息:{3}", "神州运通", requestUrl, param, mes), string.Format("神州运通--{0}--返回日志", requestType)); } }
public void HandleEvent(SZPointAllianceRequestMessage eventMessage) { SZPointAllianceResponseMessage res = InitRequest(eventMessage); if (res.Result == 2) { if (string.IsNullOrEmpty(res.Message)) { res.Message = "调用神州运通接口出现错误,但并未返回错误信息"; } throw new BizException(res.Message); } this.SZResponse = res; }