Example #1
0
        public string GetJsApiParametersnew(PayCenterSetting setting)
        {
            WxPayData jsApiParam = new WxPayData();

            jsApiParam.SetValue("appId", unifiedOrderResult.GetValue("appid"));
            jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp());
            jsApiParam.SetValue("nonceStr", unifiedOrderResult.GetValue("nonce_str"));
            //jsApiParam.SetValue("nonceStr2", WxPayApi.GenerateNonceStr());
            jsApiParam.SetValue("package", "prepay_id=" + unifiedOrderResult.GetValue("prepay_id"));
            jsApiParam.SetValue("signType", "MD5");
            //第三方支付需要查询KEY的值
            string key   = string.Empty;
            string appid = unifiedOrderResult.GetValue("appid").ToString();

            //PayCenterSetting setting = new PayCenterSettingBLL().GetPayCenterSetting(appid);
            if (setting != null && setting.Id > 0)
            {
                key = setting.Key;
            }
            jsApiParam.SetValue("paySign", jsApiParam.MakeSign(key));
            //jsApiParam.SetValue("openid", openid);
            return(jsApiParam.ToJson());
        }
Example #2
0
        /// <summary>
        /// 抛弃使用(用GetUnifiedOrderResult)
        /// </summary>
        /// <param name="setting"></param>
        /// <param name="morder"></param>
        /// <param name="notify_url"></param>
        /// <returns></returns>
        public WxPayData GetUnifiedOrderResultByCity(PayCenterSetting setting, CityMorders morder, string notify_url)
        {
            //统一下单
            string out_trade_no = morder.orderno;//商户订单号

            if (string.IsNullOrEmpty(morder.orderno))
            {
                throw new WxPayException("UnifiedOrder response error!");
            }
            string body = string.Empty;

            if (!string.IsNullOrEmpty(morder.ShowNote))
            {
                body = morder.ShowNote;
            }
            else
            {
                string paytype = string.Empty;
                switch (morder.OrderType)
                {
                case (int)ArticleTypeEnum.MiniappGoods:
                    paytype = "小程序电商模板订单";
                    break;

                case (int)ArticleTypeEnum.MiniappFoodGoods:
                    paytype = "小程序餐饮模板订单";
                    break;

                case (int)ArticleTypeEnum.MiniappSaveMoneySet:
                    paytype = "小程序餐饮储值";
                    break;

                case (int)ArticleTypeEnum.MiniappBargain:
                    paytype = "小程序砍价";
                    break;

                case (int)ArticleTypeEnum.MiniappEnt:
                    paytype = "小程序专业版";
                    break;

                case (int)ArticleTypeEnum.MiniappWXDirectPay:
                    paytype = "小程序直接微信转账";
                    break;

                case (int)ArticleTypeEnum.PlatChildOrderPay:
                    paytype = "平台子模版支付";
                    break;

                case (int)ArticleTypeEnum.PlatChildOrderInPlatPay:
                    paytype = "子模版订单平台支付";
                    break;
                }
                body = string.Format("支付中心,{0}支付{1}元", paytype, (morder.payment_free * 0.01));                                           //商品描述;
            }
            string attach = string.Format("paytype={0}&orderid={1}&orderno={2}&from=city", morder.OrderType, morder.Id, morder.orderno); //自带的信息
            //统一下单
            WxPayData data = new WxPayData();

            data.SetValue("body", body);
            data.SetValue("attach", attach);
            data.SetValue("out_trade_no", out_trade_no);
            data.SetValue("total_fee", total_fee);
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            data.SetValue("goods_tag", "test");
            data.SetValue("trade_type", "JSAPI");
            data.SetValue("openid", openid);
            data.SetValue("notify_url", notify_url);
            WxPayData result = WxPayApi.UnifiedOrder(data, setting);

            if (result != null && (!result.IsSet("appid") || !result.IsSet("prepay_id") || !result.IsSet("prepay_id")))
            {
                throw new WxPayException(result.ToJson());
            }
            unifiedOrderResult = result;
            return(result);
        }
Example #3
0
        public override void ProcessNotify()
        {
            try
            {
                WxPayData notifyData = GetNotifyData();
                //检查支付结果中transaction_id是否存在
                if (!notifyData.IsSet("transaction_id") || !notifyData.IsSet("appid"))
                {
                    //若transaction_id不存在,则立即返回结果给微信支付后台
                    WxPayData res = new WxPayData();
                    res.SetValue("return_code", "FAIL");
                    res.SetValue("return_msg", "支付结果中微信订单号不存在");
                    log4net.LogHelper.WriteError(GetType(), new Exception("transaction_id不存在 : " + res.ToXml()));
                    context.Response.Write(res.ToXml());
                    context.Response.End();
                    return;
                }
                string transactionId = notifyData.GetValue("transaction_id").ToString();
                //别删该日志
                log4net.LogHelper.WriteInfo(this.GetType(), $"微信支付回调返回:{transactionId}");
                string           appid   = notifyData.GetValue("appid").ToString();
                PayCenterSetting setting = PayCenterSettingBLL.SingleModel.GetPayCenterSetting(appid);
                //增加重复回调判断
                int re = RedisUtil.Get <int>(string.Format(MemCacheKey.ProcessNotify, transactionId));
                if (re != 0)
                {
                    return;
                }
                RedisUtil.Set(string.Format(MemCacheKey.ProcessNotify, transactionId), 1, TimeSpan.FromMinutes(30));
                //查询订单,判断订单真实性
                if (!QueryOrder(transactionId, setting))
                {
                    //若订单查询失败,则立即返回结果给微信支付后台
                    WxPayData res = new WxPayData();
                    res.SetValue("return_code", "FAIL");
                    res.SetValue("return_msg", "订单查询失败");
                    log4net.LogHelper.WriteError(GetType(), new Exception("订单查询失败: " + notifyData.ToJson()));
                    context.Response.Write(res.ToXml());
                    context.Response.End();
                }
                //查询订单成功
                else
                {
                    //说付款成功:插入记录
                    //这里要注意,微信通知过来之后,15秒之内没有给微信回复处理状态,微信还会第二次,第三次通知。
                    //带过来的信息一模一样,所以这要做标志判断,万一处理过程出现问题没有给微信回复。
                    //在以后多次请求的时候避免多次进行业务处理,插入多条记录
                    PayResult result = notifyData.ToPayResult();

                    if (result == null)
                    {
                        return;
                    }

                    int id = Convert.ToInt32(PayResultBLL.SingleModel.Add(result));//插入记录,论坛,直播、有约
                    result.Id = id;
                    NotifyOper(result);
                }
            }
            catch (Exception ex)
            {
                log4net.LogHelper.WriteError(typeof(ResultNotify), ex);
            }
            finally
            {
                //最后要给微信放回接收成功数据,不然微信会连续多次发送同样请求
                WxPayData res = new WxPayData();
                res.SetValue("return_code", "SUCCESS");
                res.SetValue("return_msg", "OK");
                context.Response.Write(res.ToXml());
                context.Response.End();
            }
        }