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); }
/// <summary> /// 生成微信二维码 /// </summary> /// <param name="scene_str"></param> /// <param name="access_token"></param> /// <param name="scene_id"></param> /// <param name="isTemp"></param> /// <returns></returns> public static WXQRResult getQR(string scene_str, string access_token, string scene_id = "0", bool isTemp = false) { WXQRResult resObj = null; try { //获取数据的地址(微信提供) String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" + access_token; //发送给微信服务器的数据 String jsonStr = "{\"action_name\": \"QR_LIMIT_SCENE\", \"action_info\":{\"scene\": {\"scene_id\":" + scene_id + "}}}"; if (!string.IsNullOrEmpty(scene_str)) { if (isTemp) { jsonStr = "{\"expire_seconds\": \"180\",\"action_name\": \"QR_STR_SCENE\", \"action_info\":{\"scene\": {\"scene_str\":\"" + scene_str + "\"}}}"; } else { jsonStr = "{\"action_name\": \"QR_LIMIT_STR_SCENE\", \"action_info\":{\"scene\": {\"scene_str\":\"" + scene_str + "\"}}}"; } } //post请求得到返回数据(这里是封装过的,就是普通的java post请求) String response = HttpHelper.RequestUrlSendMsg(url, HttpHelper.HttpMethod.Post, jsonStr); resObj = JsonConvert.DeserializeObject <WXQRResult>(response); /* * HTTP GET请求(请使用https协议)https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET * 提醒:TICKET记得进行UrlEncode */ resObj.ticket = Uri.EscapeDataString(resObj.ticket); } catch (Exception ex) { NLogHelper.ErrorTxt("[getQR]:" + ex.Message); } return(resObj); }
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; } }