/// <summary> /// 传入ProductName,OrderNumber,TotalFee,TimeExpire,OpenId(可选),TradeType,NotifyUrl(可选) /// </summary> /// <param name="param"></param> /// <param name="context"></param> /// <returns></returns> public static string GetUnifiedOrder(PayParam param = null) { if (param.TotalFee == null || string.IsNullOrWhiteSpace(param.ProductName) || string.IsNullOrWhiteSpace(param.OrderNumber) || string.IsNullOrWhiteSpace(param.TimeExpire) || param.TradeType == null) { return("参数错误"); } var req = new RequestHandler(); req.SetKey(WeChatConfig.GetKey()); req.SetParameter("appid", WeChatConfig.GetAppId()); req.SetParameter("mch_id", WeChatConfig.GetMchId()); req.SetParameter("nonce_str", GetNoncestr()); req.SetParameter("body", param.ProductName); req.SetParameter("out_trade_no", param.OrderNumber); req.SetParameter("total_fee", param.TotalFee.ToString()); req.SetParameter("spbill_create_ip", IPHelper.GetVisitorIP()); req.SetParameter("time_start", DateTime.Now.ToString("yyyyMMddHHmmss")); req.SetParameter("time_expire", param.TimeExpire); req.SetParameter("notify_url", string.IsNullOrWhiteSpace(param.NotifyUrl) ? WeChatConfig.GetNotify() : param.NotifyUrl); req.SetParameter("trade_type", param.TradeType.ToString()); if (!string.IsNullOrWhiteSpace(param.OpenId)) { req.SetParameter("openid", param.OpenId); } req.SetParameter("sign", req.CreateMd5Sign()); var reqXml = req.ParseXml(); var result = HttpHelper.Post(new HttpParam() { Url = ApiList.UnifiedOrderUrl, PostParam = reqXml, Encoding = HttpContext.Current.Request.ContentEncoding }); return(result); }