laravel 微信生成带参数的二维码

微信生成带参数的二维码 查看微信官方文档
https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html

 

安装

使用 composer:

$ composer require overtrue/wechat:~4.0 -vvv

 

目前有 2 种类型的二维码:

  1. 临时二维码,是有过期时间的,最长可以设置为在二维码生成后的 30天后过期,但能够生成较多数量。临时二维码主要用于帐号绑定等不要求二维码永久保存的业务场景
  2. 永久二维码,是无过期时间的,但数量较少(目前为最多10万个)。永久二维码主要用于适用于帐号绑定、用户来源统计等场景。

创建临时二维码

$result = $app->qrcode->temporary('foo', 6 * 24 * 3600);

// Array
// (
//     [ticket] => gQFD8TwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyTmFjVTRWU3ViUE8xR1N4ajFwMWsAAgS2uItZAwQA6QcA
//     [expire_seconds] => 518400
//     [url] => http://weixin.qq.com/q/02NacU4VSubPO1GSxj1p1k
// )

 

创建永久二维码

$result = $app->qrcode->forever(56);// 或者 $app->qrcode->forever("foo"); //字段串是对应用户扫码时间的EventKey值
// Array
// (
//     [ticket] => gQFD8TwAAAAAAAAAAS5odHRwOi8vd2VpeGluLnFxLmNvbS9xLzAyTmFjVTRWU3ViUE8xR1N4ajFwMWsAAgS2uItZAwQA6QcA
//     [url] => http://weixin.qq.com/q/02NacU4VSubPO1GSxj1p1k
// )

 

获取二维码网址

$url = $app->qrcode->url($ticket);
// https://api.weixin.qq.com/cgi-bin/showqrcode?ticket=TICKET

获取二维码内容

 
$url = $app->qrcode->url($ticket);

$content = file_get_contents($url); // 得到二进制图片内容

file_put_contents(__DIR__ . '/code.jpg', $content); // 写入文件

详见地址:https://www.easywechat.com/docs/4.x/basic-services/qrcode

 

posted @ 2020-11-05 10:43  jintaonote  阅读(653)  评论(0编辑  收藏  举报