Ejemplo n.º 1
0
        /// <summary>
        /// 查询订单
        /// </summary>
        /// <param name="transaction_id"></param>
        /// <returns></returns>
        private bool AppQueryOrder(string transaction_id)
        {
            AppPayData req = new AppPayData();

            req.SetValue("transaction_id", transaction_id);
            AppPayData res = AppPayApi.OrderQuery(req);

            if (res.GetValue("return_code").ToString() == "SUCCESS" && res.GetValue("result_code").ToString() == "SUCCESS")
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 微信app支付
        /// </summary>
        /// <param name="oidStr">订单编号</param>
        /// <returns></returns>
        public ActionResult WxPayApp(string oidStr)
        {
            // App调用只能传参
            int[] oIds = Serialize.JsonTo <List <int> >(oidStr).ToArray();

            #region 验证订单是否有效

            decimal payPrice = 0;
            string  detail   = "";

            /// 验证订单是否有效,并统计订单总金额
            /// ...

            #endregion

            #region 统一下单
            try
            {
                //string userId = LoginUser.Id.ToString();
                var        address = WebConfigurationManager.AppSettings["WxAppNotifyUrl"].ToString();
                AppPayData data    = new AppPayData();
                data.SetValue("body", "民政社工培训-课程购买");
                //data.SetValue("attach", userId + "|" + String.Join(",", oIds).ToString());
                data.SetValue("attach", String.Join(",", oIds).ToString());
                Random rd     = new Random();
                var    payNum = DateTime.Now.ToString("yyyyMMddHHmmss") + rd.Next(0, 1000).ToString().PadLeft(3, '0');
                data.SetValue("out_trade_no", payNum);
                data.SetValue("detail", detail.Substring(0, detail.Length - 1));
                data.SetValue("total_fee", Convert.ToInt32(payPrice * 100));
                data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
                data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
                data.SetValue("notify_url", address);

                //注意,这里交易方式是APP
                data.SetValue("trade_type", "APP");

                AppPayData result    = AppPayApi.UnifiedOrder(data);
                var        appid     = "";
                var        partnerid = "";
                var        prepayid  = "";
                var        package   = "";
                var        nonceStr  = "";
                var        timestamp = "";
                var        sign      = "";
                if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
                {
                    return(Json(false, "下单失败!"));
                }
                else
                {
                    //统一下单
                    /// 修改订单状态
                    //OrderBll.Value.UpdateOrderApp(oIds, payNum);

                    appid     = result.GetValue("appid").ToString();
                    nonceStr  = result.GetValue("nonce_str").ToString();
                    partnerid = result.GetValue("mch_id").ToString();
                    prepayid  = result.GetValue("prepay_id").ToString();
                    package   = "Sign=WXPay";// "prepay_id=" + result.GetValue("prepay_id").ToString();
                }
                var signType = "MD5";
                timestamp = ((DateTime.Now.Ticks - TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)).Ticks) / 10000).ToString();
                AppPayData applet = new AppPayData();
                applet.SetValue("appid", appid);
                applet.SetValue("noncestr", nonceStr);
                applet.SetValue("package", package);
                applet.SetValue("partnerid", partnerid);
                applet.SetValue("prepayid", prepayid);
                //applet.SetValue("signType", signType);
                applet.SetValue("timestamp", timestamp);
                sign = applet.MakeSign();
                return(Json(new { appid, partnerid, prepayid, package, nonceStr, timestamp, sign }));
            }
            catch (Exception ex)
            {
                return(Json(false, "缺少参数"));
            }

            #endregion
        }