Beispiel #1
0
        /// <summary>
        /// 创建微信支付参数
        /// </summary>
        /// <param name="money"></param>
        /// <param name="vpm"></param>
        /// <param name="uniacid"></param>
        /// <param name="account"></param>
        /// <param name="weChatOrder"></param>
        /// <returns></returns>
        private WXPayModel GetCreatePacketsPayParams(decimal money, VoicePacketsModel vpm, string uniacid, AccountModel account, out WeChatOrder weChatOrder)
        {
            weChatOrder = new WeChatOrder()
            {
                CreateTime    = DateTime.Now,
                Total         = money,
                VoicePackets  = vpm,
                WeChatOrderID = ObjectId.GenerateNewId()
            };
            if (account.WeChatOrders == null)
            {
                collection.UpdateOne(x => x.AccountID.Equals(account.AccountID),
                                     Builders <AccountModel> .Update.Set(x => x.WeChatOrders, new List <WeChatOrder>()));
            }
            collection.UpdateOne(x => x.AccountID.Equals(account.AccountID),
                                 Builders <AccountModel> .Update.Push(x => x.WeChatOrders, weChatOrder));
            ///微擎相关
            JsApiPay jsApiPay = new JsApiPay();

            jsApiPay.openid    = account.OpenID;
            jsApiPay.total_fee = money.ConvertToMoneyCent();
            var body      = "test";
            var attach    = account.AccountID + "," + weChatOrder.WeChatOrderID.ToString();
            var goods_tag = "创建红包";

            jsApiPay.CreateWeChatOrder(uniacid, body, attach, goods_tag);
            var param = jsApiPay.GetJsApiParameters(We7Tools.Models.We7ProcessMiniConfig.GetAllConfig(uniacid).KEY);
            var wxpm  = JsonConvert.DeserializeObject <WXPayModel>(param);

            return(wxpm);
        }
        public ActionResult GetLogin(string code)
        {
            JsApiPay jsapi = new JsApiPay();

            jsapi.GetOpenidAndAccessTokenFromCode(code);

            string sessionid = Guid.NewGuid().ToString("N");

            Session[sessionid] = jsapi.openid + "|" + jsapi.access_token;

            var user = UserBLL.Read(jsapi.openid);

            if (user.Id > 0)
            {
                UserBLL.UserLoginInit(user);
                //VirtualUser vuser = new VirtualUser()
                //{
                //    id = user.Id,
                //    name = HttpUtility.UrlDecode(user.UserName, System.Text.Encoding.UTF8),
                //};
                var vuser = new
                {
                    id     = user.Id,
                    name   = HttpUtility.UrlDecode(user.UserName, System.Text.Encoding.UTF8),
                    status = user.Status,
                    avatar = user.Photo
                };
                return(Json(new { flag = true, sessionid = sessionid, userinfo = vuser, thesessionid = Session.SessionID }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { flag = false, msg = "no user", openid = jsapi.openid, sessionid = sessionid, thesessionid = Session.SessionID }, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #3
0
        /// <summary>
        /// wx支付提交请求
        /// </summary>
        /// <param name="clientOpenId"></param>
        /// <param name="totalfell">注意这里单位是 分</param>
        /// <returns></returns>
        public string WXNAVITE_SubRequest(string orderNumber, string totalfell)
        {
            if (!orderNumber.OrderNumberVerify())
            {
                return("-1");//提交失败 参数异常
            }


            JsApiPay jsApiPay = new JsApiPay();

            jsApiPay.total_fee   = AlipayConfig.MoneyFormatEco(totalfell).ParseInt();
            jsApiPay.orderNumber = orderNumber;
            try
            {
                string    url;
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(true, out url);
                string    wxJsApiParam       = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                return(url);
            }
            catch (Exception ex)
            {
                return("-2");//提交异常
            }
        }
Beispiel #4
0
        public void UnifiedOrder(string deviceid, string tariffid, string tradetype)
        {
            int tariff_id         = int.Parse(tariffid);
            SQLServerOperating s  = new SQLServerOperating();
            DataTable          dt = s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type  from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) });

            if (dt.Rows.Count <= 0)
            {
                return;
            }
            s.ExecuteSql("update TariffPackages set BuyCount=BuyCount+cast( ceiling(rand()*100) as int) where ID=@ID", new SqlParameter[] { new SqlParameter("ID", tariff_id) });
            s.Selects(" select ID, TariffName, Price, OldPrice, BuyCount, Type  from TariffPackages where ID=@tariff_id", new SqlParameter[] { new SqlParameter("tariff_id", tariff_id) });
            string total_fee   = dt.Rows[0]["Price"].toStringEmpty();
            string tariff_name = dt.Rows[0]["TariffName"].toStringEmpty();
            string device_name = s.Select("select case when DeviceName='' then SerialNumber else DeviceName end from Devices where deviceid=@deviceid", new SqlParameter[] { new SqlParameter("deviceid", deviceid) });

            if (string.IsNullOrEmpty(device_name))
            {
                return;
            }
            tariff_name = "GPS移动流量-" + device_name + " 充值" + tariff_name;
            JsApiPay jsApiPay = new JsApiPay();

            jsApiPay.user_id   = int.Parse(myHeader.UserID);
            jsApiPay.openid    = "";
            jsApiPay.total_fee = jsApiPay.user_id == 6 || jsApiPay.user_id == 7 ? new Random().Next(1, 10) : int.Parse(total_fee);
            jsApiPay.device_id = int.Parse(deviceid);
            jsApiPay.tariff_id = tariff_id;

            jsApiPay.product_body = tariff_name;
            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();

            jsApiPay.InsertMgooOrder();
            // AddOrder(myHeader.UserID,deviceid,"",);
        }
Beispiel #5
0
        /// <summary>
        /// 生成支付预处理的 WxPayData
        /// </summary>
        /// <param name="jsApiPay"></param>
        /// <param name="totalfee"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static WxPayData GenerateUnifiedWxPayData(this JsApiPay jsApiPay, string payKey)
        {
            var data = new WxPayData();

            var ran = new Random();

            data.Body       = "test";
            data.Attach     = "test";
            data.OutTradeNo = string.Format("{0}{1}{2}", Constants.WxConfig.MchId, DateTime.Now.ToString("yyyyMMddHHmmss"), ran.Next(999)); // "150848433120180905090411634"; //
            data.TimeStart  = DateTime.Now.ToString("yyyyMMddHHmmss");                                                                      // "20180905090412";// "20180905091412"; //

            data.TimeExpire     = DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss");                                                   //"20180905091412"; //
            data.AppId          = Constants.WxConfig.AppId;
            data.OpenId         = jsApiPay.OpenId;
            data.TradeType      = "JSAPI";
            data.GoodsTag       = "test";
            data.MchId          = Constants.WxConfig.MchId;
            data.Totalfee       = jsApiPay.TotalFee;
            data.NotifyUrl      = "https://www.yourc.club/api/";
            data.SpbillCreateIp = "118.24.139.228";
            data.NonceStr       = RandomGenerator.Instance.Genernate();
            data.SignType       = WxPayData.SIGN_TYPE_HMAC_SHA256;
            data.Sign           = data.MakeSign(payKey);
            //data.ProductId = "12235413214070356458058";
            //data.SceneInfo = "";
            if (data.WithRequired(out string errMsg) == false)
            {
                throw new WxPayException(errMsg);
            }
            return(data);
        }
Beispiel #6
0
        }                                               //H5调起JS API参数
        //
        // GET: /WxPay/
        public ActionResult Index()
        {
            //JSAPI支付预处理
            try
            {
                string  openid       = Utility.ChangeText.GetOpenId();
                string  total_fee    = Request["PayTotal"].ToString();
                decimal Paytotal_fee = Convert.ToDecimal(total_fee) * 100;
                string  OrdersId     = Request["OrdersId"];
                ViewData["OrdersId"] = OrdersId;
                //检测是否给当前页面传递了相关参数

                //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay();
                jsApiPay.openid    = openid;
                jsApiPay.total_fee = Convert.ToInt32(Paytotal_fee);

                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(OrdersId);
                wxJsApiParam          = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                ViewData["WxPayInfo"] = wxJsApiParam;
                ERP.WxPay.Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
            }
            catch (Exception ex)
            {
                Utility.Log.WriteTextLog("微信支付", "", "", "", ex.ToString());
            }
            return(View());
        }
