Ejemplo n.º 1
0
        /// <summary>
        /// 生成请求时的签名
        /// </summary>
        /// <param name="sPara">请求给支付宝的参数数组</param>
        /// <returns>签名结果</returns>
        private static string BuildRequestMysign(Dictionary <string, string> sPara)
        {
            //把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串
            string prestr = AlipayCore.CreateLinkString(sPara);

            //把最终的字符串签名,获得签名结果
            string mysign = "";

            switch (_sign_type)
            {
            case "MD5":
                mysign = Mozart.Payment.AliPay.AlipayMD5.Sign(prestr, _key, _input_charset);
                break;

            case "RSA":
                mysign = AlipayRSAFromPkcs8.sign(prestr, _private_key, _input_charset);
                break;

            case "0001":
                mysign = AlipayRSAFromPkcs8.sign(prestr, _private_key, _input_charset);
                break;

            default:
                mysign = "";
                break;
            }

            return(mysign);
        }
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()
        {
            //订单id
            int oid = WebHelper.GetQueryInt("oid");

            //订单信息
            OrderInfo orderInfo = Orders.GetOrderByOid(oid);

            if (orderInfo == null || orderInfo.OrderState != (int)OrderState.WaitPaying)
            {
                return(Content(""));
            }

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

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

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

            //商户订单号
            string outTradeNo = orderInfo.Oid.ToString() + Randoms.CreateRandomValue(10, false);
            //订单名称
            string subject = BSPConfig.ShopConfig.SiteTitle + "购物";
            //付款金额
            string totalFee = orderInfo.SurplusMoney.ToString();
            //订单描述
            string body = "订单编号为:" + orderInfo.OSN;

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

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

            parms.Add("partner", partner);
            parms.Add("seller_id", sellerEmail);
            parms.Add("out_trade_no", outTradeNo);
            parms.Add("subject", subject);
            parms.Add("body", body);
            parms.Add("total_fee", totalFee);
            parms.Add("notify_url", notifyUrl);
            parms.Add("service", "mobile.securitypay.pay");
            parms.Add("payment_type", paymentType);
            parms.Add("_input_charset", AlipayConfig.AppInputCharset);
            parms.Add("it_b_pay", "30m");
            parms.Add("show_url", "m.alipay.com");

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

            string content = AlipayCore.CreateLinkString(dicArray);

            return(Content("{ \"orderString\":\"" + content + "\" }"));
        }