示例#1
0
文件: JsApiPay.cs 项目: soon14/vzan
        /**
         *
         * 从统一下单成功返回的数据中获取微信浏览器调起jsapi支付所需的参数,
         * 微信浏览器调起JSAPI时的输入参数格式如下:
         * {
         *   "appId" : "wx2421b1c4370ec43b",     //公众号名称,由商户传入
         *   "timeStamp":" 1395712654",         //时间戳,自1970年以来的秒数
         *   "nonceStr" : "e61463f8efa94090b1f366cccfbbb444", //随机串
         *   "package" : "prepay_id=u802345jgfjsdfgsdg888",
         *   "signType" : "MD5",         //微信签名方式:
         *   "paySign" : "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名
         * }
         * @return string 微信浏览器调起JSAPI时的输入参数,json格式可以直接做参数用
         * 更详细的说明请参考网页端调起支付API:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7
         *
         */
        //public string GetJsApiParameters()
        //{
        //    WxPayData jsApiParam = new WxPayData();
        //    jsApiParam.SetValue("appId", unifiedOrderResult.GetValue("appid"));
        //    jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp());
        //    jsApiParam.SetValue("nonceStr", 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));
        //    return jsApiParam.ToJson();

        //}

        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());
        }
示例#2
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();
                string           appid         = notifyData.GetValue("appid").ToString();
                PayCenterSetting setting       = new PayCenterSettingBLL().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();

                    //log4net.LogHelper.WriteInfo(this.GetType(), Newtonsoft.Json.JsonConvert.SerializeObject(result));
                    if (result == null)
                    {
                        return;
                    }
                    if ((WxUtils.getAttachValue(result.attach, "from") == "shop"))//商城支付
                    {
                    }
                    else
                    {
                        int id = Convert.ToInt32(new PayResultBLL().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();
            }
        }
示例#3
0
        /// <summary>
        /// 测速上报
        /// </summary>
        /// <param name="interface_url">接口URL</param>
        /// <param name="timeCost">接口耗时</param>
        /// <param name="inputObj">inputObj参数数组</param>
        private static void ReportCostTime(string interface_url, int timeCost, WxPayData inputObj, PayCenterSetting setting)
        {
            //如果不需要进行上报
            if (WxPayConfig.REPORT_LEVENL == 0)
            {
                return;
            }

            //如果仅失败上报
            if (WxPayConfig.REPORT_LEVENL == 1 && inputObj.IsSet("return_code") && inputObj.GetValue("return_code").ToString() == "SUCCESS" &&
                inputObj.IsSet("result_code") && inputObj.GetValue("result_code").ToString() == "SUCCESS")
            {
                return;
            }

            //上报逻辑
            WxPayData data = new WxPayData();

            data.SetValue("interface_url", interface_url);
            data.SetValue("execute_time_", timeCost);
            //返回状态码
            if (inputObj.IsSet("return_code"))
            {
                data.SetValue("return_code", inputObj.GetValue("return_code"));
            }
            //返回信息
            if (inputObj.IsSet("return_msg"))
            {
                data.SetValue("return_msg", inputObj.GetValue("return_msg"));
            }
            //业务结果
            if (inputObj.IsSet("result_code"))
            {
                data.SetValue("result_code", inputObj.GetValue("result_code"));
            }
            //错误代码
            if (inputObj.IsSet("err_code"))
            {
                data.SetValue("err_code", inputObj.GetValue("err_code"));
            }
            //错误代码描述
            if (inputObj.IsSet("err_code_des"))
            {
                data.SetValue("err_code_des", inputObj.GetValue("err_code_des"));
            }
            //商户订单号
            if (inputObj.IsSet("out_trade_no"))
            {
                data.SetValue("out_trade_no", inputObj.GetValue("out_trade_no"));
            }
            //设备号
            if (inputObj.IsSet("device_info"))
            {
                data.SetValue("device_info", inputObj.GetValue("device_info"));
            }

            try
            {
                Report(data, setting);
            }
            catch (WxPayException)
            {
                //不做任何处理
            }
        }
