/// <summary> /// 调用微信统一下单 /// </summary> /// <param name="orderId">订单Id</param> /// <param name="studentId">学生Id</param> /// <param name="voucherIds">本次支付使用的优惠券Id列表</param> /// <param name="ip">用户IP</param> /// <param name="image">支付二维码图片</param> /// <param name="isFreeOrder">是否免费订单,如为0元购返回true</param> /// <returns>统一下单处理结果。</returns> public bool WechatOrderPay(int orderId, int studentId, int[] voucherIds, string ip, ref byte[] image, ref bool isFreeOrder) { decimal amount = 0; string orderNo = ""; int batchId = Service.PreOrderPay(orderId, studentId, voucherIds, CashPayTypeEnum.微信); Service.OrderPay(orderId, studentId, voucherIds, CashPayTypeEnum.微信, batchId, out amount, out orderNo); if (batchId >= 1)//如果之前已经发起过微信支付,需要关闭之前的微信支付订单。如果关闭之前订单失败,本次支付仍然继续执行。 { try { WeChatApi weChatApi = new WeChatApi(); weChatApi.CloseOrder(orderId, GetOutTradeNo(orderNo, batchId)); } catch (Exception ex) { LogHelper.ErrorLog("", ex); } } if (amount > 0 && !string.IsNullOrEmpty(orderNo)) { WechatPreOrderResponse response = new WeChatApi().CreatePreOrder(orderId, "大语文订单", GetOutTradeNo(orderNo, batchId + 1), amount, ip); image = QRCodeUtil.MakeImage(response.CodeUrl); return true; } else if (amount == 0 && !string.IsNullOrEmpty(orderNo))//如果本次不需要微信支付(课程价格是0或者使用的现金券金额>=课程金额) { Service.OrderPayOver(orderNo); isFreeOrder = true; return false; } return false; }
static void Main(string[] args) { DriveAPI drive = new DriveAPI(); var list = drive.files; string path = list[0].WebContentLink; Console.WriteLine(QRCodeUtil.getQRCode(path)); Console.ReadKey(); }
/// <summary> /// 生成二维码保存. /// </summary> /// <param name="account">评委账号.</param> /// <param name="password">密码.</param> /// <param name="name">名字.</param> /// <returns>二维码路径.</returns> public string CreateCodePath(string account, string password, string name) { // 获取当前完整URL string url = Request.Url.ToString(); Uri uri = new Uri(url); // 获取当前主机部分 string host = uri.Host; string uploadPath = Server.MapPath("~/" + "/Source"); string codePath = "http://" + host + "/VotingLogin/CodeLogin?username="******"&password="******"/Source" + QRCodeUtil.QRCode(uploadPath, codePath, name, name)); }
public virtual int GetBitmapValue(uint dwFieldID, out IntPtr phbmp) { Logger.Write($"dwFieldID: {dwFieldID}"); try { //TryLoadUserIcon();remoteUrl phbmp = QRCodeUtil.GenerateMyQCCode(this.remoteUrl).GetHbitmap();//this.view.icon.GetHbitmap();// } catch (Exception ex) { phbmp = IntPtr.Zero; Logger.Write("Error: " + ex); } //phbmp = QRCodeUtil.GenerateMyQCCode("accccssdwddqd").GetHbitmap();//tileIcon?.GetHbitmap() ?? IntPtr.Zero; return(HRESULT.S_OK); }
// <exception cref="ConnectionException"></exception> // <exception cref="IOException"></exception> // <exception cref="NotSupportedException"></exception> // <exception cref="System.Security.SecurityException"></exception> // <exception cref="UnauthorizedAccessException"></exception> // <exception cref="Zebra.Sdk.Card.Exceptions.ZebraCardException"></exception> // <exception cref="Zebra.Sdk.Device.ZebraIllegalArgumentException"></exception> private ZebraCardImageI DrawCarnetBack(ZebraGraphics graphics, PrintType printType, DataTable data) { int positionx = 775; int positiony = 380; Font font = new Font("Arial", 7, FontStyle.Bold); Font fontIGSS = new Font("Arial", 9, FontStyle.Bold); Font fontFechaEmision = new Font("Arial", 5, FontStyle.Regular); string Recomendaciones = "La empresa no se hace responsable por el mal uso de este carné, " + "el cual es válido únicamente dentro de nuestras instalaciones y durante el periodo de relación laboral." + " En caso de emergencia comunicarse con Recursos Humanos al 7820-1700."; string NumeroDeEmpleado = data.Rows[0]["NumeroDeEmpleado"].ToString(); string ImpresionCarnet = data.Rows[0]["ImpresionCarnet"].ToString(); string AfiliacionIGSS = data.Rows[0]["AfiliacionIGSS"].ToString(); graphics.Initialize(0, 0, OrientationType.Landscape, printType, Color.White); graphics.DrawText(Recomendaciones, font, Color.Black, 10, 10, 1000, 200, 0, TextAlignment.Left, TextAlignment.Center); using (Code39Util code39 = ZebraBarcodeFactory.GetCode39(graphics)) { code39.ValueToEncode = NumeroDeEmpleado + "-" + ImpresionCarnet; code39.QuietZoneWidth = 0; code39.DrawBarcode(100, 190, 800, 180); } if (File.Exists(@"\\nastrfca1\ArchivosAdjuntosSistemas\Carnet\" + NumeroDeEmpleado + "VCARDV3.png")) { string QRVCardImagePath = @"\\nastrfca1\ArchivosAdjuntosSistemas\Carnet\" + NumeroDeEmpleado + "VCARDV3.png"; byte[] QRVCardimageData = File.ReadAllBytes(QRVCardImagePath); graphics.DrawImage(QRVCardimageData, 10, 380, 270, 270, RotationType.RotateNoneFlipNone); } else { positionx = 10; positiony = 380; } graphics.DrawText("Afiliación IGSS: ", font, Color.Black, 280, 405, 600, 45, 0, TextAlignment.Left, TextAlignment.Center); if (!string.IsNullOrEmpty(AfiliacionIGSS)) { graphics.DrawText(AfiliacionIGSS, fontIGSS, Color.Black, 280, 435, 600, 50, 0, TextAlignment.Left, TextAlignment.Center); } graphics.DrawText("Teléfono Clínica Médica:", font, Color.Black, 280, 480, 600, 45, 0, TextAlignment.Left, TextAlignment.Center); graphics.DrawText("7820 1746", fontIGSS, Color.Black, 280, 510, 600, 45, 0, TextAlignment.Left, TextAlignment.Center); graphics.DrawText("Fecha de Emisión:", fontFechaEmision, Color.Black, 280, 540, 600, 45, 0, TextAlignment.Left, TextAlignment.Center); graphics.DrawText(DateTime.Now.ToString("dd/MM/yyyy"), fontFechaEmision, Color.Black, 280, 570, 600, 45, 0, TextAlignment.Left, TextAlignment.Center); using (QRCodeUtil qrCode = ZebraBarcodeFactory.GetQRCode(graphics)) { qrCode.ValueToEncode = NumeroDeEmpleado; qrCode.DrawBarcode(positionx, positiony, 180, 180); } return(graphics.CreateImage()); }
public void GenerateQRCodeForMarketingOrders(int activityTaocanId) { AppSettings settings = AppSettings.GetAppSettings(); string qrfolder = System.IO.Path.Combine(settings.RootDirectory, settings.QRFolder); using (chargebitEntities db = new chargebitEntities()) { Marketing_Activities activity = null; Customer customer = null; List <Marketing_Orders> orders = (from o in db.Marketing_Orders where o.ActivityTaocanId == activityTaocanId select o).ToList <Marketing_Orders>(); if (orders.Count > 0) { foreach (Marketing_Orders order in orders) { if (order.Used) { continue; } if (!string.IsNullOrEmpty(order.CodePath)) { string tmpPhysicalPath = Path.Combine(settings.RootDirectory, order.CodePath.Replace('/', '\\')); if (File.Exists(tmpPhysicalPath)) { continue; } } if (activity == null) { activity = (from a in db.Marketing_Activities where a.Id == order.ActivityId select a).FirstOrDefault <Marketing_Activities>(); if (activity == null) { continue; } if (customer == null) { customer = (from c in db.Customer where c.Id == activity.CustomerId select c).FirstOrDefault <Customer>(); } } string midPhysicalPath = string.Format("{0}\\{1}", activity.AgentId, activity.CustomerId); string fileName = Guid.NewGuid().ToString() + ".png"; string urlAbsPath = string.Format("{0}/{1}/{2}", activity.AgentId, activity.CustomerId, fileName); string parameter = string.Empty; //string.Format("agentId={0}&customerId={1}&activityId={2}&activityOrderId={3}", activity.AgentId, activity.CustomerId,activity.Id,order.Id); SortedDictionary <string, string> ps = new SortedDictionary <string, string>(); ps["agentId"] = activity.AgentId.ToString(); ps["customerId"] = activity.CustomerId.ToString(); ps["activityId"] = activity.Id.ToString(); ps["activityOrderId"] = order.Id.ToString(); StringBuilder pstr = new StringBuilder(); int count = 1; foreach (KeyValuePair <string, string> p in ps) { pstr.Append(p.Key); pstr.Append("="); pstr.Append(p.Value); if (count < ps.Count) { pstr.Append("&"); } count++; } parameter = pstr.ToString(); pstr.Append("&key="); pstr.Append(customer.Token); parameter = parameter + "&signature=" + UrlSignUtil.GetMD5(pstr.ToString()); parameter = KMEncoder.Encode(parameter); string codeContent = string.Format("{0}/Product/SaoMa?p={1}", settings.WebURL, parameter); string fullFolder = Path.Combine(qrfolder, midPhysicalPath); QRCodeUtil.CreateQRCode(fullFolder, fileName, codeContent); if (File.Exists(Path.Combine(fullFolder, fileName))) { order.CodePath = urlAbsPath; } } db.SaveChanges(); } } }
public string GenerateActivityQRCode(int agendId, int customerId, int activityId) { string codePath = string.Empty; agendId = agendId > 0 ? agendId : CurrentLoginUser.User.Id; AppSettings settings = AppSettings.GetAppSettings(); using (chargebitEntities db = new chargebitEntities()) { Marketing_Activities activity = (from a in db.Marketing_Activities where a.Id == activityId select a).FirstOrDefault <Marketing_Activities>(); if (activity == null) { throw new KMBitException(string.Format("编号为:{0}的活动不存在", activityId)); } if (activity.CustomerId != customerId) { throw new KMBitException(string.Format("编号为{0}的活动不属于编号为{1}的客户", activityId, customerId)); } if (activity.AgentId != agendId) { throw new KMBitException(string.Format("编号为{0}的活动不属于编号为{1}的代理的客户的活动", activityId, agendId)); } Customer customer = (from c in db.Customer where c.Id == customerId select c).FirstOrDefault <Customer>(); codePath = agendId + "\\" + customerId; string fileName = Guid.NewGuid().ToString() + ".png"; string absPath = agendId + "/" + customerId + "/" + fileName; string fullDirectory = Path.Combine(settings.RootDirectory + "\\" + settings.QRFolder, codePath); if (!string.IsNullOrEmpty(activity.CodePath) && File.Exists(Path.Combine(settings.RootDirectory + "\\" + settings.QRFolder, activity.CodePath.Replace('/', '\\')))) { return(activity.CodePath); } string parameter = string.Empty;// string.Format("agentId={0}&customerId={1}&activityId={2}", agendId, customerId, activityId); SortedDictionary <string, string> ps = new SortedDictionary <string, string>(); ps["agentId"] = activity.AgentId.ToString(); ps["customerId"] = activity.CustomerId.ToString(); ps["activityId"] = activity.Id.ToString(); StringBuilder pstr = new StringBuilder(); int count = 1; foreach (KeyValuePair <string, string> p in ps) { pstr.Append(p.Key); pstr.Append("="); pstr.Append(p.Value); if (count < ps.Count) { pstr.Append("&"); } count++; } parameter = pstr.ToString(); pstr.Append("&key="); pstr.Append(customer.Token); parameter = parameter + "&signature=" + UrlSignUtil.GetMD5(pstr.ToString()); parameter = KMEncoder.Encode(parameter); string codeContent = string.Format("{0}/Product/SaoMa?p={1}", settings.WebURL, parameter); QRCodeUtil.CreateQRCode(fullDirectory, fileName, codeContent); if (File.Exists(Path.Combine(fullDirectory, fileName))) { activity.CodePath = absPath; } db.SaveChanges(); return(absPath); } }