/// <summary> /// 扫码支付模式二生成二维码 /// </summary> /// <param name="id">商品id</param> public void NativePayTwo(string id) { //商户根据productid【在生成二维码时传的是订单号就是订单号,是商品号就是商品号,要对应起来】生成商户系统的订单 //:TODO //统一下单 SortedDictionary <string, object> orderParams = new SortedDictionary <string, object>(); orderParams.Add("appid", ApiModel.AppID); orderParams.Add("attach", "微信扫码支付"); //附加数据 orderParams.Add("body", "扫码支付二测试"); //商品描述 orderParams.Add("mch_id", ApiModel.MchID); orderParams.Add("nonce_str", Common.GetNonceStr()); orderParams.Add("notify_url", "http://www.liblog.cn/test/pay/payresultnotify"); //支付成功后的回调URl orderParams.Add("product_id", id); //商品标记 orderParams.Add("out_trade_no", Pay.GetOutTradeNo(ApiModel.MchID)); //随机字符串 orderParams.Add("spbill_create_ip", "171.8.215.143"); orderParams.Add("total_fee", 1); //总金额 orderParams.Add("trade_type", "NATIVE"); //商品订单号 orderParams.Add("sign", Pay.GetSign(orderParams, ApiModel.MchAPISecret)); //直接支付URL var url = Pay.GetPayUrlForNativeTwo(orderParams); //初始化二维码生成工具 QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(); qrCodeEncoder.QRCodeEncodeMode = QRCodeEncoder.ENCODE_MODE.BYTE; qrCodeEncoder.QRCodeErrorCorrect = QRCodeEncoder.ERROR_CORRECTION.M; qrCodeEncoder.QRCodeVersion = 0; qrCodeEncoder.QRCodeScale = 4; //将字符串生成二维码图片 Bitmap image = qrCodeEncoder.Encode(url, Encoding.Default); //保存为PNG到内存流 MemoryStream ms = new MemoryStream(); image.Save(ms, ImageFormat.Png); //输出二维码图片 Response.BinaryWrite(ms.GetBuffer()); Response.End(); }