/// <summary> /// 统一下单 /// </summary> /// <param name="openId"></param> /// <param name="totalCharge"></param> /// <returns>StatusReport</returns> public static StatusReport UnifiedOrder(string openId, double totalCharge, string dataBag)//统一下单 { StatusReport sr = new StatusReport(); string outTradeNo = GetOutTradeNumber(); WXUnifiedOrder order = new WXUnifiedOrder() { appid = Common.Appid, mch_id = Common.Mchid, attach = dataBag, body = "北京燕侨物业管理有限公司苏州分公司-物业收费", detail = "dfsaff", nonce_str = GetNonceStr(), notify_url = "http://k17154485y.imwork.net/wxuser/Charge/OnTest", openid = openId, out_trade_no = outTradeNo, spbill_create_ip = "115.159.93.120", total_fee = Convert.ToInt32(totalCharge * 100).ToString(), trade_type = "JSAPI", }; string xmlParam = GetXmlParam(order); //sr.parameters = xmlParam; string url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; sr = RequestHelper.PostRequest(url, xmlParam); if (sr.status == "Fail") { return(sr); } string xmlResult = (string)sr.data; sr = GetOrderResult(xmlResult); sr.parameters = order.out_trade_no; return(sr); }
/// <summary> /// 获取统一下单需要的xml参数 /// </summary> /// <param name="order"></param> /// <returns></returns> private static string GetXmlParam(WXUnifiedOrder order) { Dictionary <string, string> dic = ToDictionary(order); dic = dic.OrderBy(m => m.Key).ToDictionary(m => m.Key, m => m.Value); StringBuilder sb = new StringBuilder(); StringBuilder sbXml = new StringBuilder(); sbXml.Append("<xml>"); foreach (var item in dic) { sbXml.Append("<" + item.Key + ">" + item.Value + "</" + item.Key + ">"); sb.Append(item.Key + "=" + item.Value + "&"); } sb.Append("key=" + Comman.Mchkey); string str = sb.ToString().Replace(" ", ""); string sign = EncryptionHelper.MD5Encryption(str).ToUpper(); sbXml.Append("<sign>" + sign + "</sign></xml>"); return(sbXml.ToString().Replace(" ", "")); }
/// <summary> /// 统一下单 /// </summary> /// <param name="openId"></param> /// <param name="totalCharge"></param> /// <returns>StatusReport</returns> public static StatusReport UnifiedOrder(string kindergartenName, string fromPage, string openId, double totalCharge, string dataBag)//统一下单 { StatusReport sr = new StatusReport(); string outTradeNo = GetOutTradeNumber(); string body = kindergartenName + "-收费"; string detail = fromPage == "kanyuan" ? "看园定金" : "报名费"; WXUnifiedOrder order = new WXUnifiedOrder() { appid = Comman.Appid, mch_id = Comman.Mchid, attach = dataBag, body = body, detail = detail, nonce_str = GetNonceStr(), notify_url = "http://16y7e12590.iask.in/SYServer/WXPay/OnSetWXPayInfo", openid = openId, out_trade_no = outTradeNo, spbill_create_ip = "115.159.93.120", total_fee = Convert.ToInt32(totalCharge * 100).ToString(), trade_type = "JSAPI", }; string xmlParam = GetXmlParam(order); //sr.parameters = xmlParam; string url = "https://api.mch.weixin.qq.com/pay/unifiedorder"; sr = RequestHelper.PostRequest(url, xmlParam); if (sr.status == "fail") { return(sr); } string xmlResult = (string)sr.data; sr = GetOrderResult(xmlResult); //sr.data = xmlResult; sr.parameters = order.out_trade_no; //sr.status = "success"; return(sr); }