Exemplo n.º 1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public static JResult GetNativePayQrCode(NativePayData data)
        {
            var nativePay = new NativePay();

            //var data = new NativePayData
            //{
            //    Body = "快拍立信拍车定金",//商品描述
            //    Attach = "testAttach",//附加数据
            //    TotalFee = 1,//总金额
            //    ProductId = "prodid",//商品ID
            //    OutTradeNo = WxPayApi.GenerateOutTradeNo(),//订单编号
            //    GoodsTag = "testgood"
            //};

            var result = nativePay.GetPayUrl(data);

            if (result.errcode != 0)
            {
                return result;
            }

            //生成二维码
            var bitmap = BarCodeUtility.CreateBarcode(result.errmsg.ToString(), 240, 240);

            var ran = new Random();
            var key = string.Concat("wxpay", DateTime.Now.ToString("yyyyMMddHHmmss"), ran.Next(999));
            var stream = BarCodeUtility.BitmapToStream(bitmap);
            //上传图片到七牛云
            var qinniu = new QiniuUtility();
            var qrcode = qinniu.Put(stream, "", key);
            return JResult._jResult(0, qrcode);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 生成直接支付url,支付url有效期为2小时,模式二
        /// </summary>
        /// <param name="payData"></param>
        /// <returns></returns>
        public JResult GetPayUrl(NativePayData payData)
        {
            var data = new WxPayData();
            data.SetValue("body", payData.Body);//商品描述
            data.SetValue("attach", payData.Attach);//附加数据
            data.SetValue("out_trade_no", payData.OutTradeNo);//随机字符串
            data.SetValue("total_fee", payData.TotalFee);//总金额
            data.SetValue("time_start", payData.TimeStart);//交易起始时间
            data.SetValue("time_expire", payData.TimeExpire);//交易结束时间
            data.SetValue("goods_tag", payData.GoodsTag);//商品标记
            data.SetValue("trade_type", "NATIVE");//交易类型
            data.SetValue("product_id", payData.ProductId);//商品ID

            var result = WxPayApi.UnifiedOrder(data);//调用统一下单接口
            if (result.IsSet("return_code")
                && result.IsSet("result_code")
                && result.GetValue("return_code").ToString().Equals("SUCCESS")
                && result.GetValue("result_code").ToString().Equals("SUCCESS"))
            {
                //获得统一下单接口返回的二维码链接
                return JResult._jResult(0, result.GetValue("code_url").ToString());
            }

            return JResult._jResult(400, result.ToJson());
        }
Exemplo n.º 3
0
        public void WxPayQrCodeTest()
        {
            NativePayData data = new NativePayData();
            data.Body="ccntest";//商品描述
            data.Attach ="ccntest";//附加数据
            data.TotalFee = 1;//总金额
            data.ProductId="123456789";//商品ID

            NativePay nativePay = new NativePay();
            string url2 = nativePay.GetPayUrl(data);

            var bitmap = BarCodeUtility.CreateBarcode(url2, 240, 240);

            var ran = new Random(Guid.NewGuid().GetHashCode());
            var key = string.Concat("wxpay", DateTime.Now.ToString("yyyyMMddHHmmss"), ran.Next(999));

            var stream = BarCodeUtility.BitmapToStream(bitmap);
            //上传图片到七牛云
            var qinniu = new QiniuUtility();
            var qrcode = qinniu.Put(stream,"", key);
            stream.Dispose();
        }