Beispiel #7
0
        public ActionResult <string> GetJsApiPay(string openid, string total_fee)
        {
            //检测是否给当前页面传递了相关参数
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
            {
                return("页面传参出错,请返回重试");
            }

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay(_httpContext)
            {
                Openid    = openid,
                Total_Fee = int.Parse(total_fee)
            };

            //JSAPI支付预处理
            try
            {
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();

                //获取H5调起JS API参数
                string wxJsApiParam = jsApiPay.GetJsApiParameters();
                Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);

                //在页面上显示订单信息
                return(unifiedOrderResult.ToPrintStr());
            }
            catch (Exception ex)
            {
                return("下单失败,请返回重试" + ex.Message);
            }
        }
Beispiel #8
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Log.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay(this);
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                jsApiPay.GetOpenidAndAccessToken();
                //jsApiPay.openid = openid;

                //JSAPI支付预处理
                try
                {
                    int       orderID = RequestHelper.GetQueryString <int>("OrderID");
                    OrderInfo order   = OrderBLL.ReadOrder(orderID, Cookies.User.GetUserID(true));
                    jsApiPay.out_trade_no = order.OrderNumber;
                    jsApiPay.body         = "订单号:" + order.OrderNumber;
                    jsApiPay.total_fee    = (int)(order.ProductMoney * 100); //(order.ProductMoney - order.FavorableMoney + order.ShippingMoney + order.OtherMoney - order.Balance - order.CouponMoney).ToString();

                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                    wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                    Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                    //在页面上显示订单信息
                    Response.Write("<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td colspan=\"2\" align=\"center\">订单详情</td></tr><tr><td width=\"40%\" align=\"right\">订单号:</td><td width=\"60%\" align=\"left\">" + order.OrderNumber + "</td></tr><tr><td align=\"right\">总金额:</td><td align=\"left\">" + order.ProductMoney + "元</td></tr><tr><td  colspan=\"2\" align=\"center\"><div onclick=\"callpay()\" style=\"width:210px; height:50px; text-align:center; line-height:50px; border-radius: 15px;background-color:#00CD00; border:0px #FE6714 solid; cursor: pointer;  color:white;  font-size:16px; cursor:pointer;\" >立即支付</div></td></tr></table>");
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
                    //submit.Visible = false;
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// 卡券支付
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <string> CardPay(InsertOrderInput input)
        {
            var p = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.ProductId);

            if (p == null)
            {
                throw new UserFriendlyException("该商品不存在");
            }
            var order = new StoreOrder()
            {
                OpenId     = input.OpenId,
                PayType    = PayType.ActivityPay,
                OrderNum   = Guid.NewGuid().ToString("N"),
                OrderState = null,
                PayState   = null,
                Price      = p.Price,
                ProductId  = p.ProductId
            };
            await _storeRepository.InsertAsync(order);

            JsApiPay jsApiPay = new JsApiPay
            {
                Openid   = input.OpenId,
                TotalFee = p.Price
            };

            jsApiPay.GetUnifiedOrderResult(order.OrderNum, p.ProductName, p.Description);
            var param = jsApiPay.GetJsApiParameters();

            return(param);
        }
        /// <summary>
        /// 返回前端js 支付需要的支付参数
        /// </summary>
        public void GetWxJsApiParam(string total_fee)
        {
            string wxJsApiParam = string.Empty;

            string openid = GetOpenId();

            //检测是否给当前页面传递了相关参数
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
            {
                Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit...");
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
            }

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay(this);

            jsApiPay.openid    = openid;
            jsApiPay.total_fee = int.Parse(total_fee);

            //JSAPI支付预处理
            try
            {
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                //在页面上显示订单信息
                //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>");
                //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>");
            }
            catch (Exception ex)
            {
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>");
            }
            Response.Write(wxJsApiParam);
        }
