public String Unifiedorder(SortedList <string, string> postParams) { String prepayid = string.Empty; String postData = CreateXml(postParams); // 设置链接参数 String requestUrl = "https://api.mch.weixin.qq.com/pay/unifiedorder"; string content = HttpRequestHelper.DoPost(requestUrl, postData, WeiXinPayConfig.Charset); if (string.IsNullOrEmpty(content)) { return(null); } XmlDocument doc = new XmlDocument(); doc.LoadXml(content); XmlNode node = doc.DocumentElement.SelectSingleNode("./prepay_id"); if (node == null) { throw new Exception(content); } if (string.IsNullOrEmpty(node.InnerText)) { //Utils.WriteLog(content); } return(node.InnerText); }
/// <summary> /// 查询订单支付状态 /// </summary> /// <param name="postParams"></param> /// <returns></returns> public WxOrderPayResult QueryOrderPayResult(SortedList <string, string> postParams) { String postData = CreateXml(postParams); string content = HttpRequestHelper.DoPost("https://api.mch.weixin.qq.com/pay/orderquery", postData, WeiXinPayConfig.Charset); if (string.IsNullOrEmpty(content)) { return(null); } var result = XmlUtils.Deserialize <WxOrderPayResult>(content); return(result); }
// 提交预支付 public String SendPrepay(SortedList <string, string> packageParams) { String prepayid = string.Empty; String postData = "{"; StringBuilder sb = new StringBuilder(); foreach (KeyValuePair <string, string> kv in packageParams) { if (kv.Key != "appkey") { if (postData.Length > 1) { postData += ","; } postData += "\"" + kv.Key + "\":\"" + kv.Value + "\""; } } postData += "}"; // 设置链接参数 String requestUrl = WeiXinPayConfig.GateUrl + "?access_token=" + this.accessToken; string result = HttpRequestHelper.DoPost(requestUrl, postData, WeiXinPayConfig.Charset); if (!string.IsNullOrEmpty(result)) { JObject obj = JObject.Parse(result); string errcode = obj["errcode"].ToString(); if (errcode == "0") { prepayid = obj["prepayid"].ToString(); } else if (errcode == "40001") { //memcached.Delete(AccessTokenCacheKey); } } return(prepayid); }