public string SendCouponManually(int userId)
        {
            return("");

            var success  = "";
            var error    = "";
            var doResult = "";
            var list     = new List <M_SendInfo>();

            list.Add(new M_SendInfo
            {
                CouponKey       = Configurator.JsonServiceUrl("NewMemberCouponKey"),
                UserId          = userId,
                SendDescription = "系统发送"
            });
            var request = new CouponSendDetail
            {
                Operator = UserInfo.UserSysNo,
                ClientIp = ServiceData.GetClientIP(),
                Sends    = list
            };
            bool DoFlag = BaseCouponConfigClient.Instance.SendCopuonFunction(request, out doResult, out success, out error);

            if (string.IsNullOrEmpty(doResult))
            {
                if (DoFlag)
                {
                    doResult = "发券成功。";

                    VIPClient.Instance.Add168CouponLog(userId.ToString());
                }
                else
                {
                    doResult = "发券失败。";
                }
            }

            if (error == null || error == "null")
            {
                error = "";
            }

            if (success == null || success == "null")
            {
                success = "";
            }

            return(doResult + ";" + success + ";" + error);
        }
        //发送优惠券
        public JsonResult Save(string memNos, string couponKey)
        {
            var result = new BaseResponse()
            {
                DoFlag = false, DoResult = "发送失败,请稍后重试... ..."
            };

            try
            {
                var list = new List <M_SendInfo>();
                memNos = memNos.Replace(",", ",").Trim();//替换中文字符
                foreach (var item in memNos.Split(','))
                {
                    var userId = 0;
                    int.TryParse(item, out userId);
                    list.Add(new M_SendInfo
                    {
                        CouponKey       = couponKey,
                        UserId          = userId,
                        SendDescription = "系统发送"
                    });
                }
                var request = new CouponSendDetail
                {
                    Operator = UserInfo.UserSysNo,
                    ClientIp = ServiceData.GetClientIP(),
                    Sends    = list
                };
                var success  = "";
                var error    = "";
                var doResult = "";
                result.DoFlag   = BaseCouponConfigClient.Instance.SendCopuonFunction(request, out doResult, out success, out error);
                result.DoResult = doResult + ";" + success + ";" + error;
            }
            catch (Exception ex)
            {
                result.DoResult = "发送异常,请稍后重试... ...";
            }
            return(Json(result, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        private static string SecretKey = "pointcom201708150930000000000000";        //用户名,应用AppSecret

        /// <summary>
        /// 统一下单 预支付交易会话标识
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public Ptcp <string> GetWxPayRequestData(M_GetWxPayRequestDataReq req)
        {
            var ptcp = new Ptcp <string>();

            //货币类型
            //string feeType = CurrencyType;
            string notifyUrl = NotifyUrl;
            //string lastTime = DateTime.Now.AddHours(24).ToString();

            //微信支付金额为:分
            decimal amount    = req.RechargeAmount * 100;
            int     total_fee = (int)amount;

            if (string.IsNullOrEmpty(AppId))
            {
                var errMsg = string.Format("订单号{0}]商户号不能为空!", req.OrderNo);
                Logger.Write(LoggerLevel.Error, "GetWxPayRequestData", "商户号不能为空", errMsg);

                ptcp.DoResult = "商户号不能为空";
                return(ptcp);
            }

            #region  APP支付预处理 统一下单

            //APP支付预处理
            //统一下单
            WxPayData data = new WxPayData();

            if (!string.IsNullOrEmpty(req.GoodsName) && req.GoodsName.Length > 45)
            {
                req.GoodsName = req.GoodsName.Substring(0, 45) + "...";
            }

            data.SetValue("body", req.GoodsName);
            data.SetValue("attach", req.UserId);           //微信原样返回,存入会员ID
            data.SetValue("out_trade_no", req.OrderNo);
            data.SetValue("total_fee", total_fee);
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            //data.SetValue("time_expire", lastTime);
            //data.SetValue("goods_tag", "test");//商品标签
            data.SetValue("trade_type", "APP");
            //data.SetValue("openid", info.OpenId);
            data.SetValue("notify_url", notifyUrl);                       //异步通知notifyUrl

            data.SetValue("appid", AppId);                                //公众账号ID
            data.SetValue("mch_id", mch_id);                              //商户号
            data.SetValue("spbill_create_ip", ServiceData.GetClientIP()); //终端ip
            data.SetValue("nonce_str", WxPayData.GenerateNonceStr());     //随机字符串

            WxPayData result = WxPayData.UnifiedOrder(data, SecretKey);
            if (!result.IsSet("appid") || !result.IsSet("prepay_id") ||
                result.GetValue("prepay_id").ToString() == "")
            {
                string err_code_des = "";
                if (result.GetValue("err_code_des") != null)
                {
                    err_code_des = result.GetValue("err_code_des").ToString();
                }
                else if (result.GetValue("return_msg") != null)
                {
                    err_code_des = result.GetValue("return_msg").ToString();
                }
                else
                {
                    err_code_des = result.ToJson();
                }

                var errMsg = string.Format("订单号{0}]统一下单获取预付单号失败!{1}", req.OrderNo, err_code_des);
                Logger.Write(LoggerLevel.Error, "GetWxPayRequestData", "获取预付单号失败1", errMsg);

                ptcp.DoResult = string.Format("获取预付单号失败,{0}", err_code_des);
                return(ptcp);
            }

            WxPayData unifiedOrderResult = result;
            WxPayData jsApiParam         = new WxPayData();
            jsApiParam.SetValue("appid", result.GetValue("appid"));
            jsApiParam.SetValue("noncestr", WxPayData.GenerateNonceStr());
            jsApiParam.SetValue("package", "Sign=WXPay");

            jsApiParam.SetValue("partnerid", mch_id);
            jsApiParam.SetValue("prepayid", result.GetValue("prepay_id"));

            jsApiParam.SetValue("timestamp", WxPayData.GenerateTimeStamp());
            jsApiParam.SetValue("sign", jsApiParam.MakeSign(SecretKey));

            var wxJsApiParam = jsApiParam.ToJson();
            if (string.IsNullOrEmpty(wxJsApiParam))
            {
                var errMsg = string.Format("订单号{0}]获取请求报文失败!", req.OrderNo);
                Logger.Write(LoggerLevel.Error, "GetWxPayRequestData", "获取预付单号失败2", errMsg);

                ptcp.DoResult = "获取支付请求报文失败";
                return(ptcp);
            }

            ptcp.DoResult = wxJsApiParam;
            ptcp.DoFlag   = PtcpState.Success;

            #endregion

            return(ptcp);
        }