/// 获取预payid /// <summary> /// 获取预payid /// </summary> /// <returns></returns> public string GetPrepayId() { this.parameters.Add("sign", GetSign(this.parameters)); string xml = MakePostXml(); string content = Common.Tools.GetPage(unifiedorderURL, xml); XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(content); return(WeChatConfig.GetXMLstrByKey("prepay_id", xmldoc)); }
public ActionResult PayOrder(string orderid) { ViewBag.PageFlag = "PayOrder"; var openid = CommonMethod.getCookie("openid"); var userid = CommonMethod.getCookie("userid"); var user = weiUserM.GetModelWithOutTrace(u => u.userNum == userid && u.openid == openid); if (user == null) { return(Content("对不起,请登陆系统!")); } ViewBag.UserType = user.isfenxiao; ViewBag.userYongJin = user.userYongJin; ViewBag.Userid = userid; ViewBag.Openid = openid; var order = orderB.Get(o => o.orderNum == orderid); if (order == null) { return(Content("对不起,这个订单是错误的!")); } //----- noncestr = CommonMethod.GetCode(16); string jsapi_ticket = Js_sdk_Signature.IsExistjsapi_ticket(WeChatConfig.IsExistAccess_Token2()); timestamp = DateTime.Now.Ticks.ToString().Substring(0, 10);; string url = Request.Url.ToString().Replace("#", ""); JssdkSignature = Js_sdk_Signature.GetjsSDK_Signature(noncestr, jsapi_ticket, timestamp, url); ViewBag.Appid = WeChatConfig.GetKeyValue("appid"); ViewBag.Uri = WeChatConfig.GetKeyValue("shareurl"); ViewBag.noncestr = noncestr; ViewBag.jsapi_ticket = jsapi_ticket; ViewBag.timestamp = timestamp; //微信支付代码 // //httpContext var packageReqHandler = new RequestHandler(HttpContext); packageReqHandler.Init(); //时间戳 payTimeSamp = Senparc.Weixin.MP.TenPayLibV3.TenPayV3Util.GetTimestamp(); //随机字符串 sj = CommonMethod.GetCode(16) + "_" + userid; //设置参数 packageReqHandler.SetParameter("body", "商城-购买支付"); //商品信息 127字符 packageReqHandler.SetParameter("appid", PayConfig.AppId); packageReqHandler.SetParameter("mch_id", PayConfig.MchId); packageReqHandler.SetParameter("nonce_str", sj); packageReqHandler.SetParameter("notify_url", PayConfig.NotifyUrl); packageReqHandler.SetParameter("openid", openid); packageReqHandler.SetParameter("out_trade_no", orderid + "_" + CommonMethod.GetCode(4)); //商家订单号 packageReqHandler.SetParameter("spbill_create_ip", Request.UserHostAddress); //用户的公网ip,不是商户服务器IP packageReqHandler.SetParameter("total_fee", (Convert.ToDouble(order.yunPrice) * 100).ToString()); //商品金额,以分为单位(money * 100).ToString() packageReqHandler.SetParameter("trade_type", "JSAPI"); packageReqHandler.SetParameter("attach", CommonMethod.GetCode(28)); //自定义参数 127字符 string sign = packageReqHandler.CreateMd5Sign("key", PayConfig.AppKey); //第一次签名结果 #region 获取package包====================== packageReqHandler.SetParameter("sign", sign); string data = packageReqHandler.ParseXML();//支付发送的数据 XML格式 string prepayXml = Senparc.Weixin.MP.AdvancedAPIs.TenPayV3.Unifiedorder(data); //string prepayXml = WeiXin.GetPage("https://api.mch.weixin.qq.com/pay/unifiedorder", data); var xdoc = new XmlDocument(); xdoc.LoadXml(prepayXml); XmlNode xn = xdoc.SelectSingleNode("xml"); LogHelper.WriteLog(prepayXml); try { string PrepayId = WeChatConfig.GetXMLstrByKey("prepay_id", xdoc); Package = string.Format("prepay_id={0}", PrepayId); LogHelper.WriteLog(Package); } catch (Exception ex) { LogHelper.WriteLog(ex.ToString()); Package = string.Format("prepay_id={0}", ""); } #endregion #region 设置支付参数 输出页面 该部分参数请勿随意修改 ============== var paySignReqHandler = new RequestHandler(HttpContext); paySignReqHandler.SetParameter("appId", PayConfig.AppId); paySignReqHandler.SetParameter("timeStamp", payTimeSamp); paySignReqHandler.SetParameter("nonceStr", sj); paySignReqHandler.SetParameter("package", Package); paySignReqHandler.SetParameter("signType", "MD5"); PaySign = paySignReqHandler.CreateMd5Sign("key", PayConfig.AppKey); #endregion //--------END ViewBag.payTimeSamp = payTimeSamp; ViewBag.sj = sj; ViewBag.Package = Package; ViewBag.PaySign = PaySign; return(View(VIEW_TG_order.ToViewModel(order))); }