/// <summary> /// 获取签名和参数 /// </summary> /// <param name="openid"></param> /// <param name="param"></param> /// <returns></returns> private string GetUnifiedOrderParam(string openid, Parameteres param) { //参与统一下单签名的参数,除最后的key外,已经按参数名ASCII码从小到大排序 //var unifiedorderSignParam = string.Format("appid={0}&body={1}&mch_id={2}&nonce_str={3}¬ify_url={4}&openid={5}&out_trade_no={6}&spbill_create_ip={7}&total_fee={8}&trade_type={9}&key={10}" // , param.appid, param.body, param.mch_id, param.nonce, param.notify_url // , openid, param.out_trade_no, param.spbill_create_ip, param.total_fee, param.trade_type, param.key); var unifiedorderSignParam = string.Format("appid={0}&attach={11}&body={1}&mch_id={2}&nonce_str={3}¬ify_url={4}&openid={5}&out_trade_no={6}&spbill_create_ip={7}&total_fee={8}&trade_type={9}&key={10}" , param.Appid, param.Body, param.Mch_id, param.Nonce, param.Notify_url , openid, param.Out_trade_no, param.Spbill_create_ip, param.Total_fee, param.Trade_type, param.Key, param.Attach); //MD5 var unifiedorderSign = MD5Encrypt(unifiedorderSignParam, new UTF8Encoding()).ToUpper(); //构造统一下单的请求参数 return(string.Format(@"<xml> <appid>{0}</appid> <attach>{11}</attach> <body>{1}</body> <mch_id>{2}</mch_id> <nonce_str>{3}</nonce_str> <notify_url>{4}</notify_url> <openid>{5}</openid> <out_trade_no>{6}</out_trade_no> <spbill_create_ip>{7}</spbill_create_ip> <total_fee>{8}</total_fee> <trade_type>{9}</trade_type> <sign>{10}</sign> </xml>", param.Appid, param.Body, param.Mch_id, param.Nonce, param.Notify_url, openid , param.Out_trade_no, param.Spbill_create_ip, param.Total_fee, param.Trade_type, unifiedorderSign, param.Attach)); }
//public new void Init(string id) //{ // if (!string.IsNullOrWhiteSpace(id)) // { // if (int.TryParse(id, out _rewardId)) // RaiseAllPropertiesChanged(); // } //} public override void Prepare(Parameteres parameter) { if (parameter != null) { _rewardId = parameter.RewardId; RaiseAllPropertiesChanged(); } }
private string pay(HttpContext context) { try { string openid = context.Request["openid"]; string ids = context.Request["ids"]; string quantity = context.Request["quantity"]; string macNum = ms.getMacNum(ids); int biaoNum = ms.getMacBiao(macNum); if (string.IsNullOrEmpty(ids) || string.IsNullOrEmpty(quantity)) { return("必要参数为空"); } string json = "{ids:\"" + ids + "\",quantity:\"" + quantity + "\"}"; int price = 1; DataTable dt = ms.getDeposit(); if (dt != null) { price = Convert.ToInt32(dt.Rows[0]["biaoMoney"]) * biaoNum + Convert.ToInt32(dt.Rows[0]["gameMoney"]) * Convert.ToInt32(quantity); } ms.makeLog("pay()方法:biaoNum," + biaoNum + "macNum," + macNum); Random rand = new Random(); int num = rand.Next(1000, 9999); Parameteres param = new Parameteres(); param.Total_fee = price.ToString(); //总金额有问题 string orderno = DateTime.Now.ToString("yyyyMMddHHmmss") + num; param.Out_trade_no = orderno; param.Attach = json; string canshu = GetUnifiedOrderParam(openid, param); string payResXML = Helper.ordinaryPost("https://api.mch.weixin.qq.com/pay/unifiedorder", canshu); var payRes = XDocument.Parse(payResXML); var root = payRes.Element("xml"); //序列化相应参数返回给小程序 var res = GetPayRequestParam(root, param.Appid, param.Key); string strJson = JsonConvert.SerializeObject(res); return(strJson); } catch (Exception ex) { return(ex.ToString()); } }
private string testRefund(HttpContext context) { try { string payNo = context.Request["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; //支付单号 DataTable dt = ms.getDeposit(); int refundfee = 0; if (dt != null) { refundfee = Convert.ToInt32(dt.Rows[0]["deposit"]); } int totalfee = ms.selectPayFee(payNo); refund.refund_fee = totalfee.ToString(); refund.total_fee = totalfee.ToString(); 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); //string certificatePath = ConfigurationManager.AppSettings["certificatePath"]; //return strParam; var payRes = XDocument.Parse(payResXML); var root = payRes.Element("xml"); //序列化相应参数返回给小程序 var res = GetPayRequestParam(root, refund.appid, refund.key); string strJson = JsonConvert.SerializeObject(res); return(strJson); } catch (Exception ex) { return(ex.ToString()); } }
private string adminRefund(HttpContext context) { try { string payNo = context.Request["orderno"]; string payMoney = context.Request["payPrice"]; string refundMoney = context.Request["refundMoney"]; 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 = refundMoney; refund.total_fee = payMoney; 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); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(payResXML); XmlNode rootNode = xmlDoc.SelectSingleNode("xml"); Json jsonResult = new Json(); XmlNode nodeScuecc = rootNode.SelectSingleNode("result_code"); if (nodeScuecc == null) { ms.makeLog("微信退款:result_code节点为空"); jsonResult.Success = false; jsonResult.Msg = "退款失败"; } else { 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) { jsonResult.Success = false; jsonResult.Msg = "退款失败"; } else { int aa = ms.addRefund(out_trade_no, out_refund_no, refund_id, refundfee); int changeState = ms.updateRefundState(out_trade_no); jsonResult.Success = true; jsonResult.Msg = "退款成功"; } } else { jsonResult.Success = false; jsonResult.Msg = "退款失败"; } } string strJson = JsonConvert.SerializeObject(jsonResult); return(strJson); } catch (Exception ex) { ms.makeLog("管理员退款方法异常:" + ex.ToString()); Json jsonResult = new Json(); jsonResult.Success = false; jsonResult.Msg = "退款异常" + ex.ToString(); string strJson = JsonConvert.SerializeObject(jsonResult); return(strJson); } }
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()); } }