public static string MakeSign(this WxPayParameter data, string paykey) { var str = data.PrepareSign(); str += "&key=" + paykey; return(MakeSign(str, data.SignType, paykey)); }
public static string MakeSign(this WxPayParameter data) { var str = data.PrepareSign(); str += "&key=" + Constants.WxConfig.PayKey; return(MakeSign(str, data.SignType)); }
public static string PrepareSign(this WxPayParameter data) { var ignoreProperties = new string[] { "paySign", "return_code", "return_msg" }; var @params = data.GetType().GetProperties().Select((ctx) => { var elm = ctx.GetCustomAttributes <Newtonsoft.Json.JsonPropertyAttribute>().FirstOrDefault(); if (elm == null || ignoreProperties.Any(o => o.Equals(elm.PropertyName, StringComparison.OrdinalIgnoreCase))) { return(null); } var v = ctx.GetValue(data); if (v == null) { return(null); } return(new { name = elm.PropertyName, value = v }); }) .Where(o => o != null) .OrderBy(o => o.name);//必须对参数排序否则签名不正确 return(string.Join("&", @params.Select(o => string.Format("{0}={1}", o.name, o.value)))); }
/// <summary> /// 拉起微信支付 /// </summary> /// <returns></returns> public ActionResult PullWxPay(WxPayParameter parameter) { parameter.PaySign = parameter.MakeSign(); return(View(parameter)); }