public wxpay_re WxpayCustom(wxpay value) { string stringA = wxsign(value); value.sign = stringA; return(null); }
private string wxsign(wxpay value) { StringBuilder strRe = new StringBuilder(); Dictionary <string, string> dic = new Dictionary <string, string>(); Type t = value.GetType(); foreach (PropertyInfo pi in t.GetProperties()) { var strValue = pi.GetValue(value, null); if (strValue != null) { dic.Add(pi.Name, strValue.ToString()); } } int index = 0; foreach (var item in dic) { if (index == 0) { strRe.Append(item.Key + "=" + item.Value); index++; } else { strRe.Append("&" + item.Key + "=" + item.Value); } } string signs = ""; MD5 md5 = MD5.Create(); byte[] by = md5.ComputeHash(Encoding.UTF8.GetBytes(strRe.ToString())); for (int i = 0; i < by.Length; i++) { signs += by[i].ToString("X"); } return(signs); }
public IHttpActionResult paycustom([FromBody] Order order) { UserInfo user = new UserInfo(); //报关通道实体 AliPayOrder aliorder = new AliPayOrder(); //支付报关实体 alipay alipay_reponse = new alipay(); wxpay wxpay = new wxpay(); wxpay_re wxpay_re = new wxpay_re(); WxpayViewModel wxpayviewmodel = new WxpayViewModel(); API_Message message = new API_Message(); message.MessageCode = "1"; if (ModelState.IsValid) { try { string userid = order.OrderItems?[0].OrderItemDetails?[0].CustomsChannelId.ToString(); user = _IUserRepository.UserInfos.Where(t => t.userId == (order.OrderItems?[0].OrderItemDetails?[0].CustomsChannelId.ToString() ?? order.OrderItems[0].CustomsChannelId.ToString())).FirstOrDefault(); if (user != null && userid != null) { order.OrderGuid = Guid.NewGuid(); order.api_type = 3;//类型:支付报关 for (int i = 0; i < order.OrderItems.Count; i++) { order.OrderItems[i].ItemGuid = Guid.NewGuid(); } _iEcmOrder.Save_Orders(order);//保存接收order信息 if ((order?.PaymentMethodSystemName).Contains("支付宝")) { aliorder.partner = user.alipayAppId; aliorder.out_request_no = order.SubOrderNo ?? "" + order.OrderNo.ToString(); //aliorder.trade_no = "2019052222001497581037471813";// order.PayTransactionId; aliorder.trade_no = order.PayTransactionId; //"2019052322001491491036394115";// order.PayTransactionId; aliorder.merchant_customs_code = user.ebpCode; // user.cebCode; aliorder.amount = order.OrderTotal.ToString("f2"); //"0.01";// order.OrderTotal.ToString(".00"); aliorder.alipaySec = user.alipaySec; aliorder.customs_place = user?.AlipayPortCode;// user.PortCode;// "tianjin"; aliorder.merchant_customs_name = user.copName; aliorder.is_split = "F"; aliorder.buyer_name = order.BuyerName; // "李晨";// order.BuyerName; aliorder.buyer_id_no = order.BuyerIdNumber;; // "120102199966552141";// order.BuyerIdNumber; _IRabbitMQHelper.Publish <custompayController>(JsonConvert.SerializeObject(aliorder)); if ((user?.AlipayPortCode).ToLower().Contains("tianjin") || (user?.AlipayPortCode).ToLower().Contains("guangzhou")) { aliorder.customs_place = "zongshu";// user?.AlipayPortCode;// user.PortCode;// "tianjin"; _IRabbitMQHelper.Publish_Delay <custompay_zongshuController>(JsonConvert.SerializeObject(aliorder), "custompayController"); } _ILog4netHelper.WriteLog_Info <custompayController>(JsonConvert.SerializeObject(aliorder), null, "aliorder", null); //alipay_reponse = _IAlipayRepository.alipay_update(aliorder, "ujsidc9esjszyov0fc0trsveq733ttvd"); } else if ((order?.PaymentMethodSystemName).Contains("财付通")) { wxpay.appid = user.wxappId; // "wx75732915fa967aca"; wxpay.mch_id = user.wxshopId; // "1536978981"; wxpay.out_trade_no = order.OrderNo; wxpay.transaction_id = order.PayTransactionId; wxpay.customs = user?.WxpayPortCode;// user.PortCode;//"GUANGZHOU_ZS"; wxpay.mch_customs_no = user.copCode; wxpay.cert_type = "IDCARD"; wxpay.cert_id = order?.BuyerIdNumber.ToUpper(); wxpay.name = order.BuyerName; wxpayviewmodel.wxshopId = user.wxshopId; wxpayviewmodel.wxpayCode = user.wxpayCode; wxpayviewmodel.wxappId = user.wxappId; wxpayviewmodel.wxpay = wxpay; _IRabbitMQHelper.Publish <custompayController_wx>(JsonConvert.SerializeObject(wxpayviewmodel)); _ILog4netHelper.WriteLog_Info <custompayController>(JsonConvert.SerializeObject(wxpayviewmodel), null, "wxpayviewmodel", null); } _ILog4netHelper.WriteLog_Info <custompayController>(JsonConvert.SerializeObject(order), null, null, null); } else { message.MessageCode = "2"; message.ErrorMsg = "没有对应的报关通道"; } } catch (Exception ex) { _ILog4netHelper.WriteLog_Error <custompayController>(JsonConvert.SerializeObject(order), null, null, ex); } } else { var modelstate = BadRequest(ModelState); string returestr = ""; foreach (var item in modelstate.ModelState.Values) { returestr += item.Errors != null ? item.Errors[0].ErrorMessage + "\r\n" : ""; } message.MessageCode = "2"; message.ErrorMsg = returestr; } return(Json(message)); }