private string refund(HttpContext context) { try { //string alluserid = context.Request["alluserid"]; string biaoNum = context.Request["biaoNum"]; string payNo = context.Request["orderno"]; ms.makeLog("进来了退款的方法:" + ",还镖数量:" + biaoNum + ",付款单号:" + payNo); //注意这里,这里有异常 refundInfo info = ms.getRefundInfo(biaoNum, payNo); //这里计算出需要退款的信息 payNo = info.orderno; Random rand = new Random(); int num = rand.Next(1000, 9999); Parameteres param = new Parameteres(); string orderno = DateTime.Now.ToString("yyyyMMddHHmmss") + num; Refund refund = new Refund(); refund.appid = "wxd6cf371dbe9f5906"; refund.key = "F56S456F4SD5F4S65F4AS65D4FS6D54F"; refund.mch_id = "1519238551"; refund.nonce_str = "5K8264ILTKCH16CQ2502SI8ZNMTM67VS"; //随机字符串 refund.out_refund_no = orderno; //退款单号随机生成 refund.out_trade_no = payNo; //支付单号 refund.refund_fee = info.refundPrice; refund.total_fee = info.totalPrice; refund.notify_url = "https://feibiao.ty-gz.com:8137/dist/Handler/refundNotify.ashx"; string strParam = getRefundParam(refund); string payResXML = Helper.PostWebRequest("https://api.mch.weixin.qq.com/secapi/pay/refund", strParam); ms.makeLog("退款方法:" + payResXML + ",refund.refund_fee:" + refund.refund_fee + ",refund.total_fee:" + refund.total_fee); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(payResXML); XmlNode rootNode = xmlDoc.SelectSingleNode("xml"); XmlNode nodeScuecc = rootNode.SelectSingleNode("result_code"); if (nodeScuecc == null) { ms.makeLog("微信退款:result_code节点为空"); return(""); } XmlNode refund_idNode = rootNode.SelectSingleNode("refund_id"); if (refund_idNode != null) { string refund_id = refund_idNode.InnerText; refund_id = refund_id.Replace("<![CDATA[", "").Replace("]]", ""); XmlNode refund_feeNode = rootNode.SelectSingleNode("cash_refund_fee"); string refundfee = refund_feeNode.InnerText.Replace("<![CDATA[", "").Replace("]]", ""); XmlNode out_trade_noNode = rootNode.SelectSingleNode("out_trade_no"); string out_trade_no = out_trade_noNode.InnerText.Replace("<![CDATA[", "").Replace("]]", ""); XmlNode out_refund_noNode = rootNode.SelectSingleNode("out_refund_no"); string out_refund_no = out_refund_noNode.InnerText.Replace("<![CDATA[", "").Replace("]]", ""); int count = ms.selectRefundCount(refund_id); if (count > 0) { return(""); } int aa = ms.addRefund(out_trade_no, out_refund_no, refund_id, refundfee); int changeState = ms.updateRefundState(out_trade_no); } return("成功退押金:" + info.refundPrice + "分"); } catch (Exception ex) { ms.makeLog("退款方法异常:" + ex.ToString()); return(ex.ToString()); } }