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

合集下载

h5在微信生成分享海报(带二维码)

h5在微信生成分享海报(带二维码)

h5在微信⽣成分享海报(带⼆维码)⼀、前⾔⼈⽣处处是坑,最近做⼀个h5项⽬,弄这个海报很是头疼,来⾃萌新的⽆助。

终于在访遍了n多个帖⼦,问了n个热⼼群友,⾃⼰顿悟之后写了出来之前的需求是保存海报,但是在微信中根本是⽆法保存的,最后做成图⽚然后长按保存。

⼆、⼯具1. qrcode.js⽣成⼆维码2. html2canvas⽣成图⽚三、实现思路⾸先⽤qrcode⽣成⼆维码,然后拿到后台传的背景,接着把⼆维码放在背景的中央,最后使⽤html2canvas截取包含⼆维码和背景的div,保存成功⼀张图⽚,把这个图⽚渲染出来,长按即可在微信分享、保存了四、代码//⽤qrcodejs⽣成⼆维码createQrcode() {this.qrcodeUrl = this.host + '/#/reg' + this.qrCodeInfo[0].url;let qrcode = new QRCode('qrcode', {width: 120,height: 120,text: this.qrcodeUrl, // ⼆维码地址colorDark: "#000",colorLight: "#fff",correctLevel: QRCode.CorrectLevel.H})}//使⽤html2canvas⽣成海报createPoster() {// ⽣成海报const vm = thisconst domObj = document.getElementById('box')html2canvas(domObj,{useCORS: true,logging: false,}).then(function(canvas) {// 在微信⾥,可长按保存或转发 posterImg ⽣成的海报路径vm.posterImg = canvas.toDataURL('image/png')vm.mask = true;})}⼤功告成,是不是很简单,可是对于从未接触的萌新,可是耗费了⼀些功夫。

PHP图片+文字+二维码生成小程序分享海报

PHP图片+文字+二维码生成小程序分享海报

