public TPostBackContent GetBack(T obj, Action <IPostRequestContent, T> otherSet = null) { //根据商户配置信息、传入参数创建请求正文 var content = CreateContent(obj); //触发设置参数相关事件 obj.SetParamaters?.Invoke(content); otherSet?.Invoke(content, obj); //为请求正文签名 if (Signature == null) { throw new PaymentException(GateWay.Name, "Signature不能为空"); } content.Sign = Signature.Sign(content); //创建http请求对象 var client = new LiteHttpClient(content.Encoding); var request = DefaultRequest.FromString(GetActionUrl(content)); BeforePost(request, content); //执行请求获得响应字符串 string backstr; try { backstr = client.PostString(request, content.RequestPostData); } catch (Exception ex) { throw new GateWayException(GateWay.Name, message: "网络异常!", inner: ex); } //加载响应字符串获取返回对象 var back = Load(backstr); if (!Signature.Verify(back)) { throw new VerifyException(GateWay.Name, back); } if (!back.IsSuccessRequest) { throw new GateWayException(GateWay.Name, back.SubCode, back.SubMsg); } return(back); }
public override void Stop() { Connection.started = false; LiteHttpClient.Dispose(); }