public async Task <IActionResult> PayNotify() { if (!Request.HasFormContentType) { return(BadRequest("参数错误")); } var formCollection = await Request.ReadFormAsync(); if (formCollection == null || formCollection.Count <= 0) { throw new Exception("未解析到callback信息"); } var sign = formCollection["sign"].ToString(); var dict = new UmsPayDictionary(); foreach (var key in formCollection.Keys) { if (key != "sign") { dict.Add(key, formCollection[key]); } } // sign validation if (!UmsPay.Utility.UmsSignature.Validate(dict, sign, _options.SecretKey)) { throw new Exception("签名校验失败"); } // TODO: check if it is an repeat request and if is repeat we should return SUCCESS OR FAILED to terminate. var billPayment = dict["billPayment"]; var str = JsonConvert.SerializeObject(dict); var payResult = JsonConvert.DeserializeObject <PayResultNotify>(str); payResult.Body = str; payResult.BillPaymentObj = JsonConvert.DeserializeObject <BillPayment>(billPayment); if (payResult.BillStatus != BillStatus.Paid) { return(Content("FAILED")); } var billQuery = new BillQueryRequest { BillDate = payResult.BillDate, BillNo = payResult.BillNo, RequestTimestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), }; var res = await _client.ExecuteAsync(billQuery); if (res.BillStatus != BillStatus.Paid) { return(Content("FAILED")); } return(Content("SUCCESS")); }
public IDictionary <string, string> GetParameters() { var parameters = new UmsPayDictionary { { "msgType", MsgType }, { "requestTimestamp", RequestTimestamp }, { "billNo", BillNo }, { "billDate", BillDate }, }; return(parameters); }
public IDictionary <string, string> GetParameters() { var parameters = new UmsPayDictionary { { "requestTimestamp", RequestTimestamp }, { "billNo", BillNo }, { "billDate", BillDate }, { "billDesc", BillDesc }, { "totalAmount", TotalAmount }, { "notifyUrl", NotifyUrl }, { "returnUrl", ReturnUrl }, { "msgType", MsgType }, }; return(parameters); }
public async Task <T> ExecuteAsync <T>(IUmsPayRequest <T> request) where T : UmsPayResponseBase { var txtParams = new UmsPayDictionary(request.GetParameters()) { { "mid", _options.Mid }, { "instMid", _options.InstMid }, { "msgSrc", _options.MsgSrc }, { "tid", _options.Tid } }; UmsSignature.Sign(txtParams, _options.SecretKey); using (var client = _httpClientFactory.CreateClient(UmsPayOptions.DefaultClientName)) { var content = JsonConvert.SerializeObject(txtParams); var body = await HttpClientUtility.DoPostAsync(client, _options.GetQrCodeUrl, content); if (string.IsNullOrEmpty(body)) { throw new ArgumentNullException(nameof(body)); } //var dict = JsonConvert.DeserializeObject<Dictionary<string, object>>(body); T resp = default(T); try { resp = JsonConvert.DeserializeObject <T>(body); } catch { throw new FormatException($"二维码返回信息解析失败: {body}"); } resp.Body = body; return(resp); } }