Beispiel #11
0
        public static async Task <string> CorpPayAsync(int num)
        {
            var openid = "oO8Kd1bx8pPV6dGkOI7KILsrmPLY";
            var f      = (double)num / 100;

            if (openid != null)
            {
                JsApiPay jsApiPay = new JsApiPay(null);
                jsApiPay.openid    = openid;
                jsApiPay.total_fee = num;
                //JSAPI支付预处理
                try
                {
                    WxPayData unifiedOrderResult = jsApiPay.GetCompanycParameters("提现");

                    //在页面上显示订单信息
                    var info = unifiedOrderResult.ToPrintStr();
                    //System.Net.Http.HttpClient http = new System.Net.Http.HttpClient();
                    var xml = unifiedOrderResult.ToXml();

                    //HttpContent hc = new StringContent(unifiedOrderResult.ToXml());
                    var str = HttpService.Post(unifiedOrderResult.ToXml(), "https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers", true, 3);
                    //var messageTask =await http.PostAsync("https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers", hc);
                    JObject obj = new JObject();
                    //obj.Add("bill", uc.bill.ToString());
                    return(str);// await messageTask.Content.ReadAsStringAsync();
                }
                catch (Exception ex)
                {
                    return("下单失败");
                }
            }
            return(null);
        }
        public IActionResult ShowWeiXInPay(string openid, string orderNo = "asdfsdgbadfgsdf", string employeeid = null, decimal fAmt = 0)
        {
            orderNo = commercialRepository.ProduceID(4);
            var userAgent = (HttpContext.Request.Headers as Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.FrameRequestHeaders).HeaderUserAgent.ToString().ToLower();

            //检测是否给当前页面传递了相关参数
            if (string.IsNullOrEmpty(openid))
            {
                ViewData["error"] = "页面传参出错,请返回重试";
                Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit...");
                return(View());
            }
            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            var jsApiPay = new JsApiPay();

            jsApiPay.openid       = openid;
            jsApiPay.total_fee    = Convert.ToInt32(fAmt * 100);
            jsApiPay.notice_url   = $"{_setting.DomainName}/registerresult";
            jsApiPay.out_trade_no = orderNo;
            jsApiPay.body         = "奖励金";
            jsApiPay.attach       = employeeid;
            //JSAPI支付预处理
            try
            {
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                var       wxJsApiParam       = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                ViewData["wxJsApiParam"] = wxJsApiParam;
            }
            catch (Exception ex)
            {
                ViewData["error"] = $"下单失败,请返回重试,{ex.Message}";
            }
            return(View());
        }
