示例#1
0
        public ParamsData UnifiedOrder()
        {
            if (String.IsNullOrEmpty(notify_url))
            {
                notify_url = Config.NOTIFY_URL;
            }

            //统一下单
            var req = new ParamsData();

            req.SetValue("body", "E717平台订单");
            req.SetValue("attach", "");
            req.SetValue("out_trade_no", product_id);
            req.SetValue("total_fee", total_fee);
            if (!String.IsNullOrEmpty(time_expire))
            {
                req.SetValue("time_expire", time_expire);
            }
            else if (expire_minutes > 5)
            {
                req.SetValue("time_expire", DateTime.Now.AddMinutes(expire_minutes).ToString("yyyyMMddHHmmss"));
            }
            req.SetValue("goods_tag", "");
            req.SetValue("trade_type", "NATIVE");
            req.SetValue("openid", openId);
            req.SetValue("product_id", product_id);
            req.SetValue("notify_url", notify_url);

            return(PayApi.UnifiedOrder(req));
        }
示例#2
0
        /**
         * 调用统一下单,获得下单结果
         * @return 统一下单结果
         * @失败时抛异常WxPayException
         */
        public ParamsData GetUnifiedOrderResult()
        {
            if (String.IsNullOrEmpty(notify_url))
            {
                notify_url = Config.NOTIFY_URL;
            }

            //统一下单
            var data = new ParamsData();

            data.SetValue("device_info", "WEB");
            data.SetValue("body", "文化广场会员订单");
            data.SetValue("attach", "");                 //附加数据,在查询API和支付通知中原样返回,可作为自定义参数使用。
            data.SetValue("out_trade_no", out_trade_no); //商户系统内部订单号,要求32个字符内、且在同一个商户号下唯一。
            data.SetValue("total_fee", total_fee);       //订单总金额,单位为分
            if (!String.IsNullOrEmpty(time_expire))
            {
                data.SetValue("time_expire", time_expire);
            }
            else if (expire_minutes > 5)
            {
                data.SetValue("time_expire", DateTime.Now.AddMinutes(expire_minutes).ToString("yyyyMMddHHmmss"));
            }
            data.SetValue("trade_type", trade_type.ToString());
            data.SetValue("openid", openid);
            data.SetValue("product_id", product_id == null ? "" : product_id);
            data.SetValue("notify_url", notify_url);

            var result = PayApi.UnifiedOrder(data);

            if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
            {
                Log.Error(this.GetType().ToString(), "UnifiedOrder response error!");
                throw new Exception("UnifiedOrder response error!");
            }

            unifiedOrderResult = result;
            return(result);
        }
示例#3
0
        /**
         * 生成直接支付url,支付url有效期为2小时,模式二
         * @param productId 商品ID
         * @return 模式二URL
         */
        public string GetPayUrl(string out_trade_no)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");

            var data = new ParamsData();

            data.SetValue("body", "E717平台订单");                                                    //商品描述
            data.SetValue("attach", "");                                                          //附加数据
            data.SetValue("out_trade_no", out_trade_no);                                          //随机字符串
            data.SetValue("total_fee", 1);                                                        //总金额
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));                 //交易起始时间
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间
            data.SetValue("goods_tag", "");                                                       //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", out_trade_no);                                            //商品ID

            var    result = PayApi.UnifiedOrder(data);                                            //调用统一下单接口
            string url    = result.GetValue("code_url").ToString();                               //获得统一下单接口返回的二维码链接

            Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }