//[Authorize] public ActionResult Index() { IndexModel Model = new IndexModel(); string openid = Request.RequestContext.HttpContext.User.Identity.Name; string OrderNo = _WeiXinConfig.GenerateOutTradeNo(); PaymentData payData = new PaymentData(); payData.SetValue("attach", OrderNo); payData.SetValue("body", "微信在线支付"); payData.SetValue("out_trade_no", OrderNo); payData.SetValue("trade_type", "JSAPI"); payData.SetValue("total_fee", 1);//1分钱 payData.SetValue("openid", openid); //payData.SetValue("spbill_create_ip", "127.0.0.1"); payData.SetValue("notify_url", _WeiXinConfig.NOTIFY_URL); PaymentData returnData = _WeiXinConfig.UnifiedOrder(payData); string prepay_id = ""; string returnCode = returnData.GetValue("return_code").ToString(); if (returnCode.ToUpper().Equals("SUCCESS")) { #region 获取支付签名 //获取支付ID prepay_id = returnData.GetValue("prepay_id").ToString(); PaymentData jsApiParam = new PaymentData(); string NonceStr = _WeiXinConfig.GenerateNonceStr(); string TimeStamp = _WeiXinConfig.GenerateTimeStamp(); jsApiParam.SetValue("appId", _WeiXinConfig.AppId); jsApiParam.SetValue("timeStamp", TimeStamp); jsApiParam.SetValue("nonceStr", NonceStr); jsApiParam.SetValue("package", "prepay_id=" + prepay_id); jsApiParam.SetValue("signType", "MD5"); Model.AppId = _WeiXinConfig.AppId; Model.TimeStamp = TimeStamp; Model.NonceStr = NonceStr; Model.PrepayID = prepay_id; Model.PaySign = jsApiParam.MakeSign(_WeiXinConfig.SignKey); Model.Success = true; #endregion } else { Model.Success = false; Model.ErrorMessage = returnData.GetValue("return_msg").ToString(); } return(View(Model)); }