Beispiel #13
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.out_trade_no.Value = Request.QueryString["out_trade_no"] == null ? "" : Request.QueryString["out_trade_no"];   //本地订单号

        Log.Info(this.GetType().ToString(), "page load");
        if (!IsPostBack)
        {
            JsApiPay jsApiPay = new JsApiPay(this);
            try
            {
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                jsApiPay.GetOpenidAndAccessToken();

                //获取收货地址js函数入口参数
                //wxEditAddrParam = jsApiPay.GetEditAddressParameters();
                ViewState["openid"] = jsApiPay.openid;
            }
            catch (Exception ex)
            {
                //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
                Button1.Visible = false;
                Label1.Visible  = false;
            }

            if (ViewState["openid"] != null && ViewState["openid"].ToString() != "")
            {
                //根据订单号获取订单金额
                int total_fee = (int)(GetMoeny(this.out_trade_no.Value) * 100);
                //total_fee=1;
                this.pay_url = "http://www.yiqixkj.com/PayInterface/WXPpay/JsApiPayPage.aspx?openid=" + ViewState["openid"].ToString() + "&out_trade_no=" + this.out_trade_no.Value + "&total_fee=" + total_fee;
            }
        }
    }
Beispiel #14
0
        public BaseApiResponse WxPay(WxPaymentRequest request)
        {
            request.CheckNotNull(nameof(request));
            JsApiPay jsApiPay = new JsApiPay();

            jsApiPay.openid    = request.OpenId;
            jsApiPay.total_fee = request.Amount;
            //JSAPI支付预处理
            try
            {
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(); //统一下单
                var       wxJsApiParam       = jsApiPay.GetJsApiParameters();    //获取H5调起JS API参数   这个要返回给客户端
                Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                //在页面上显示订单信息
                //unifiedOrderResult.ToPrintStr();
                return(new BaseApiResponse {
                    Message = wxJsApiParam
                });
            }
            catch (Exception ex)
            {
                return(new BaseApiResponse {
                    Code = 400, Message = ex.Message
                });
            }
        }
Beispiel #15
0
        /// <summary>
        /// 生成js调用相关数据
        /// </summary>
        public WxPayData JsApiPayPage()
        {
            //检测是否给当前页面传递了相关参数
            if (total_fee <= 0)
            {
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
                WxPayAPI.Log.Error(this.GetType().ToString(), "交易资金小于等于0");
                return(null);
            }
            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay(this);

            //jsApiPay.openid = "";
            jsApiPay.total_fee = total_fee;
            //JSAPI支付预处理
            try
            {
                //付款方信息
                string buyer = string.Empty;
                if (acc != null)
                {
                    buyer = string.IsNullOrWhiteSpace(acc.Ac_MobiTel1) ? acc.Ac_AccName : acc.Ac_MobiTel1;
                }
                Song.Entities.Organization org = Business.Do <IOrganization>().OrganSingle(orgid);
                //统一下单
                return(jsApiPay.GetUnifiedOrderResult("MWEB", org.Org_PlatformName, serial, appid, mchid, paykey, notify_url, buyer));
            }
            catch (Exception ex)
            {
                WxPayAPI.Log.Error(this.GetType().ToString(), "支付下单失败 : " + ex.Message);
                WxPayAPI.Log.Error(this.GetType().ToString(), "支付下单失败 : " + ex.StackTrace);
                return(null);
            }
        }
Beispiel #16
0
        /// <summary>
        /// 充值
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <string> ChargePay(InsertOrderInput input)
        {
            var order = new StoreOrder()
            {
                OpenId     = input.OpenId,
                PayType    = PayType.PayCharge,
                OrderNum   = Guid.NewGuid().ToString("N"),
                OrderState = null,
                PayState   = null,
                Price      = input.Price,
                ProductId  = input.ProductId
            };
            var type = await _chargeTypeRepository.FirstOrDefaultAsync(input.ProductId);

            if (type == null)
            {
                throw new UserFriendlyException("充值类型不存在");
            }
            await _storeRepository.InsertAsync(order);

            JsApiPay jsApiPay = new JsApiPay
            {
                Openid   = input.OpenId,
                TotalFee = type.Cost
            };

            jsApiPay.GetUnifiedOrderResult(order.OrderNum, "用户充值", "用户充值");
            var param = jsApiPay.GetJsApiParameters();

            return(param);
        }
Beispiel #17
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LogHelper.Info(this.GetType().ToString(), "page load");
            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.GetOpenidAndAccessToken();

                    //获取收货地址js函数入口参数
                    wxEditAddrParam     = jsApiPay.GetEditAddressParameters();
                    ViewState["openid"] = jsApiPay.openid;
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + "</span>");
                    Button1.Visible = false;
                    Button2.Visible = false;
                    Label1.Visible  = false;
                    Label2.Visible  = false;
                }
            }
        }
Beispiel #18
0
        public string Pays(int fee)
        {
            this.HttpContext.Session.SetInt32("fee", fee);
            var openid = HttpContext.Session.GetString("openid");

            if (openid != null)
            {
                //string url = "http://paysdk.weixin.qq.com/example/JsApiPayPage.aspx?openid=" + openid + "&total_fee=" + total_fee;
                //Response.Redirect(url);
                JsApiPay jsApiPay = new JsApiPay(this);
                jsApiPay.openid    = openid;
                jsApiPay.total_fee = fee;// int.Parse(total_fee);

                //JSAPI支付预处理
                try
                {
                    WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();
                    var       wxJsApiParam       = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                    Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                    //在页面上显示订单信息
                    var info = unifiedOrderResult.ToPrintStr();
                    return(wxJsApiParam);
                }
                catch (Exception ex)
                {
                    return("下单失败");
                }
            }
            return("-1");
        }
Beispiel #19
0
        public static Wxprepay wxPayOrderSomething(string openid, string total_fee, string couponType, Store store)
        {
            //var url = ConfigurationManager.AppSettings["wxpay"].ToString() + "?" + "grant_type=client_credential&appid=" + Appid + "&secret=" + Secret;
            Wxprepay wxprepay = new Wxprepay();

            //检测是否给当前页面传递了相关参数
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
            {
                return(null);
            }
            else
            {
                ////若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
                JsApiPay jsApiPay = new JsApiPay();
                //jsApiPay.openid = openid;
                //jsApiPay.total_fee = int.Parse(total_fee);

                //JSAPI支付预处理
                var       prepayid           = WxPayApi.GenerateOutTradeNo();
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(store.appid.Trim(), store.mchid.Trim(), total_fee, store.StoreName, couponType, openid, prepayid);
                var       wxJsApiParam       = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数

                LogHelper.WriteLog("wxJsApiParam:" + wxJsApiParam.ToString());
                //在页面上显示订单信息
                wxprepay.wxJsApiParam = wxJsApiParam;
                wxprepay.prepayid     = prepayid;
                return(wxprepay);
            }
        }
Beispiel #20
0
        /// <summary>
        /// 调用JSAPI
        /// </summary>
        /// <param name="openid">用户对于公众号唯一标识</param>
        /// <param name="total_fee"></param>
        /// <returns></returns>
        public static JSApi_model JsPay(string openid, string total_fee, string oName)
        {
            JSApi_model model        = new JSApi_model();
            string      wxJsApiParam = "";
            double      money        = double.Parse(total_fee);
            int         truemoney    = (int)(money * 100);

            //检测是否给当前页面传递了相关参数
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
            {
                return(null);
            }
            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay();

            //JSAPI支付预处理
            try
            {
                //进行统一支付认证
                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(oName, openid, truemoney);
                //获取H5调起JS API参数
                wxJsApiParam = jsApiPay.GetJsApiParameters();
                model        = wxJsApiParam.toJsonObject <JSApi_model>();
            }
            catch (Exception ex)
            {
                //Response.Write("<span style='color:#FF0000;font-size:20px'>" + ex + "下单失败,请返回重试" + "</span>");
                //submit.Visible = false;
            }
            return(model);
        }