PHP图⽚+⽂字+⼆维码⽣成⼩程序分享海报思路:1、请求微信接⼝获取⼀定尺⼨微信⼆维码2、准备海报主图,处理尺⼨按⽐例缩放3、准备分享语录,计算段落⾼度4、⽣成海报:创建画布,分写别⼊按顺序和位置写⼊⼆维码、图⽚、⽂字等5、保存海报具体如下:1、请求微信接⼝获取⼀定尺⼨微信⼆维码$access_token = 'jkagfgjkdahfgadhsfkdsj';$url = sprintf("https:///cgi-bin/wxaapp/createwxaqrcode?access_token=%s",$access_token);$postdata = '{"path": "/pages/subActivity/pages/activityDetail/activityDetail?id='.$id.'", "width": 210}';//微信的⼆维码$image = http_post($url,$postdata);//准备微信⼆维码以备⽣成海报使⽤$wxim = imagecreatefromstring($image);$wxim_size = 270;function http_post($url = '', $param = '') {if (empty($url) || empty($param)) {return false;}$postUrl = $url;$curlPost = $param;$ch = curl_init();//初始化curlcurl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定⽹页curl_setopt($ch, CURLOPT_HEADER, 0);//设置headercurl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上curl_setopt($ch, CURLOPT_POST, 1);//post提交⽅式curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);$data = curl_exec($ch);//运⾏curlcurl_close($ch);return $data;}2、准备海报主图,处理尺⼨按⽐例缩放$share_img = '图⽚路径'$share_img_size = getimagesize($share_img); //图⽚尺⼨$shareim = imagecreatefromstring(file_get_contents($share_img));//计算原图长宽⽐例$size_rate = $share_img_size[1]/$share_img_size[0];//新图尺⼨$share_img_width = 450;$share_img_height = intval($share_img_width*$size_rate);//复制⽣成新图并保存$new_share_img = imagecreatetruecolor($share_img_width, $share_img_height);imagecopyresampled($new_share_img, $shareim, 0, 0, 0, 0,$share_img_width,$share_img_height,$share_img_size[0], $share_img_size[1]); $new_share_img_filename = $dir.'/'.$id.'_new_share.jpg';imagejpeg($new_share_img, $new_share_img_filename);imagedestroy($new_share_img);//准备可写⼊新分享主图以备⽣成海报使⽤$new_shareim = imagecreatefromstring(file_get_contents($dir.'/'.$id.'_new_share.jpg'));unlink($new_share_img_filename); //删除临时新的分享图3、准备分享语录⽂字,计算⾼度//准备分享语录$content = "";// 将字符串拆分成⼀个个单字保存到数组 letter 中for ($i=0;$i<mb_strlen($share_title);$i++) {$letter[] = mb_substr($share_title, $i, 1);}foreach ($letter as$l) {$teststr = $content." ".$l;$share_title_size = imagettfbbox(16, 0, $font, $teststr);// 判断拼接后的字符串是否超过预设的宽度if (($share_title_size[2] > $share_img_width) && ($content !== "")) {$content .= "\n";}$content .= $l;} //⽂字⾼度$share_title_height = $share_title_size[3];4、⽣成海报:创建画布,分写别⼊按顺序和位置写⼊⼆维码、图⽚、⽂字等//⽣成海报$font = FCPATH.'/styles/font/wryh.ttf'; //保证字体⽂件⽬录正确$filepath = $dir.'/'.$id.'_p.jpg';$posters_width = 510;$posters_height = 130 + $share_img_height+$share_title_height + 280;$newimg = imagecreatetruecolor($posters_width, $posters_height);$bg = imagecolorallocate($newimg, 255, 255, 255);imagefill($newimg,0,0,$bg);$black = imagecolorallocate($newimg, 0, 0, 0);//写宣传⾔imagettftext($newimg,18,0,30,47,$black,$font,'美好⽣活');imagettftext($newimg,15,0,30,76,$black,$font,'关注美好⽣活了解社区好⽣活');//写分享图⽚imagecopy($newimg,$new_shareim,30,95,0,0,$share_img_width,$share_img_height);//写分享标题imagettftext ($newimg, 15, 0, 30, $share_img_height+122, $black, $font, $content );//写⼆维码$wxim_start_hight = 130+$share_title_height+$share_img_height;imagecopy($newimg,$wxim,20,$wxim_start_hight,0,0,$wxim_size,$wxim_size);$gray = imagecolorallocate($newimg, 136, 136, 136);//写提⽰语$tips = '长按保存海报⾄⼿机相册';$tips_hight = $wxim_start_hight+200;imagettftext($newimg,13,0,290,$tips_hight,$gray,$font,$tips);//海报⽣成保存imagejpeg($newimg, $filepath);ImageDestroy($newimg);ImageDestroy($wxim);整体代码 $access_token = '请求微信接⼝的aceess_token';if($access_token){$url = sprintf("https:///cgi-bin/wxaapp/createwxaqrcode?access_token=%s",$access_token);$postdata = '{"path": "/pages/subActivity/pages/activityDetail/activityDetail?id='.$id.'", "width": 210}';//微信的⼆维码$image = http_post($url,$postdata);if(strlen($image) < 200){ //出错了log_message('error',"getTopicQRCodeProcessed, error : " . $image);//刷新tokenls('wx_service');$this->wx_service->refreshToken();return false;}$dir = FCPATH.'upload/qrcode/'.date('Ym');MkFolder($dir);$path = $dir.'/'.$id.'.jpg';file_put_contents($path,$image);$qrcode = pathATOR($path);$share_title = element('share_title',$event);$share_img = element('share_img_moment',$event) ? : element('cover',$event);$share_img = get_oss_file_url($share_img);$font = FCPATH.'/styles/font/wryh.ttf';//准备分享图⽚先处理图⽚尺⼨$share_img_size = getimagesize($share_img);$shareim = imagecreatefromstring(file_get_contents($share_img));$size_rate = $share_img_size[1]/$share_img_size[0];$share_img_width = 450;$share_img_height = intval($share_img_width*$size_rate);$new_share_img = imagecreatetruecolor($share_img_width, $share_img_height);imagecopyresampled($new_share_img, $shareim, 0, 0, 0, 0,$share_img_width,$share_img_height,$share_img_size[0], $share_img_size[1]);$new_share_img_filename = $dir.'/'.$id.'_new_share.jpg';imagejpeg($new_share_img, $new_share_img_filename);imagedestroy($new_share_img);$new_shareim = imagecreatefromstring(file_get_contents($dir.'/'.$id.'_new_share.jpg'));unlink($new_share_img_filename);//准备分享标题$content = "";// 将字符串拆分成⼀个个单字保存到数组 letter 中for ($i=0;$i<mb_strlen($share_title);$i++) {$letter[] = mb_substr($share_title, $i, 1);}foreach ($letter as$l) {$teststr = $content." ".$l;$share_title_size = imagettfbbox(16, 0, $font, $teststr);// 判断拼接后的字符串是否超过预设的宽度if (($share_title_size[2] > $share_img_width) && ($content !== "")) {$content .= "\n";}$content .= $l;}$share_title_height = $share_title_size[3];//准备微信⼆维码$wxim = imagecreatefromstring($image);$wxim_size = 270;//⽣成海报$filepath = $dir.'/'.$id.'_p.jpg';$posters_width = 510;$posters_height = 130 + $share_img_height+$share_title_height + 280;$newimg = imagecreatetruecolor($posters_width, $posters_height);$bg = imagecolorallocate($newimg, 255, 255, 255);imagefill($newimg,0,0,$bg);$black = imagecolorallocate($newimg, 0, 0, 0);//写宣传⾔imagettftext($newimg,18,0,30,47,$black,$font,'昌品⽣活');imagettftext($newimg,15,0,30,76,$black,$font,'关注昌品⽣活了解社区好⽣活');//写分享图⽚imagecopy($newimg,$new_shareim,30,95,0,0,$share_img_width,$share_img_height);//写分享标题imagettftext ($newimg, 15, 0, 30, $share_img_height+122, $black, $font, $content );//写⼆维码$wxim_start_hight = 130+$share_title_height+$share_img_height;imagecopy($newimg,$wxim,20,$wxim_start_hight,0,0,$wxim_size,$wxim_size);$gray = imagecolorallocate($newimg, 136, 136, 136);//写提⽰语$tips = '长按保存海报⾄⼿机相册';$tips_hight = $wxim_start_hight+200;imagettftext($newimg,13,0,290,$tips_hight,$gray,$font,$tips);//海报⽣成保存imagejpeg($newimg, $filepath);ImageDestroy($newimg);ImageDestroy($wxim);$posters = pathATOR($filepath);。

