示例#1
0
        /// <summary>
        /// 生成直接支付url,支付url有效期为2小时,模式二
        /// </summary>
        /// <param name="productId">商品ID</param>
        /// <returns>模式二URL</returns>
        public static string GetPayUrl(string productId)
        {
            WxPayData data = new WxPayData();

            data.SetValue("body", "test");                                                        //商品描述
            data.SetValue("attach", "test");                                                      //附加数据
            data.SetValue("out_trade_no", CommonHelper.CreateOutTradeNo());                       //随机字符串
            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", "jjj");                                                    //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", productId);                                               //商品ID
            WxPayData result = WxPayAPI2.UnifiedOrder(data);                                      //调用统一下单接口
            string    url    = result.GetValue("code_url").ToString();                            //获得统一下单接口返回的二维码链接

            return(url);
        }
示例#2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="openId"></param>
        /// <param name="productId"></param>
        /// <returns></returns>
        private WxPayData UnifiedOrder(string openId, string productId)
        {
            //统一下单
            WxPayData req = new WxPayData();

            req.SetValue("body", "test");
            req.SetValue("attach", "test");
            req.SetValue("out_trade_no", CommonHelper.CreateOutTradeNo());
            req.SetValue("total_fee", 1);
            req.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));
            req.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss"));
            req.SetValue("goods_tag", "test");
            req.SetValue("trade_type", "NATIVE");
            req.SetValue("openid", openId);
            req.SetValue("product_id", productId);
            WxPayData result = WxPayAPI2.UnifiedOrder(req);

            return(result);
        }
        /// <summary>
        /// 调用统一下单,获得下单结果
        /// </summary>
        /// <returns>统一下单结果</returns>
        public WxPayData GetUnifiedOrderResult()
        {
            //统一下单
            WxPayData data = new WxPayData();

            data.SetValue("body", "test");
            data.SetValue("attach", "test");
            data.SetValue("out_trade_no", CommonHelper.CreateOutTradeNo());
            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 = WxPayAPI2.UnifiedOrder(data);

            if (!result.IsSet("appid") || !result.IsSet("prepay_id") || result.GetValue("prepay_id").ToString() == "")
            {
                throw new WxPayException("UnifiedOrder response error!");
            }
            unifiedOrderResult = result;
            return(result);
        }