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()); } }