微信小程序生成二维码之传参(接收的参数乱码该咋解决)

微信小程序生成二维码之传参(接收的参数乱码该咋解决)

微信⼩程序⽣成⼆维码之传参(接收的参数乱码该咋解决)
先说我的案例,我需要的是,扫码进⼊不同的区域展⽰(因此这个就需要进⾏⼆维码路径传参),⼤致思路:接收数据,然后根据所接收的数据进⾏判断,展⽰不同的区域。

路径是这样的:pages/addPage/addPage?location=阿⾥爸爸
因此,我们就需要转译,通过所接收的参数进⾏转译然后得到正确的字符(阿⾥爸爸)
下串代码只做接收并进⾏转译操作
onLoad(option){
this.currentLocation = option.location;
//默认如果没有传输地址就为嘻嘻
if (!this.currentLocation || this.currentLocation === undefined || this.currentLocation.trim() === '') {
this.currentLocation = '嘻嘻';
} else if (this.currentLocation.indexOf('\\u') != -1) {
// UNICODE转中⽂
this.currentLocation = unescape(this.currentLocation.replace(/\\u/g, '%u'));
} else if (this.currentLocation.indexOf('%') != -1) {
// encodeURI 转中⽂
this.currentLocation = decodeURI(this.currentLocation);
}
}。

微信小程序动态生成二维码的实现代码

微信小程序动态生成二维码的实现代码