Beispiel #21
0
        /// <summary>
        /// 进行微信授权验证,获取Openid
        /// </summary>
        /// <param name="UrlCode">URL参数</param>
        /// <param name="UrlHost">URL服务地址</param>
        /// <param name="UrlPath">URL路径</param>
        /// <returns></returns>
        public static string GetOpenidAndAccessToken(string UrlCode, string Url)
        {
            string   str      = "";
            JsApiPay jsApiPay = new JsApiPay();

            try
            {
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                jsApiPay.GetOpenidAndAccessToken(UrlCode, Url);

                if (string.IsNullOrEmpty(UrlCode))
                {
                    //如果UrlCode为空,则获取重定向URL
                    str = jsApiPay.url1;
                }
                else
                {
                    //如果UrlCode不为空,则解析Code,获取Openid
                    //用户统一下单接口
                    str  = jsApiPay.openid;
                    str += "," + jsApiPay.access_token;
                }
            }
            catch (Exception ex)
            {
            }
            return(str);
        }
Beispiel #22
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            JsApiPay jsApiPay = new JsApiPay(this);
            try
            {
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                jsApiPay.GetOpenidAndAccessToken();

                //获取收货地址js函数入口参数
                openid = jsApiPay.openid;
                HttpContext.Current.Response.Cookies.Add(new HttpCookie("openid", openid)
                {
                    HttpOnly = true
                });
                using (var db = new DBConnection())
                {
                    //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "您的id为" + HttpContext.Current.Request.Cookies["userid"].Value + ",微信标识为:" + openid + "</span>");
                    DataTable        dt  = db.GetEmptyDataTable("tb_b_user");
                    DataTableTracker dtt = new DataTableTracker(dt);
                    DataRow          dr  = dt.NewRow();
                    dr["UserID"] = HttpContext.Current.Request.Cookies["userid"].Value;
                    dr["OpenID"] = openid;
                    dt.Rows.Add(dr);
                    db.UpdateTable(dt, dtt);
                }
                //new Handler().SendWeText(HttpContext.Current.Request.Cookies["openid"].Value, "欢迎登陆");
            }
            catch (Exception ex)
            {
                //Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex + "</span>");
            }
        }
    }
        public IActionResult GetOpenID(string redirectUrl, string code = null, string employeeid = null)
        {
            var jsApiPay = new JsApiPay();

            try
            {
                //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                var url = jsApiPay.GetOpenidAndAccessToken($@"{_setting.DomainName}/getopenid/{employeeid}?redirectUrl=" + redirectUrl, code);

                if (string.IsNullOrEmpty(url))
                {
                    if (employeeid == "employee")
                    {
                        return(Redirect($"/login?openID={jsApiPay.openid}"));
                    }
                    return(Redirect($"/wxpay?openid={jsApiPay.openid}&employeeid={employeeid}"));
                }
                else
                {
                    return(Redirect(url));
                }
            }
            catch (Exception exc)
            {
                return(NotFound());
            }
        }
Beispiel #24
0
        /// <summary>
        /// 在线支付
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task <string> LinePay(InsertOrderInput input)
        {
            var p = await _productRepository.FirstOrDefaultAsync(c => c.Id == input.ProductId);

            if (p == null)
            {
                throw new UserFriendlyException("该商品不存在");
            }
            var order = await _storeRepository.FirstOrDefaultAsync(c => c.OrderNum.Equals(input.Order));

            if (order == null)
            {
                order = new StoreOrder()
                {
                    FastCode   = input.FastCode,
                    OpenId     = input.OpenId,
                    PayType    = PayType.LinePay,
                    OrderType  = input.OrderType,
                    OrderState = null,
                    OrderNum   = input.Order,
                    DeviceNum  = input.Device,
                    PayState   = null,
                    Price      = p.Price,
                    ProductId  = p.ProductId
                };
            }
            else
            {
                if (order.PayState.HasValue && order.PayState.Value)
                {
                    throw new UserFriendlyException("该订单已支付,不可重复付款");
                }
                order.OpenId    = input.OpenId;
                order.Price     = p.Price;
                order.FastCode  = input.FastCode;
                order.OrderType = input.OrderType;
                order.PayType   = PayType.LinePay;
            }
            JsApiPay jsApiPay = new JsApiPay
            {
                Openid   = input.OpenId,
                TotalFee = p.Price
            };
            var card = await _cardRepository.FirstOrDefaultAsync(c => c.Key == input.Key.Value);

            //使用优惠券
            if (card != null)
            {
                order.UseCard = input.Key;
                var t = p.Price - card.Cost;
                jsApiPay.TotalFee = t <= 0 ? 0 : t;
            }
            await _storeRepository.InsertOrUpdateAsync(order);

            jsApiPay.GetUnifiedOrderResult(order.OrderNum, p.ProductName, p.Description);
            var param = jsApiPay.GetJsApiParameters();

            return(param);
        }
