Beispiel #1
0
        /// <summary>
        /// 提交
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void btnPay_Click(object sender, EventArgs e)
        {
            string strAccounts   = CtrlHelper.GetText(txtPayAccounts);
            string strReAccounts = CtrlHelper.GetText(txtPayReAccounts);
            int    amount        = CtrlHelper.GetInt(txtPayAmount, 0);

            if (strAccounts == "")
            {
                RenderAlertInfo(true, "抱歉,请输入充值帐号。", 2);
                return;
            }
            if (strReAccounts != strAccounts)
            {
                RenderAlertInfo(true, "抱歉,两次输入的帐号不一致。", 2);
                return;
            }

            // 验证是否合法的金额
            if (amount <= 0)
            {
                RenderAlertInfo(true, "请输入正确的充值金额", 2);
                return;
            }

            // 支付方法
            string      orderid     = PayHelper.GetOrderIDByPrefix("WX");
            OnLineOrder onlineOrder = new OnLineOrder();

            onlineOrder.ShareID = 401;
            onlineOrder.OrderID = orderid;

            if (Fetch.GetUserCookie() == null)
            {
                onlineOrder.OperUserID = 0;
            }
            else
            {
                onlineOrder.OperUserID = Fetch.GetUserCookie().UserID;
            }
            onlineOrder.Accounts    = strAccounts;
            onlineOrder.OrderAmount = amount;
            onlineOrder.IPAddress   = GameRequest.GetUserIP();

            //生成订单
            Message umsg = FacadeManage.aideTreasureFacade.RequestOrder(onlineOrder);

            if (!umsg.Success)
            {
                RenderAlertInfo(true, umsg.Content, 2);
                return;
            }

            //随机字符串
            string nonce_str = WeiXinHelper.GetNonce_str();
            //商品描述
            string body = "充值游戏豆";
            //商户订单号
            string out_trade_no = orderid;
            //交易金额(分为单位)
            int total_fee = Convert.ToInt32(amount * 100);
            //终端IP
            string spbill_create_ip = Utility.UserIP;
            //回调地址
            string notify_url = "http://" + Request.Url.Authority + "/Pay/WX/WxpayNotify.aspx";
            //商品ID
            string product_id = orderid.Substring(2, orderid.Length - 2);

            SortedDictionary <string, object> dic = new SortedDictionary <string, object>();

            dic.Add("nonce_str", nonce_str);
            dic.Add("body", body);
            dic.Add("trade_type", "NATIVE");
            dic.Add("out_trade_no", out_trade_no);
            dic.Add("total_fee", total_fee);
            dic.Add("spbill_create_ip", spbill_create_ip);
            dic.Add("notify_url", notify_url);
            dic.Add("product_id", product_id);

            pnlContinue.Visible = false;
            RenderAlertInfo(false, "页面正跳转到支付平台,请稍候。。。", 2);

            SortedDictionary <string, object> result = WeiXinHelper.UnifiedOrder(dic, 10);
            string        code    = result["return_code"].ToString();
            StringBuilder builder = new StringBuilder();

            builder.AppendLine(CreateInputHidden("return_code", code));
            builder.AppendLine(CreateInputHidden("return_msg", result["return_msg"].ToString()));
            if (code == "SUCCESS")
            {
                builder.AppendLine(CreateInputHidden("code_url", result["code_url"].ToString()));
                builder.AppendLine(CreateInputHidden("orderID", orderid));
                builder.AppendLine(CreateInputHidden("amount", amount.ToString()));
            }

            formData = builder.ToString();

            js = "<script>window.onload = function() { document.forms[0].submit(); }</script>";
        }
Beispiel #2
0
        public void btnPay_Click(object sender, System.EventArgs e)
        {
            string text  = CtrlHelper.GetText(this.txtPayAccounts);
            string text2 = CtrlHelper.GetText(this.txtPayReAccounts);
            int    @int  = CtrlHelper.GetInt(this.txtPayAmount, 0);

            if (text == "")
            {
                this.RenderAlertInfo(true, "抱歉,请输入充值帐号。", 2);
            }
            else
            {
                if (text2 != text)
                {
                    this.RenderAlertInfo(true, "抱歉,两次输入的帐号不一致。", 2);
                }
                else
                {
                    if (@int <= 0)
                    {
                        this.RenderAlertInfo(true, "请输入正确的充值金额", 2);
                    }
                    else
                    {
                        string      orderIDByPrefix = PayHelper.GetOrderIDByPrefix("WX");
                        OnLineOrder onLineOrder     = new OnLineOrder();
                        onLineOrder.ShareID = 401;
                        onLineOrder.OrderID = orderIDByPrefix;
                        if (Fetch.GetUserCookie() == null)
                        {
                            onLineOrder.OperUserID = 0;
                        }
                        else
                        {
                            onLineOrder.OperUserID = Fetch.GetUserCookie().UserID;
                        }
                        onLineOrder.Accounts    = text;
                        onLineOrder.OrderAmount = @int;
                        onLineOrder.IPAddress   = GameRequest.GetUserIP();
                        Message message = FacadeManage.aideTreasureFacade.RequestOrder(onLineOrder);
                        if (!message.Success)
                        {
                            this.RenderAlertInfo(true, message.Content, 2);
                        }
                        else
                        {
                            string nonce_str = WeiXinHelper.GetNonce_str();
                            string value     = "充值游戏豆";
                            string value2    = orderIDByPrefix;
                            int    num       = System.Convert.ToInt32(@int * 100);
                            string userIP    = Utility.UserIP;
                            string value3    = "http://" + base.Request.Url.Authority + "/Pay/WX/WxpayNotify.aspx";
                            string value4    = orderIDByPrefix.Substring(2, orderIDByPrefix.Length - 2);
                            SortedDictionary <string, object> sortedDictionary = new SortedDictionary <string, object>();
                            sortedDictionary.Add("nonce_str", nonce_str);
                            sortedDictionary.Add("body", value);
                            sortedDictionary.Add("trade_type", "NATIVE");
                            sortedDictionary.Add("out_trade_no", value2);
                            sortedDictionary.Add("total_fee", num);
                            sortedDictionary.Add("spbill_create_ip", userIP);
                            sortedDictionary.Add("notify_url", value3);
                            sortedDictionary.Add("product_id", value4);
                            this.pnlContinue.Visible = false;
                            this.RenderAlertInfo(false, "页面正跳转到支付平台,请稍候。。。", 2);
                            SortedDictionary <string, object> sortedDictionary2 = WeiXinHelper.UnifiedOrder(sortedDictionary, 10);
                            string text3 = sortedDictionary2["return_code"].ToString();
                            System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
                            stringBuilder.AppendLine(this.CreateInputHidden("return_code", text3));
                            stringBuilder.AppendLine(this.CreateInputHidden("return_msg", sortedDictionary2["return_msg"].ToString()));
                            if (text3 == "SUCCESS")
                            {
                                stringBuilder.AppendLine(this.CreateInputHidden("code_url", sortedDictionary2["code_url"].ToString()));
                                stringBuilder.AppendLine(this.CreateInputHidden("orderID", orderIDByPrefix));
                                stringBuilder.AppendLine(this.CreateInputHidden("amount", @int.ToString()));
                            }
                            this.formData = stringBuilder.ToString();
                            this.js       = "<script>window.onload = function() { document.forms[0].submit(); }</script>";
                        }
                    }
                }
            }
        }