通过get请求获取专属海报

     /*** 获取专属海报** @param mid    会议编号* @param openId 邀请人唯一码* @return*/@SneakyThrows@ApiOperation(value = "获取专属海报", notes = "获取专属海报")@RequestMapping(value = "/getOwnPoster")public ModelAndView getOwnPoster(@RequestParam(value = "mid") String mid,@RequestParam(value = "code", required = false) String code,@RequestParam(value = "openId", required = false) String openId,HttpServletRequest request, HttpServletResponse response) {if (StringUtil.isEmpty(openId)) {if (StringUtil.isNotEmpty(code)) {LOGGER.info("开始调用TencentApi服务,code为:{}", code);// 微信用户信息String wxResult = tencentApiClient.getWxUserInfo(code);LOGGER.info("调用微信接口返回信息:{}", wxResult);if (ERROR_CODE.equals(wxResult)) {ModelAndView modelAndView = new ModelAndView("html/error");return modelAndView;} else {WxUserInfoVo wxUserInfoVo = JSON.parseObject(wxResult, WxUserInfoVo.class);// 保存微信用户信息到裂变主表wxFisssionService.saveWxUserInfoToMain(wxUserInfoVo, mid);openId = wxUserInfoVo.getOpenid();String url = "https://m.woyaoce.cn/special/act/getOwnPoster?mid=" + mid + "&openId=" + openId;response.sendRedirect(url);}}}// 根据openid、mid获取一条唯一微信用户信息List<WxFissionInnovation> wxUserInfos = wxFissionInnovationMapper.getUserInfoByOpenIdAndMid(openId, mid);// 生成专属二维码String url = "https://m.woyaoce.cn/special/act/getCode?mid=" + mid + "&aoid=" + openId;LOGGER.info("我的专属海报地址是:{}" + url);String qrcode = QRCodeUtil.creatRrCode(url, 200, 200);ModelAndView modelAndView = new ModelAndView("wxfission/qr");modelAndView.addObject("qrcode", qrcode);if (wxUserInfos.get(0).getNickName().length() > 5) {wxUserInfos.get(0).setNickName(wxUserInfos.get(0).getNickName().substring(0, 3) + "...");}modelAndView.addObject("wxUserInfo", wxUserInfos.get(0));//微信分享StringBuilder sb = new StringBuilder("https://m.woyaoce.cn/special/act/getOwnPoster");Enumeration enu = request.getParameterNames();//获取请求参数名信息String key = "";int a = 1;while (enu.hasMoreElements()) {key = (String) enu.nextElement();//得到参数名if (!"id".equals(key)) {sb.append((a == 1 ? "?" : "&") + key + "=" + request.getParameter(key));//获取参数值,同时进行拼装a++;}}String s = sb.toString();WeiXinJsSdk weiXinJsSdk = new WeiXinJsSdk();String encodeUrl = "";try {encodeUrl = URLEncoder.encode(s, "UTF-8");String url1 = "http://Openapi.woyaoce.cn/WeiXinJsSdk/GetInsSdk?url=" + encodeUrl;System.out.println(url1);LinkedHashMap<String, String> map = new LinkedHashMap<>();map.put("url", encodeUrl);String ss = HttpXmlClient.httpGet("http://Openapi.woyaoce.cn/WeiXinJsSdk/GetInsSdk", map);weiXinJsSdk = JsonUtils.toBean(ss, WeiXinJsSdk.class);} catch (Exception e) {e.printStackTrace();}weiXinJsSdk.setNowurl(s);weiXinJsSdk.setSharetitle(wxUserInfos.get(0).getNickName() + "邀请您报名参加" + wxUserInfos.get(0).getMetName());weiXinJsSdk.setSharcontent("");String imgUrl = "https://img1.17img.cn/ui/simg/woyaoce/20180125/images/300_300wyc.jpg";weiXinJsSdk.setSharimg(imgUrl);modelAndView.addObject("weiXinJsSdk", weiXinJsSdk);return modelAndView;}/*** 微信公众号中点击获取专属海报链接** @param mid      会议编号* @param response*/@ApiOperation(value = "微信公众号中点击获取专属海报链接", notes = "微信公众号中点击获取专属海报链接")@RequestMapping(value = "/getPosterForGzh")public void getPosterForGzh(@RequestParam(value = "mid") String mid,HttpServletResponse response) {String redirectUri = "https://m.woyaoce.cn/special/act/getOwnPoster?mid=" + mid;try {redirectUri = URLEncoder.encode(redirectUri, "utf-8");} catch (UnsupportedEncodingException e) {e.printStackTrace();}// 微信授权接口String getCodeUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?" +"appid=" + WxConstants.APPID +"&redirect_uri=" + redirectUri +"&response_type=code&" +"scope=snsapi_userinfo&" +"state=STATE&connect_redirect=1#wechat_redirect";try {response.sendRedirect(getCodeUrl);} catch (IOException e) {e.printStackTrace();LOGGER.error("错误信息为:", e);}}

生成专属二维码关键代码


import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;
import sun.misc.BASE64Encoder;import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Hashtable;public class QRCodeUtil {public static String creatRrCode(String contents, int width, int height) {String binary = null;Hashtable hints = new Hashtable();hints.put(EncodeHintType.CHARACTER_SET, "utf-8");try {BitMatrix bitMatrix = new MultiFormatWriter().encode(contents, BarcodeFormat.QR_CODE, width, height, hints);// 1、读取文件转换为字节数组ByteArrayOutputStream out = new ByteArrayOutputStream();BufferedImage image = toBufferedImage(bitMatrix);//转换成png格式的IO流ImageIO.write(image, "png", out);byte[] bytes = out.toByteArray();// 2、将字节数组转为二进制BASE64Encoder encoder = new BASE64Encoder();binary = encoder.encodeBuffer(bytes).trim();} catch (WriterException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return binary;}/*** image流数据处理** @author ianly*/public static BufferedImage toBufferedImage(BitMatrix matrix) {int width = matrix.getWidth();int height = matrix.getHeight();BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);for (int x = 0; x < width; x++) {for (int y = 0; y < height; y++) {image.setRGB(x, y, matrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF);}}return image;}// 使用以下main方法可以直接生成以下链接的专属二维码base64地址,赋值到浏览器上即可看到效果public static void main(String[] args) {String binary = creatRrCode("https://m.woyaoce.cn/special/act/getCode?mid=17657", 200,200);System.out.println(binary);}
}

前端代码

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover"><meta content="yes" name="apple-mobile-web-app-capable"><meta content="black" name="apple-mobile-web-app-status-bar-style"><meta content="telephone=no" name="format-detection"><meta content="email=no" name="format-detection"><meta name="description" content="不超过150个字符"/><meta name="keywords" content=""/><meta content="caibaojian" name="author"/><title th:text="${weiXinJsSdk.getSharetitle()}"></title><link rel="canonical" th:href="${'https://m.woyaoce.cn/special/act/getPosterForGzh?mid='+wxUserInfo.getMid()}"><link rel="stylesheet" href="https://img1.17img.cn/ui/simg/woyaoce/jl/wap/base.css"><link rel="stylesheet" href="/special/static/css/wx/style.css"><script src="/special/static/js/html2canvas.js"></script><script src="https://m.woyaoce.cn/js/jquery-1.7.1.min.js" type="text/javascript"></script><script type="text/javascript">//引入该flexible.min.js!function(e,t){function n(){var n=l.getBoundingClientRect().width;t=t||540,n>t&&(n=t);var i=100*n/e;r.innerHTML="html{font-size:"+i+"px;}"}var i,d=document,o=window,l=d.documentElement,r=document.createElement("style");if(l.firstElementChild)l.firstElementChild.appendChild(r);else{var a=d.createElement("div");a.appendChild(r),d.write(a.innerHTML),a=null}n(),o.addEventListener("resize",function(){clearTimeout(i),i=setTimeout(n,300)},!1),o.addEventListener("pageshow",function(e){e.persisted&&(clearTimeout(i),i=setTimeout(n,300))},!1),"complete"===d.readyState?d.body.style.fontSize="16px":d.addEventListener("DOMContentLoaded",function(e){d.body.style.fontSize="16px"},!1)}(750,750);</script>
</head>
<body>
<div class="box" id="hidden_wrap" style="position: relative"><div class="success-text" id="first" style="position: absolute;margin-left: 0.3rem"><!--当前登录人openid--><input id="openId" th:value="${wxUserInfo.getOpenId()}" hidden="hidden"/><!--当前登录人mid--><input id="mid" th:value="${wxUserInfo.getMid()}" hidden="hidden"/><!--当前登录人mid--><input id="headImgUrl" th:value="${wxUserInfo.getHeadImgUrl()}" hidden="hidden"/><div class="avator center690 clearfix space-s-p-t"><span class="avator-img fl sp"><img id="headImg" th:src="${wxUserInfo.getHeadImgUrl()}" style="position: absolute" crossorigin="anonymous"></span><span class="fl avator-text space-m-m-l space-s-m-t" style="width: 5.2rem"><p class="space-s-m-t"><span class="f18 fw600 color-white ">我是[[${wxUserInfo.nickName}]],邀请您参会:</span></p><p class="space-s-m-t"><span class="f18 fw600 color-white pStyle" style="font-size: 15px">[[${wxUserInfo.metName}]]</span></p></span></div></div><div id="qrcode" class="tc typesetting-secondary f18 pa" style="bottom:0.4rem; right: 0.49rem;"><img style="width:1.8rem;" th:src="'data:image/png;base64,'+${qrcode}" crossorigin="anonymous"></div><!--专属海报背景图--><img id="back-img" src="https://img1.17img.cn/ui/simg/woyaoce/20210203/bg-lb.png">
</div>
<img style="width: 100%;height: auto;" class="o-img" id="o-img" src="" alt="" hidden>
<style>.o-img{position: absolute;top: 0;left: 0;width: 100%;z-index: 20;}.pStyle {margin-top: .1rem;margin-bottom: .1rem;/*border: 1px solid #ccc;*/overflow: hidden;display: -webkit-box;-webkit-line-clamp: 2;-webkit-box-orient: vertical;}
</style>
</body>
<script><!--实现html转图片,进而实现长按分享-->window.onload = function () {html2canvas($("body"),{useCORS:true,  // 跨域allowTaint:false, // 允许污染async: false, // 是否异步解析和呈现元素foreignObjectRendering: true,// 是否在浏览器支持的情况下使用ForeignObject渲染dpi:300, // 清晰度background: "#ffffff", // 背景色onrendered:function(canvas){$("#o-img").show();const dataURL =canvas.toDataURL("image/png");$("#o-img").attr("src",dataURL);$("#back-img").hide();}})}
</script>
<script src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script><!--定制微信专属分享链接-->
<script th:inline="javascript">var shareimg = [[${weiXinJsSdk.sharimg}]];var appid = [[${weiXinJsSdk.appId}]];var newsdesc = [[${weiXinJsSdk.sharcontent}]];var timestamp = [[${weiXinJsSdk.timestamp}]];var nonceStr = [[${weiXinJsSdk.nonceStr}]];var title = [[${weiXinJsSdk.sharetitle}]];var link = [[${weiXinJsSdk.nowurl}]];var signature = [[${weiXinJsSdk.signature}]];console.log(link)if (appid != null && appid != "") {wx.config({debug: false,appId: appid,timestamp: timestamp,nonceStr: nonceStr,signature: signature,jsApiList: ['onMenuShareAppMessage','onMenuShareTimeline','onMenuShareQQ','onMenuShareQZone',]});wx.ready(function () {wx.onMenuShareTimeline({title: title,link: link,imgUrl: shareimg,desc: newsdesc,success: function () {},cancel: function () {}});wx.onMenuShareAppMessage({title: title,imgUrl: shareimg,link: link,desc: newsdesc,success: function () {},cancel: function () {}});wx.onMenuShareQQ({title: title,imgUrl: shareimg,link: link,desc: newsdesc,success: function () {},cancel: function () {}});wx.onMenuShareQZone({title: title,imgUrl: shareimg,link: link,desc: newsdesc,success: function () {},cancel: function () {}});});}
</script></html>

微信生成专属海报(专属二维码)相关推荐

  1. 微信生成带参数的二维码,合成海报,扫码后推送小程序?

    微信服务号渠道二维码功能,支持生成带参数二维码,合成海报二维码,微信扫码后推送内容:结合微号帮平台48小时信息推送,推送微信小程序. 带参二维码 海报二维码 微信扫码后回复 48小时信息推送 在微号帮 ...

  2. 使用 iview 实现PC端生成推广海报与二维码并下载的功能,基于iview Modal 对话框 与 Carousel 走马灯组件实现

    使用 iview 实现PC端生成推广海报与二维码并下载的功能,基于iview Modal 对话框 与 Carousel 走马灯组件实现 前言:最近在对公司网页进行改版的时候遇到一个问题,需要在PC端实 ...

  3. div生成图片_Vue生成分享海报(含二维码)

    本文已同步到专业技术网站 www.sufaith.com, 该网站专注于前后端开发技术与经验分享, 包含Web开发.Nodejs.Python.Linux.IT资讯等板块. 功能需求: 海报有1张背景 ...

  4. 微信小程序生成海报带二维码功能

    wxml文件 <view><text class='shareText'>生成海报分享至</text><view class='imgBox'>< ...

  5. 微信公众平台 生成带参数的二维码

    前言:最近一直在开发微信的东西,总结一下微信生成带参数的二维码.这个其实在参考文章的第一篇总结的非常详细,大家可以参考一下.这里总结一下微信生成带参数二维码的过程和主要开发代码. 注:本文使用Rest ...

  6. [微信开发] - 用户获取推广二维码

    通过生成带参二维码,将用户的openid获取的同时做为参数,生成后,另一个用户扫码该二维码,系统可以获取到新用户openid的同时,也能标识着是哪个用户被扫码了. 更多的图 通过上图可以看到,当A君关 ...

  7. 7个步骤轻松创建你的专属社交媒体二维码!

    使用手机扫描社交媒体二维码之后,你会看到一个众多社交媒体渠道的集合页面. 社交媒体二维码,一个界面链接和连接您所有的社交媒体渠道和数字资源,从微信.微博.QQ.知乎.Bilibili.抖音.快手.小红 ...

  8. 微信小程序二维码生成工具,后端二维码生成工具类。

    微信小程序开发二维码生成工具类 前言 业务背景 设计思路 具体实现 接下来我们进行工具的改造 前言 或许这是你搜寻的第n篇文章来解决你项目中的问题,虽然我不能去替你完全适配你的业务需求,但是我可以给你 ...

  9. 微信公众平台----带参数二维码生成和扫描事件

    原文:微信公众平台----带参数二维码生成和扫描事件 摘要: 账号管理----生成带参数的二维码 消息管理----接收消息----接收事件推送 为了满足用户渠道推广分析和用户帐号绑定等场景的需要,公众 ...

  10. 微信小程序条码、二维码生成模块

    代码地址如下: http://www.demodashi.com/demo/13994.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.c ...

最新文章

  1. U-net结构及代码注释
  2. SQL Server 2005 SP2发布了,开发人员怎么办?
  3. kompozer+mysql_KompoZer for mac下载_KompoZer for mac版V0.8b3下载(暂未上线)_预约_飞翔下载...
  4. html5后代选择符,css选择符有哪些?哪些属性可以继承?
  5. 2020年第十一届蓝桥杯 - 省赛 - Python大学组 - B.寻找2020
  6. 【转】ABP源码分析三:ABP Module
  7. android 6.0 adb,安卓6.0,adb停用系统更新
  8. Httpd2.4简介及CenOS6.6下编译安装
  9. 17秋 SDN课程 第五次上机作业
  10. bzoj3207花神的嘲讽计划Ⅰ
  11. linux shell pattern,shell 三剑客之 sed pattern 详解
  12. 测试用例经典练习之淘宝app购物车测试用例
  13. GitHub——注册github账号、安装git工具、仓库工作流程、创建本地仓库、写项目提交本地仓库、版本回退、创建远程仓库、使用远程仓库、Git忽略文件、协作冲突、分支管理
  14. 天梯赛题目练习——查询水果价格(附带测试点)
  15. IV-18(前苏联ИВ-18)荧光管电子钟【Energy Pillar.能量柱】
  16. python无法读取excel文字_Python帮你做Excel——读取Excel文档
  17. python修改桌面壁纸_python设置windows桌面壁纸
  18. 虚拟机怎么架设dns服务器,虚拟机centos7 DNS服务器搭建
  19. 【高级数理统计R语言学习】9 无序多分类分析
  20. java 离线语音识别

热门文章

  1. OC CoreData简单使用
  2. HBase在共享经济互联网业务的应用
  3. java测试驱动开发(TDD)之《井字游戏》
  4. 世界备份日——如果您丢失了所有文件
  5. php dirname(_FILE_)
  6. bzoj3555 企鹅QQ
  7. httpd服务配置(未完待续)
  8. 7款HTML5的精美应用教程让你立即爱上HTML5
  9. android环境搭建—— 工欲善其事必先利其器
  10. 关于使用struts2上传文件时获取不到文件内容的问题的解决方案