public bool GenQRInvite(string openId, string phone, string headerUrl) { var qr = _dbContext.DBQRInvite.Where(a => a.UserOpenId == openId && a.InviteQRType == InviteQRType.UserInvite).FirstOrDefault(); if (qr != null) { throw new EduException("不能重复创建邀请码"); } string qrDownFilePath = EduEnviroment.GetQRInviteUserFilePath($"OrigUserInvite_{phone}.png"); string qrWithLogoFilePath = EduEnviroment.GetQRInviteUserFilePath($"UserInviteWithLogo_{phone}.png"); string bkFilePath = EduEnviroment.GetQRFilePath("InviteBK.png"); string finalFilePath = EduEnviroment.GetQRInviteUserFilePath($"FinalUserInvite_{phone}.png"); AccessToken accessToken = WXApi.getAccessToken(); WXQRResult result = WXApi.getQR(WxConfig.QR_Invite_User + "_" + openId, accessToken.access_token); WXApi.DownLoadWXQR(result.ticket, qrDownFilePath); //添加Logo ,且添加文字 List <string> text = new List <string>(); text.Add("您的朋友邀请您加入云艺书院"); QRHelper.AddLogoForQR(headerUrl, new Bitmap(qrDownFilePath), qrWithLogoFilePath, text); //添加背景 QRHelper.AddBKForQR(bkFilePath, qrWithLogoFilePath, finalFilePath); qr = new EQRInvite() { OrigFilePath = EduEnviroment.VirPath_QRInviteUser + $"OrigUserInvite_{phone}.png", FileWithLogoPath = EduEnviroment.VirPath_QRInviteUser + $"UserInviteWithLogo_{phone}.png", FinalFilePath = EduEnviroment.VirPath_QRInviteUser + $"FinalUserInvite_{phone}.png", InviteQRType = InviteQRType.UserInvite, RecordStatus = RecordStatus.Normal, TargetUrl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" + result.ticket + "", CreateDateTime = DateTime.Now, UserOpenId = openId }; _dbContext.DBQRInvite.Add(qr); _dbContext.SaveChanges(); return(true); }
public IActionResult OnPostCreateLessonQR(ELessonQR qr) { ResultNormal result = new ResultNormal(); try { var code = EduCodeGenerator.Tool_LessonQRCode(); var url = $"http://edu.iqianba.cn/Tools/QRScan?code={code}"; qr.Code = code; qr.CreateDateTime = DateTime.Now; string filePath = EduEnviroment.DicPath_Tools_LessonQR + $"{code}.png"; qr.QRFilePath = EduEnviroment.VirPath_Tools_LessonQR + $"{code}_logo.png"; string filePathWithLogo = EduEnviroment.DicPath_Tools_LessonQR + $"{code}_logo.png"; var desc = new List <string>(); if (!string.IsNullOrEmpty(qr.Name)) { desc.Add(qr.Name); } QRHelper.GenQR(url, filePath, desc); var logoUrl = "http://edu.iqianba.cn/images/logo_120.png"; QRHelper.AddLogoForQR(logoUrl, new Bitmap(filePath), filePathWithLogo); _ToolsSrv.AddQR(qr); _ToolsSrv.SaveChanges(); result.SuccessMsg = qr.QRFilePath; } catch (Exception ex) { result.ErrorMsg = ex.Message; } return(new JsonResult(result)); }