示例#4
0
        /// <summary>
        /// 统一下单
        /// </summary>
        /// <param name="inputObj">提交给统一下单API的参数</param>
        /// <param name="timeOut">超时时间</param>
        /// <returns></returns>
        public static WxPayData UnifiedOrder(WxPayData inputObj, PayCenterSetting setting, int timeOut = 60, bool livePay = false)
        {
            string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            //检测必填参数
            if (!inputObj.IsSet("out_trade_no"))
            {
                throw new WxPayException("缺少统一支付接口必填参数out_trade_no!");
            }
            else if (!inputObj.IsSet("body"))
            {
                throw new WxPayException("缺少统一支付接口必填参数body!");
            }
            else if (!inputObj.IsSet("total_fee"))
            {
                throw new WxPayException("缺少统一支付接口必填参数total_fee!");
            }
            else if (!inputObj.IsSet("trade_type"))
            {
                throw new WxPayException("缺少统一支付接口必填参数trade_type!");
            }

            //关联参数
            if (inputObj.GetValue("trade_type").ToString() == "JSAPI" && !inputObj.IsSet("openid"))
            {
                throw new WxPayException("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
            }
            if (inputObj.GetValue("trade_type").ToString() == "NATIVE" && !inputObj.IsSet("product_id"))
            {
                throw new WxPayException("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
            }
            //异步通知url未设置,则使用配置文件中的url
            if (!inputObj.IsSet("notify_url") || string.IsNullOrEmpty(inputObj.GetValue("notify_url").ToString()))
            {
                inputObj.SetValue("notify_url", WxPayConfig.NOTIFY_URL);//异步通知url
            }
            if (livePay)
            {
                inputObj.SetValue("notify_url", inputObj.GetValue("notify_url").ToString().Replace("/pay/", "/live/"));//异步通知url,直播要跳到直播回调
            }
            string appid  = WxPayConfig.APPID;
            string mch_id = WxPayConfig.MCHID;
            string key    = string.Empty;

            if (setting != null && setting.Id > 0)
            {
                appid  = setting.Appid;
                mch_id = setting.Mch_id;
                key    = setting.Key;
            }
            inputObj.SetValue("appid", appid);                     //公众账号ID
            inputObj.SetValue("mch_id", mch_id);                   //商户号
            inputObj.SetValue("spbill_create_ip", WxPayConfig.IP); //终端ip
            inputObj.SetValue("nonce_str", GenerateNonceStr());    //随机字符串


            //签名
            inputObj.SetValue("sign", inputObj.MakeSign(key));
            //log4net.LogHelper.WriteInfo(typeof(wxuserinfo),inputObj.ToJson());
            string xml      = inputObj.ToXml();
            string response = WxHelper.Post(xml, url, false, setting, timeOut);
            //log4net.LogHelper.WriteInfo(typeof(WxPayApi), "UnifiedOrder().response=" + response);

            WxPayData result = new WxPayData();

            result.FromXml(response);
#if DEBUG
            log4net.LogHelper.WriteInfo(typeof(WxPayApi), "UnifiedOrder().response=" + response);
#endif
            return(result);
        }
示例#5
0
文件: JsApiPay.cs 项目: soon14/vzan
        /**
         *
         * 网页授权获取用户基本信息的全部过程
         * 详情请参看网页授权获取用户基本信息:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
         * 第一步:利用url跳转获取code
         * 第二步:利用code去获取openid和access_token
         *
         */
        //public void GetOpenidAndAccessToken()
        //{
        //    if (!string.IsNullOrEmpty(context.Request.QueryString["code"]))
        //    {
        //        //获取code码,以获取openid和access_token
        //        string code = context.Request.QueryString["code"];
        //        log4net.LogHelper.WriteInfo(this.GetType(), "Get code : " + code);
        //        GetOpenidAndAccessTokenFromCode(code);
        //    }
        //    else
        //    {
        //        //构造网页授权获取code的URL
        //        string host = context.Request.Url.Host;
        //        string path = context.Request.Path;
        //        string redirect_uri = HttpUtility.UrlEncode("http://" + host + path);
        //        WxPayData data = new WxPayData();
        //        data.SetValue("appid", WxPayConfig.APPID);
        //        data.SetValue("redirect_uri", redirect_uri);
        //        data.SetValue("response_type", "code");
        //        data.SetValue("scope", "snsapi_base");
        //        data.SetValue("state", "STATE" + "#wechat_redirect");
        //        string url = "https://open.weixin.qq.com/connect/oauth2/authorize?" + data.ToUrl();
        //        log4net.LogHelper.WriteInfo(this.GetType(), "Will Redirect to URL : " + url);
        //        try
        //        {
        //            //触发微信返回code码
        //            context.Response.Redirect(url);//Redirect函数会抛出ThreadAbortException异常,不用处理这个异常
        //        }
        //        catch (System.Threading.ThreadAbortException )
        //        {
        //        }
        //    }
        //}


        /**
         *
         * 通过code换取网页授权access_token和openid的返回数据,正确时返回的JSON数据包如下:
         * {
         *  "access_token":"ACCESS_TOKEN",
         *  "expires_in":7200,
         *  "refresh_token":"REFRESH_TOKEN",
         *  "openid":"OPENID",
         *  "scope":"SCOPE",
         *  "unionid": "o6_bmasdasdsad6_2sgVt7hMZOPfL"
         * }
         * 其中access_token可用于获取共享收货地址
         * openid是微信支付jsapi支付接口统一下单时必须的参数
         * 更详细的说明请参考网页授权获取用户基本信息:http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
         * @失败时抛异常WxPayException
         */
        //public void GetOpenidAndAccessTokenFromCode(string code)
        //{
        //    try
        //    {
        //        //构造获取openid及access_token的url
        //        WxPayData data = new WxPayData();
        //        data.SetValue("appid", WxPayConfig.APPID);
        //        data.SetValue("secret", WxPayConfig.APPSECRET);
        //        data.SetValue("code", code);
        //        data.SetValue("grant_type", "authorization_code");
        //        string url = "https://api.weixin.qq.com/sns/oauth2/access_token?" + data.ToUrl();

        //        //请求url以获取数据
        //        string result = WxHelper.HttpGet(url);

        //        //保存access_token,用于收货地址获取
        //        WxAuthorize jd = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<WxAuthorize>(result);
        //        access_token = jd.access_token;

        //        //获取用户openid
        //        openid = jd.openid;
        //    }
        //    catch (Exception ex)
        //    {
        //        log4net.LogHelper.WriteError(this.GetType(), ex);
        //        throw ex;
        //    }
        //}

        ///// <summary>
        ///// 文章打赏
        ///// </summary>
        ///// <param name="article">文章实体</param>
        ///// <returns></returns>
        //public WxPayData GetUnifiedOrderResult(PayCenterSetting setting,Article article, int luserid, out int orderid, int artcommentid = 0)
        //{
        //    OAuthUserBll bll = new OAuthUserBll(article.MinisnsId.ToString());
        //    OAuthUser looker = bll.GetUserByCache(luserid);
        //    OAuthUser maker = bll.GetUserByCache(article.UserId);

        //    //统一下单
        //    string out_trade_no = WxPayApi.GenerateOutTradeNo();//商户订单号
        //    string body = "赞赏" + (maker == null ? "匿名用户" : Utility.ReplaceSpecialChar(maker.Nickname, '?'));//商品描述
        //    if (article.IsGuerdon == (int)ArticleTypeEnum.Donation)
        //    {
        //        body = "支持" + (maker == null ? "匿名用户" : Utility.ReplaceSpecialChar(maker.Nickname, '?'));//商品描述
        //    }
        //    string attach = "paytype=1&minisnsid=" + article.MinisnsId + "&articleid=" + article.Id + "&userid=" + article.UserId + "&luserId=" + looker.Id;//自带的信息
        //    if (article.IsGuerdon == (int)ArticleTypeEnum.Donation && artcommentid != 0)
        //    {
        //        attach += "&articlecommentid=" + artcommentid;
        //    }
        //    //统一下单
        //    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);

        //    WxPayData result = WxPayApi.UnifiedOrder(data, setting);

        //    if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
        //    {
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("data:" + data.ToJson()));
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("result:" + result.ToJson()));
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("统一下单请求失败!prepay_id:" + result.GetValue("prepay_id").ToString()));
        //        throw new WxPayException("UnifiedOrder response error!");
        //    }
        //    //插入打赏记录
        //    if (maker == null)
        //    {
        //        //作者为空,不能打赏
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("文章作者为空!"));
        //        throw new WxPayException("文章作者为空!");
        //    }
        //    if (looker == null)
        //    {
        //        //打赏者为空,新增用户信息(在前面获取用户信息已经跳转注册过)
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("获取用户信息失败!"));
        //        throw new WxPayException("获取用户信息失败!");
        //    }
        //    RewardOrder order = new RewardOrder();
        //    order.userip = Utility.Web.WebHelper.GetIP();
        //    order.addTime = DateTime.Now;
        //    order.articleId = article.Id;
        //    order.minisnsId = article.MinisnsId;
        //    order.rewardFromUserId = looker.Id;
        //    order.rewardMoney = total_fee;
        //    order.rewardToUserId = maker.Id;
        //    order.out_trade_no = out_trade_no;
        //    order.status = 0;
        //    order.percent = ((100 - WebConfigBLL.VzanRewardPercent) - new MinisnsBll().GetModel(article.MinisnsId).RewardPercent);
        //    //众筹
        //    if (article.IsGuerdon == (int)ArticleTypeEnum.Donation)
        //    {
        //        order.percent = 100 - WebConfigBLL.DonationPercent;
        //        order.rewardtype = 3;
        //    }
        //    //新增区分文章和回复类型
        //    order.rewardtype = 0;
        //    RewardOrderBLL bllorder = new RewardOrderBLL();
        //    try
        //    {
        //        orderid = Convert.ToInt32(bllorder.Add(order));
        //        if (orderid <= 0)
        //        {
        //            throw new WxPayException("打赏新增订单失败!");
        //        }
        //    }
        //    catch (Exception ex)
        //    {
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("插入RewardOrder失败!" + ex.Message));
        //        throw;
        //    }
        //    unifiedOrderResult = result;
        //    return result;
        //}

        ///// <summary>
        ///// 文章悬赏
        ///// </summary>
        ///// <param name="article">文章实体</param>
        ///// <returns></returns>
        //public WxPayData GetUnifiedOrderResult(PayCenterSetting setting,Article article)
        //{
        //    OAuthUserBll bll = new OAuthUserBll(article.MinisnsId.ToString());
        //    OAuthUser maker = bll.GetUserByCache(article.UserId);
        //    //ArticleType articleType = new ArticleTypeBll().GetModel(article.ArticleTypeId);
        //    //统一下单
        //    string out_trade_no = WxPayApi.GenerateOutTradeNo();//商户订单号
        //    string body = string.Empty;
        //    int paytype = 0;
        //    if (article.GuerdonMoney > 0)
        //    {
        //        body += string.Format("悬赏贴:{0}元", article.GuerdonMoney * 0.01);//商品描述
        //        paytype = 2;
        //    }
        //    if (article.payment_free > 0)
        //    {
        //        if (article.IsGuerdon == (int)ArticleTypeEnum.Pay)
        //        {
        //            body += string.Format("付费贴:{0}元", article.payment_free * 0.01);//商品描述
        //            paytype = 3;
        //        }
        //        if (article.IsGuerdon == (int)ArticleTypeEnum.Stick)
        //        {
        //            body += string.Format("置顶贴:{0}元", article.payment_free * 0.01);//商品描述
        //            paytype = 4;
        //        }
        //    }

        //    string attach = string.Empty;
        //    attach = "paytype=" + paytype + "&minisnsid=" + article.MinisnsId + "&articleid=" + article.Id + "&userid=" + article.UserId;//自带的信息

        //    //统一下单
        //    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);

        //    WxPayData result = WxPayApi.UnifiedOrder(data, setting);

        //    if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
        //    {
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("文章付款ID:" + article.Id + ",data:" + data.ToJson()));
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("result:" + result.ToJson()));
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("统一下单请求失败!prepay_id:" + result.GetValue("prepay_id").ToString()));
        //        throw new WxPayException("UnifiedOrder response error!");
        //    }
        //    //插入打赏记录
        //    if (maker == null)
        //    {
        //        //作者为空,不能打赏
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("文章作者为空!"));
        //        throw new WxPayException("文章作者为空!");
        //    }
        //    if (article.IsGuerdon == 1)
        //    {
        //        GuerdonOrder order = new GuerdonOrder();
        //        order.Addtime = DateTime.Now;
        //        order.Articleid = article.Id;
        //        order.MinisnsId = article.MinisnsId;
        //        order.GuerdonFromUserId = maker.Id;
        //        order.GuerdonMoney = article.GuerdonMoney;
        //        order.OutTradeNo = out_trade_no;
        //        order.Status = 0;
        //        order.Percent = ((100 - WebConfigBLL.VzanRewardPercent) - new MinisnsBll().GetModel(article.MinisnsId).RewardPercent);
        //        //新增区分文章和回复类型
        //        order.OperStatus = 0;
        //        GuerdonOrderBLL bllorder = new GuerdonOrderBLL();
        //        bllorder.Add(order);
        //    }
        //    unifiedOrderResult = result;
        //    return result;
        //}
        ///// <summary>
        ///// 回复打赏
        ///// </summary>
        ///// <param name="article">回复实体</param>
        ///// <returns></returns>
        //public WxPayData GetUnifiedOrderResult(PayCenterSetting setting, ArticleComment comment, OAuthUser looker, out int orderid)
        //{

        //    OAuthUserBll bll = new OAuthUserBll(comment.MinisnsId.ToString());
        //    OAuthUser maker = bll.GetUserByCache(comment.UserId);
        //    //统一下单
        //    string out_trade_no = WxPayApi.GenerateOutTradeNo();//商户订单号
        //    string body = "打赏" + (maker == null ? "匿名用户" : Utility.ReplaceSpecialChar(maker.Nickname, '?'));//商品描述
        //    string attach = "paytype=1&minisnsid=" + comment.MinisnsId + "&commentid=" + comment.Id + "&userid=" + comment.UserId + "&luserId=" + looker.Id;//自带的信息

        //    //统一下单
        //    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);
        //    WxPayData result = WxPayApi.UnifiedOrder(data, setting);
        //    if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
        //    {
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("文章回复实体ID" + comment.Id + ",data:" + data.ToJson()));
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("result:" + result.ToJson()));
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("统一下单请求失败!prepay_id:" + result.GetValue("prepay_id").ToString()));
        //        throw new WxPayException("UnifiedOrder response error!");
        //    }
        //    //插入打赏记录
        //    if (maker == null)
        //    {
        //        //作者为空,不能打赏
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("文章作者为空!"));
        //        throw new WxPayException("文章作者为空!");
        //    }
        //    if (looker == null)
        //    {
        //        //打赏者为空,新增用户信息(在前面获取用户信息已经跳转注册过)
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("获取用户信息失败!"));
        //        throw new WxPayException("获取用户信息失败!");
        //    }
        //    RewardOrder order = new RewardOrder();
        //    order.userip = Utility.Web.WebHelper.GetIP();
        //    order.addTime = DateTime.Now;
        //    order.articleId = comment.ArticleId;
        //    order.minisnsId = comment.MinisnsId;
        //    order.rewardFromUserId = looker.Id;
        //    order.rewardMoney = total_fee;
        //    order.rewardToUserId = maker.Id;
        //    order.out_trade_no = out_trade_no;
        //    order.status = 0;
        //    order.percent = ((100 - WebConfigBLL.VzanRewardPercent) - new MinisnsBll().GetModel(comment.MinisnsId).RewardPercent);
        //    //新增区分文章和回复类型
        //    order.rewardtype = 1;
        //    order.commentId = comment.Id;//如果是回复打赏,commentId为空
        //    RewardOrderBLL bllorder = new RewardOrderBLL();
        //    try
        //    {
        //        orderid = Convert.ToInt32(bllorder.Add(order));
        //    }
        //    catch (Exception ex)
        //    {
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("插入RewardOrder失败!" + ex.Message));
        //        throw;
        //    }
        //    //orderid = bllorder.GetModel(string.Format("out_trade_no='{0}'", order.out_trade_no)).Id;
        //    unifiedOrderResult = result;
        //    return result;
        //}

        ///// <summary>
        ///// 支付中心
        ///// </summary>
        ///// <param name="article">Morders订单实体</param>
        ///// <returns></returns>
        //public WxPayData GetUnifiedOrderResult(PayCenterSetting setting, Morders morder, bool livePay = false)
        //{
        //    //统一下单
        //    string out_trade_no = morder.orderno;//商户订单号
        //    if (string.IsNullOrEmpty(morder.orderno))
        //    {
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("统一下单失败,订单的内部订单号为空!:OrderID:" + morder.Id));
        //        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.Offer:
        //                paytype = "悬赏贴";
        //                break;
        //            case (int)ArticleTypeEnum.Pay:
        //                paytype = "付费贴";
        //                break;
        //            case (int)ArticleTypeEnum.Stick:
        //                paytype = "置顶帖";
        //                break;
        //            case (int)ArticleTypeEnum.VoiceRedPacket:
        //                paytype = "语音红包";
        //                break;
        //            case (int)ArticleTypeEnum.Advert:
        //                paytype = "广告";
        //                break;
        //            case (int)ArticleTypeEnum.VoiceRedPacketRecharge:
        //                paytype = "红包充值";
        //                break;
        //            case (int)ArticleTypeEnum.LiveReward:
        //                paytype = "直播间打赏";
        //                break;
        //            case (int)ArticleTypeEnum.CashWishes:
        //                paytype = "送彩礼";
        //                break;
        //            case (int)ArticleTypeEnum.CityArticleTop:
        //            case (int)ArticleTypeEnum.CityBannerShow:
        //            case (int)ArticleTypeEnum.CityStoreTop:
        //                paytype = "同城推广";
        //                break;
        //        }
        //        body = string.Format("支付中心,{0}支付{1}元", paytype, (morder.payment_free * 0.01));//商品描述;
        //    }
        //    string attach = string.Format("paytype={0}&orderid={1}&orderno={2}&from=center", 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);

        //    WxPayData result = WxPayApi.UnifiedOrder(data, setting,60,livePay);

        //    if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
        //    {
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("data:" + data.ToJson()));
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("result:" + result.ToJson()));
        //        log4net.LogHelper.WriteError(this.GetType(), new WxPayException("统一下单请求失败!prepay_id:" + result.GetValue("prepay_id").ToString()));
        //        throw new WxPayException("UnifiedOrder response error!");
        //    }
        //    unifiedOrderResult = result;
        //    return result;
        //}
        public WxPayData GetUnifiedOrderResultByCity(PayCenterSetting setting, CityMorders morder, string notify_url)
        {
            //统一下单
            string out_trade_no = morder.orderno;//商户订单号

            if (string.IsNullOrEmpty(morder.orderno))
            {
                //log4net.LogHelper.WriteError(this.GetType(), new WxPayException("统一下单失败,订单的内部订单号为空!:OrderID:" + morder.Id));
                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;
                }
                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", WebConfigBLL.citynotify_url);
            //data.SetValue("notify_url", WebConfigBLL.citynotify_url);
            data.SetValue("notify_url", notify_url);
            //log4net.LogHelper.WriteInfo(GetType(),"支付回调链接:"+ WebConfigBLL.citynotify_url);
            WxPayData result = WxPayApi.UnifiedOrder(data, setting);

            if (result != null && (!result.IsSet("appid") || !result.IsSet("prepay_id") || !result.IsSet("prepay_id")))
            {
                //log4net.LogHelper.WriteError(this.GetType(), new WxPayException("data:" + data.ToJson()));
                //log4net.LogHelper.WriteError(this.GetType(), new WxPayException("result:" + result.ToJson()));
                //log4net.LogHelper.WriteError(this.GetType(), new WxPayException("统一下单请求失败!prepay_id:" + result.GetValue("prepay_id").ToString()));
                throw new WxPayException("UnifiedOrder response error!" + "result:" + result.ToJson());
            }
            unifiedOrderResult = result;
            return(result);
        }