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 void OnPostCreateTecQR() { Msg = "创建成功!"; string qrDownFilePath = EduEnviroment.GetQRInviteTecFilePath("WXInvite.png"); string bkFilePath = EduEnviroment.GetQRFilePath("InviteBK.png"); string finalFilePath = EduEnviroment.GetQRInviteTecFilePath("EduTecInvite.png"); try { AccessToken accessToken = WXApi.getAccessToken(); WXQRResult result = WXApi.getQR(WxConfig.QR_Invite_TecPre, accessToken.access_token); WXApi.DownLoadWXQR(result.ticket, qrDownFilePath); QRHelper.AddBKForQR(bkFilePath, qrDownFilePath, finalFilePath); } catch (Exception ex) { Msg = ex.Message; } }