public HttpResponseMessage Tenpay() { //生成单据 var result = Request.Content.ReadAsStringAsync().Result; this.WriteLogFile("回调参数:" + result); var bizJson = WxPayData.ParaseNotify(result); var bizObj = JsonConvert.DeserializeObject<WxPayData.NOTIFY>(bizJson); var orderNo = bizObj.SALES_NO; var tranId = bizObj.TRANSACTION_ID; //var tranId = bizObj.TRANSACTION_ID; var arrachArray = bizObj.ARRACH.Split('|'); var productId = arrachArray[0]; var buyUserId = arrachArray[1]; var response = new HttpResponseMessage(); Cache c = HttpRuntime.Cache; var isExit = c.Get(productId); if (isExit != null) { this.WriteLogFile("已收到回调"); response.Content = new StringContent(WxPayData.NotifySuccess()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); } else { //插入缓存,标识已收到微信回调 c.Insert(productId, bizObj.ARRACH); //执行生成订单逻辑 var isCreate = CreateOrder(productId, buyUserId, orderNo, tranId); if (isCreate) { WriteLogFile("TenpayOK!"); response.Content = new StringContent(WxPayData.NotifySuccess()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); } else { WriteLogFile("TenpaySysEx:" + "单据生成错误"); response.Content = new StringContent(WxPayData.NotifyFail()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); } } return response; }
public HttpResponseMessage RefundApi() { var response = new HttpResponseMessage(); try { var result = Request.Content.ReadAsStringAsync().Result; WriteLogFile("回调参数:" + result); var bizJson = WxPayData.RefundJson(result); var bizObj = JsonConvert.DeserializeObject<WxPayData.REFUND_NOTIFY>(bizJson); var status = bizObj.refund_status; var out_refund_no = bizObj.out_refund_no; var orderNo = bizObj.out_trade_no; if (status == "SUCCESS") { Cache c = HttpRuntime.Cache; var isExit = c.Get(out_refund_no); if (isExit != null) { this.WriteLogFile("已收到回调"); response.Content = new StringContent(WxPayData.NotifySuccess()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); } else { //插入缓存,标识已收到微信回调 c.Insert(out_refund_no, orderNo); //执行单据退款逻辑 var isRefund = this.Refund(orderNo); if (isRefund) { WriteLogFile("TenpayOK!"); response.Content = new StringContent(WxPayData.NotifySuccess()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); } else { WriteLogFile("TenpaySysEx:" + "单据退款失败"); response.Content = new StringContent(WxPayData.NotifyFail()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); } } } else { WriteLogFile("TenpayEx:" + "回调失败"); response.Content = new StringContent(WxPayData.NotifyFail()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); return response; } } catch (Exception ex) { WriteLogFile("TenpayEx:" + ex.Message); response.Content = new StringContent(WxPayData.NotifyFail()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); return response; } WriteLogFile("TenpayOK!"); response.Content = new StringContent(WxPayData.NotifySuccess()); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("text/xml"); return response; }