Ejemplo n.º 1
0
        /// <summary>
        /// 支付
        /// </summary>
        public ActionResult Pay()
        {
            string result = WebHelper.GetPostStr();
            NameValueCollection parmas = WebHelper.GetParmList(result);

            //服务器异步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数
            string notifyUrl = string.Format("{0}/appalipay/notify", BSPConfig.ShopConfig.SiteUrl);


            //付款金额
            string totalFee = decimal.Parse(parmas["totalfee"]).ToString();


            //记录充值信息
            RechargeModel rech = new RechargeModel
            {
                Out_trade_no = parmas["outtradeno"],
                Account      = parmas["account"],
                SuiteId      = parmas["vossuiteid"],
                PlatForm     = "支付宝",
                Type         = int.Parse(parmas["type"]),
                Role         = int.Parse(parmas["role"])
            };
            bool addres = Recharge.AddRecharge(rech);

            if (!addres)
            {
                return(AjaxResult("error", "记录充值信息失败"));
            }

            return(AjaxResult("success", "验证成功"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 支付
        /// </summary>
        public ActionResult Pay()
        {
            string result = WebHelper.GetPostStr();
            NameValueCollection parmas = WebHelper.GetParmList(result);

            //支付类型,必填,不能修改
            string paymentType = "1";

            //服务器异步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数
            string notifyUrl = string.Format("{0}/appalipay/notify", BSPConfig.ShopConfig.SiteUrl);

            //收款支付宝帐户
            string sellerEmail = AlipayConfig.Seller;
            //合作者身份ID
            string partner = AlipayConfig.Partner;
            //交易安全检验码
            string key = AlipayConfig.Key;

            //商户订单号
            string outTradeNo = "hmk" + DateTime.Now.ToString("yyMMdd") + Randoms.CreateRandomValue(6, true);
            //订单名称
            string subject = BSPConfig.ShopConfig.SiteTitle;
            //付款金额
            string totalFee = double.Parse(parmas["totalFee"]).ToString();
            //订单描述
            string body = "话费套餐";



            Encoding e = Encoding.GetEncoding(AlipayConfig.AppInputCharset);

            //把请求参数打包成数组
            SortedDictionary <string, string> parms = new SortedDictionary <string, string>();

            parms.Add("app_id", "2016092001932731");
            parms.Add("method", "alipay.trade.app.pay");
            parms.Add("charset", AlipayConfig.AppInputCharset);
            parms.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            parms.Add("version", "1.0");
            parms.Add("notify_url", notifyUrl);


            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic.Add("partner", partner);
            dic.Add("seller_id", sellerEmail);
            dic.Add("out_trade_no", outTradeNo);
            dic.Add("subject", subject);
            dic.Add("body", body);
            dic["total_amount"]    = totalFee;
            dic["product_code"]    = "QUICK_MSECURITY_PAY";
            dic["timeout_express"] = "30m";
            parms.Add("biz_content", JsonHelper.StringDicToJson(dic));
            parms.Add("sign_type", AlipayConfig.AppSignType);

            string sign = AlipayRSAFromPkcs8.sign(AlipayCore.CreateLinkString(AlipayCore.FilterPara(parms)), AlipayConfig.PrivateKey, AlipayConfig.AppInputCharset);

            parms.Add("sign", sign);

            //parms.Add("sign", HttpUtility.UrlEncode(sign, e));

            //parms.Remove("biz_content");
            Dictionary <string, string> dicArray = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> temp in parms)
            {
                dicArray.Add(temp.Key, temp.Value);
            }

            //记录充值信息
            RechargeModel rech = new RechargeModel
            {
                Out_trade_no = outTradeNo,
                Account      = parmas["account"],
                SuiteId      = parmas["vossuiteid"],
                PlatForm     = "支付宝",
                Type         = int.Parse(parmas["type"]),
                Role         = int.Parse(parmas["role"])
            };
            bool addres = Recharge.AddRecharge(rech);

            if (!addres)
            {
                return(AjaxResult("error", "记录充值信息失败"));
            }

            //string content = JsonHelper.StringDicToJson(dicArray);
            //content = content.Substring(0, content.Length - 1) + ",\"biz_content\":" + JsonHelper.StringDicToJson(dic) + "}";
            string content = AlipayCore.CreateLinkStringUrlencode(AlipayCore.FilterAllPara(parms), Encoding.UTF8);

            return(AjaxResult("success", content));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 支付
        /// </summary>
        public ActionResult Pay()
        {
            string result = WebHelper.GetPostStr();
            NameValueCollection parmas = WebHelper.GetParmList(result);
            //if (parmas.Keys.Count < 5)
            //{
            //    return Content("缺少请求参数");
            //}
            //支付类型,必填,不能修改
            string paymentType = "1";

            //服务器异步通知页面路径,需http://格式的完整路径,不能加?id=123这类自定义参数
            string notifyUrl = string.Format("{0}/appalipay/notify", BSPConfig.ShopConfig.SiteUrl);

            //收款支付宝帐户
            string sellerEmail = AlipayConfig.Seller;
            //合作者身份ID
            string partner = AlipayConfig.Partner;
            //交易安全检验码
            string key = AlipayConfig.Key;

            //商户订单号
            string outTradeNo = "hmk" + DateTime.Now.ToString("yyMMdd") + Randoms.CreateRandomValue(6, true);
            //订单名称
            string subject = BSPConfig.ShopConfig.SiteTitle;
            //付款金额
            string totalFee = double.Parse(parmas["totalFee"]).ToString();
            //订单描述
            string body = "话费套餐";



            Encoding e = Encoding.GetEncoding(AlipayConfig.AppInputCharset);

            //把请求参数打包成数组
            SortedDictionary <string, string> parms = new SortedDictionary <string, string>();

            parms.Add("service", "mobile.securitypay.pay");
            parms["partner"] = partner;
            parms.Add("_input_charset", AlipayConfig.AppInputCharset);
            parms["seller_id"]    = sellerEmail;
            parms["out_trade_no"] = parmas["outtradeno"];
            parms["subject"]      = subject;
            parms["body"]         = body;
            parms["total_fee"]    = totalFee;
            parms.Add("notify_url", notifyUrl);
            parms.Add("payment_type", paymentType);
            parms.Add("it_b_pay", "30m");


            string sign = AlipayRSAFromPkcs8.sign(AlipayCore.CreateLinkString(AlipayCore.FilterPara(parms)), AlipayConfig.PrivateKey, AlipayConfig.AppInputCharset);

            parms.Add("sign", HttpUtility.UrlEncode(sign, e));
            parms.Add("sign_type", AlipayConfig.AppSignType);

            Dictionary <string, string> dicArray = new Dictionary <string, string>();

            foreach (KeyValuePair <string, string> temp in parms)
            {
                dicArray.Add(temp.Key, temp.Value);
            }

            //记录充值信息
            RechargeModel rech = new RechargeModel
            {
                Out_trade_no = outTradeNo,
                Account      = parmas["account"],
                SuiteId      = parmas["vossuiteid"],
                PlatForm     = "支付宝",
                Type         = int.Parse(parmas["type"]),
                Role         = int.Parse(parmas["role"])
            };
            bool addres = Recharge.AddRecharge(rech);

            if (!addres)
            {
                return(AjaxResult("error", "记录充值信息失败"));
            }

            string content = JsonHelper.StringDicToJson(dicArray);

            return(AjaxResult("success", content, true));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 支付
        /// </summary>
        public ActionResult Pay()
        {
            /*微信支付三步:统一下单》调起支付接口》支付结果通知*/
            string result = WebHelper.GetPostStr();
            NameValueCollection parmas = WebHelper.GetParmList(result);

            //if (parmas.Keys.Count < 5)
            //{
            //    return AjaxResult("error", "缺少请求参数");
            //}



            #region 支付操作============================

            #region 基本参数===========================
            //商户订单号
            string outTradeNo = "hmk" + DateTime.Now.ToString("yyMMdd") + Randoms.CreateRandomValue(6, true);
            //订单名称
            string subject = BSPConfig.ShopConfig.SiteTitle;
            //付款金额
            string totalFee = (double.Parse(parmas["totalfee"]) * 100).ToString();
            //时间戳
            string timeStamp = TenpayUtil.getTimestamp();
            //随机字符串
            string nonceStr = TenpayUtil.getNoncestr();
            //服务器异步通知页面路径
            string notifyUrl = string.Format("{0}/appwechat/notify", BSPConfig.ShopConfig.SiteUrl);


            //记录充值信息
            OWZX.Model.RechargeModel rech = new OWZX.Model.RechargeModel
            {
                Out_trade_no = outTradeNo,
                Account      = parmas["account"],
                SuiteId      = parmas["vossuiteid"],
                PlatForm     = "微信",
                Type         = int.Parse(parmas["type"]),
                Role         = int.Parse(parmas["role"])
            };
            bool addres = Recharge.AddRecharge(rech);
            if (!addres)
            {
                return(AjaxResult("error", "记录充值信息失败"));
            }

            //string access_token = "";
            //string url = string.Format("https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}", PayConfig.AppId, PayConfig.AppSecret);
            //string returnStr = HttpUtil.Get_Http(url, 120000);
            //LogUtil.WriteLog("returnStr 页面  returnStr:" + returnStr);
            //if (!returnStr.Contains("access_token"))
            //{
            //    return Content("");
            //}
            //else
            //{
            //    string[] list = returnStr.Split(',');
            //    access_token = list[0].Split(':')[1].Trim('"');
            //}

            //LogUtil.WriteLog("access_token 页面  access_token:" + access_token);

            //创建支付应答对象
            RequestHandler packageReqHandler = new RequestHandler(System.Web.HttpContext.Current);
            //初始化
            packageReqHandler.init();

            //设置package订单参数  具体参数列表请参考官方pdf文档,请勿随意设置
            packageReqHandler.setParameter("appid", PayConfig.AppId);
            packageReqHandler.setParameter("body", subject); //商品信息 127字符
            packageReqHandler.setParameter("mch_id", PayConfig.MchId);
            packageReqHandler.setParameter("nonce_str", nonceStr.ToLower());
            packageReqHandler.setParameter("notify_url", notifyUrl);
            packageReqHandler.setParameter("out_trade_no", outTradeNo);                  //商家订单号
            packageReqHandler.setParameter("spbill_create_ip", Request.UserHostAddress); //用户的公网ip,不是商户服务器IP
            packageReqHandler.setParameter("total_fee", totalFee);                       //商品金额,以分为单位(money * 100).ToString()
            packageReqHandler.setParameter("trade_type", "APP");
            //if (!string.IsNullOrEmpty(this.Attach))
            //    packageReqHandler.setParameter("attach", this.Attach);//自定义参数 127字符

            #endregion

            #region sign===============================
            string sign = packageReqHandler.CreateMd5Sign("key", PayConfig.AppKey);
            #endregion

            #region 获取package包======================
            packageReqHandler.setParameter("sign", sign);

            string data = packageReqHandler.parseXML();

            string prepayXml = HttpUtil.Send(data, "https://api.mch.weixin.qq.com/pay/unifiedorder");
            //LogUtil.WriteLog("WeiPay 页面  prepayXml:" + prepayXml);
            //获取预支付ID
            string      prepayId = "";
            string      package  = "";
            XmlDocument xdoc     = new XmlDocument();
            xdoc.LoadXml(prepayXml);
            XmlNode     xn  = xdoc.SelectSingleNode("xml");
            XmlNodeList xnl = xn.ChildNodes;
            if (xnl.Count > 7)
            {
                prepayId = xnl[7].InnerText;
                package  = string.Format("prepay_id={0}", prepayId);
                //LogUtil.WriteLog("WeiPay 页面  package:" + package);
            }
            if (xnl[0].InnerText.Trim() == "FAIL")
            {
                return(AjaxResult("error", "微信下单失败 " + xnl[1].InnerText));
            }
            #endregion

            #region 设置支付参数 输出页面  该部分参数请勿随意修改 ==============

            nonceStr = TenpayUtil.getNoncestr();
            RequestHandler paySignReqHandler = new RequestHandler(System.Web.HttpContext.Current);
            paySignReqHandler.setParameter("appid", PayConfig.AppId);
            paySignReqHandler.setParameter("noncestr", nonceStr.ToLower());
            paySignReqHandler.setParameter("package", "Sign=WXPay");
            paySignReqHandler.setParameter("partnerid", PayConfig.MchId);
            paySignReqHandler.setParameter("prepayid", prepayId);
            paySignReqHandler.setParameter("timestamp", timeStamp);
            string paySign = paySignReqHandler.CreateMd5Sign("key", PayConfig.AppKey);

            //LogUtil.WriteLog("WeiPay 页面  paySign:" + paySign);
            #endregion
            #endregion

            return(AjaxResult("success", string.Format("{0}\"appId\":\"{1}\",\"partnerId\":\"{2}\",\"prepayId\":\"{3}\",\"package\":\"{4}\",\"nonceStr\":\"{5}\",\"timeStamp\":\"{6}\",\"sign\":\"{7}\"{8}",
                                                       "{",
                                                       PayConfig.AppId,
                                                       PayConfig.MchId,
                                                       prepayId,
                                                       "Sign=WXPay",
                                                       nonceStr.ToLower(),
                                                       timeStamp,
                                                       paySign,
                                                       "}"), true));
        }