Beispiel #25
0
        public Result <PayResult> Create(PayData data)
        {
            Result <PayResult> result = new Result <PayResult>();

            result.Msg = "生成支付订单失败";
            if (data != null && !string.IsNullOrWhiteSpace(data.iduser) && !string.IsNullOrWhiteSpace(data.orderno))
            {
                try
                {
                    long _iduser  = long.Parse(data.iduser);
                    long _orderno = long.Parse(data.orderno);
                    using (TCom.EF.TN db = new TCom.EF.TN())
                    {
                        TCom.EF.User u = db.Users.Where(m => m.iduser == _iduser && m.inuse == true).FirstOrDefault();
                        if (u != null)
                        {
                            TCom.EF.MyOrder o = db.MyOrders.Where(m => m.orderno == _orderno && m.inuse == true).FirstOrDefault();
                            if (o != null)
                            {
                                if (o.paystatus == PayStatus.WeiXin_CLOSED)
                                {
                                    o.status = OrderStatus.Close;
                                    db.SaveChanges();
                                    result.Msg = "订单已关闭";
                                }
                                else
                                {
                                    o.paystatus = PayStatus.WaitPay;
                                    if (o.payway != "weixin")
                                    {
                                        o.payway = "weixin";
                                        if (db.SaveChanges() <= 0)
                                        {
                                            result.Msg = "更新支付方式失败";
                                            return(result);
                                        }
                                    }
                                    result.Data = new PayResult
                                    {
                                        order = JsApiPay.PayOrder(o, u)
                                    };
                                    result.Code = R.Ok;
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    result.Code = R.Error;
                    result.Msg  = "拉取订单出错";
                }
            }
            else
            {
                result.Msg = "不存在该订单";
            }
            return(result);
        }
        //   /WeChat/WeChatPay/JsApiPayPage?uid=123&total_fee=0.01return_url=oksMlwPF5Y1KQvoi8AklF-lUwnYQ&
        public ActionResult JsApiPayPage(double total_fee, string return_url)
        {
            string openid = DataContext.UserId;

            if (!openid.HasValue() || !return_url.HasValue())
            {
                return(Content("参数错误"));
            }
            var money        = (int)(total_fee * 100);
            var wxJsApiParam = "";

            //检测是否给当前页面传递了相关参数
            if (string.IsNullOrEmpty(openid))
            {
                return(Content("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>"));;
            }

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            var jsApiPay = new JsApiPay <Qx.Account.Configs.Setting.WxPayConfig.Sports>(HttpContext);

            jsApiPay.openid    = openid;
            jsApiPay.total_fee = money;
            var poid = "";

            //JSAPI支付预处理
            try
            {
                //1.创建支付订单
                var chargePayOrder = _accountPayService.CreatePayOrder(Qx.Account.Configs.Setting.PLATE_WECHAT_ACCOUNT,
                                                                       openid,
                                                                       total_fee,
                                                                       PayOrderTypeEnum.WeChatPay,
                                                                       PaymentTypeEnum.Rmb);
                poid = chargePayOrder.PayOrder.PO_ID;
                var trade_no = chargePayOrder.PayOrder.PO_ID;
                //2.同步支付订单
                _accountPayService.SyncPayOrder(chargePayOrder);

                //3.通知微信服务器
                var unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(trade_no, "充值" + (total_fee) + "元");
                wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                if (!wxJsApiParam.HasValue())
                {
                    throw new Exception("下单失败");
                }

                //在页面上显示订单信息
                return(View("JsApiPayPage", JsApiPayPage_M.Init(wxJsApiParam,
                                                                "<span style='color:#00CD00;font-size:20px'>充值" + total_fee + "元</span><br/><span style='color:#00CD00;font-size:20px'>" + "</span>",
                                                                //"<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/><span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>",
                                                                total_fee + "", poid, DataContext.UserId, return_url
                                                                )));
            }
            catch (Exception ex)
            {
                return(View("JsApiPayPage", JsApiPayPage_M.Init(wxJsApiParam,
                                                                "<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "<hr/>" + ex.Data + "<hr/>" + ex.InnerException + "<hr/>" + ex.Message + "<hr/>" + ex.StackTrace + "</span>", "", poid, DataContext.UserId, return_url)));
            }
        }
Beispiel #27
0
    protected void Page_Load(object sender, EventArgs e)
    {
        Log.Info(this.GetType().ToString(), "page load");
        if (!IsPostBack)
        {
            Cms.Model.C_user userModel    = adminUser.GetuserLoginState();
            int               otid        = Convert.ToInt32(Request["orderid"].ToString());
            Cms.BLL.C_order   otBll       = new Cms.BLL.C_order();
            Cms.Model.C_order orderEntity = otBll.GetModel(otid);
            order_num.Text = orderEntity.order_num;
            litMoney.Text  = Convert.ToDecimal(orderEntity.price_sum).ToString("0.00");
            litDate.Text   = orderEntity.updateTime.ToString();
            string openid    = userModel.openid.ToString();
            string total_fee = ((int)(Convert.ToDecimal(orderEntity.price_sum) * 100)).ToString();
            //检测是否给当前页面传递了相关参数
            if (string.IsNullOrEmpty(openid) || string.IsNullOrEmpty(total_fee))
            {
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面传参出错,请返回重试" + "</span>");
                Log.Error(this.GetType().ToString(), "This page have not get params, cannot be inited, exit...");
                submit.Visible = false;
                return;
            }

            //若传递了相关参数,则调统一下单接口,获得后续相关接口的入口参数
            JsApiPay jsApiPay = new JsApiPay(this);
            jsApiPay.openid  = openid;
            jsApiPay.orderid = orderEntity.order_num;
            DataTable dt = new Cms.BLL.C_ordersub().GetList("order_id=" + orderEntity.id).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                jsApiPay.productName = dt.Rows[0]["title"].ToString();
            }
            else
            {
                jsApiPay.productName = "泓源鼎盛酒业商品";
            }
            try
            {
                jsApiPay.total_fee = int.Parse(total_fee);


                //JSAPI支付预处理

                WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult();

                wxJsApiParam = jsApiPay.GetJsApiParameters();//获取H5调起JS API参数
                orderNum     = Request["orderid"].ToString();
                Log.Debug(this.GetType().ToString(), "wxJsApiParam : " + wxJsApiParam);
                //在页面上显示订单信息
                //Response.Write("<span style='color:#00CD00;font-size:20px'>订单详情:</span><br/>");
                //Response.Write("<span style='color:#00CD00;font-size:20px'>" + unifiedOrderResult.ToPrintStr() + "</span>");
            }
            catch (Exception ex)
            {
                Response.Write("<span style='color:#FF0000;font-size:20px'>" + "下单失败,请返回重试" + "</span>" + ex.Message.ToString() + Convert.ToDecimal(orderEntity.price_sum).ToString());
                submit.Visible = false;
            }
        }
    }
Beispiel #28
0
        /// <summary>
        /// 返回当前微信客户端的OpenId,每个客户端在每个公众号里的OpenId是唯一的
        /// </summary>
        /// <returns></returns>
        public static string GetOpenId()
        {
            JsApiPay jsApiPay = new JsApiPay(System.Web.HttpContext.Current);

            jsApiPay.GetOpenidAndAccessToken();
            Log.Debug("GetOpenId", "openid : " + jsApiPay.openid);
            return(jsApiPay.openid);
        }
Beispiel #29
0
        public string CreateWxJsApiParam()
        {
            JsApiPay  jsApiPay           = new JsApiPay();
            WxPayData unifiedOrderResult = jsApiPay.GetUnifiedOrderResult(this);

            Prepay_id = (string)unifiedOrderResult.GetValue("prepay_id");
            string wxJsApiParam = jsApiPay.GetJsApiParameters();

            return(wxJsApiParam);
        }
Beispiel #30
0
        public BaseApiResponse GetOpenIdAndAccessToken(string code)
        {
            code.CheckNotNullOrEmpty(nameof(code));
            JsApiPay jsApiPay = new JsApiPay();

            jsApiPay.GetOpenidAndAccessTokenFromCode(code);
            return(new GetOpenIdAndAccessTokenResponse {
                Message = "", openid = jsApiPay.openid, access_token = jsApiPay.access_token
            });
        }