微信⼩程序动态⽣成⼆维码的实现代码效果图如下:实现wxml<!-- 存放⼆维码的图⽚--><view class='container'><image bindtap="previewImg" mode="scaleToFill" src="{{imagePath}}"></image></view><!-- 画布,⽤来画⼆维码,只⽤来站位,不⽤来显⽰--><view class="canvas-box"><canvas hidden="{{canvasHidden}}" style="width: 686rpx;height: 686rpx;background:#f1f1f1;" canvas-id="mycanvas" /></view>wxss.container {display: flex;align-items: center;justify-content: center;width: 100%;height: 100%;}.container image {width: 686rpx;height: 686rpx;background-color: #f9f9f9;}.canvas-box {position: fixed;top: 999999rpx;left: 0;}jsvar QR = require("../../../lib/qrcode.js");Page({/*** 页⾯的初始数据*/data: {canvasHidden: false,imagePath: '',},/*** ⽣命周期函数--监听页⾯加载*/onLoad: function(options) {//option为上个页⾯传递过来的参数var jiaoyanCode = 'sorry,jiaoyanCode is loss';if (options) {jiaoyanCode = options.jiaoyanCode;}console.log(jiaoyanCode);var size = this.setCanvasSize(); //动态设置画布⼤⼩this.createQrCode(jiaoyanCode, "mycanvas", size.w, size.h);},//适配不同屏幕⼤⼩的canvassetCanvasSize: function() {var size = {};try {var res = wx.getSystemInfoSync();var scale = 750 / 686; //不同屏幕下canvas的适配⽐例;设计稿是750宽 686是因为样式wxss⽂件中设置的⼤⼩var width = res.windowWidth / scale;var height = width; //canvas画布为正⽅形size.w = width;size.h = height;} catch (e) {// Do something when catch errorconsole.log("获取设备信息失败" + e);}return size;},/*** 绘制⼆维码图⽚*/createQrCode: function(url, canvasId, cavW, cavH) {//调⽤插件中的draw⽅法,绘制⼆维码图⽚QR.api.draw(url, canvasId, cavW, cavH);setTimeout(() => {this.canvasToTempImage();}, 1000);},/*** 获取临时缓存照⽚路径,存⼊data中*/canvasToTempImage: function() {var that = this;//把当前画布指定区域的内容导出⽣成指定⼤⼩的图⽚,并返回⽂件路径。

17种微信小程序推广方法,你知道几个?

17种微信小程序推广方法,你知道几个?

17种微信小程序推广方法,你知道几个?目前火热的微信小程序,很多企业、商家都纷纷注册开发,但之后便不了了之了,用户/消费者根本不了解企业、商家是否有微信小程序,归根结底是推广做的不到位,微信小程序应该怎么做推广呢?下面是腾鸽信息为大家整理的一份详细的微信小程序推广方法。

(图片来源于网络)1、附近的小程序(免费)在「附近的小程序」中,小程序自动展现给周边5km 内的微信用户,所有符合条件的小程序能在「附近的小程序」中被免费曝光,且一个小程序能添加10个地理位置。

也就是说,做一个小程序,相当于给店铺增加10倍曝光的机会。

2、分享,实现粉丝裂变(免费)微信小程序支持直接分享到微信群里面,所以一些精准的用户群是可以作为小程序推广场所的,这种推广与传统的公众号推广还不同,不需要用户点开链接,再扫码或者点击名称关注。

用户觉得有需要,直接打开小程序就行,不需要关注等任何操作,觉得不合适直接关闭就行。

另外像QQ群,豆瓣群,以及百度贴吧,天涯论坛,知乎等,都可以作为小程序推广的途径。

3、拼团(免费)用小程序来承载拼团、秒杀、砍价等优惠活动,激发消费者低价消费的积极性,实现快速裂变。

这种玩法,可在较短时间内,积累出庞大的精准用户,后期商家可借此进行精准营销。

目前,电商类小程序TOP1和2就是蘑菇街和拼多多,啥也不说了,买就一定要拼。

4、附近的小程序广告(需付费)附近的小程序是微信开放的关键流量入口,同时开放了广告投放渠道。

广告位是在附近小程序的第三行,点击即可打开对应的小程序。

5、聊天小程序(免费)把小程序任何一个页面分享到群,在群聊天信息页面可以查看10个被分享到群的小程序,方便群成员在有需求时方便快捷找到你的小程序,这也是小程序打通微信社群的一大妙招。

6、小程序商店(需付费)通过付费或其他方式将小程序投放至小程序商店,起到一定的宣传推广效果。

7、地推(免费,但是需成本)对于部分小程序而言,地推或许是最贴近用户场景的推广方式,线下以小程序码的方式,通过宣传物料等推广小程序。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
相关文档
最新文档