You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.6 KiB

<?php
namespace app\base\service\mpweixin;
class Qrcode extends Base
{
/**
* 生成小程序码并上传至OSS
* @param string $path 扫码进入的小程序页面路径,最大长度 128 字节,不能为空
* @date 2022-08-24
*/
public function getQrcodeToOss($path)
{
$mp_weixin_param = get_mp_weixin_config();
$oss_param = get_ali_oss_config();
$oss_class = new \ali\oss\Oss($oss_param);
$qrcode_class = new \tencent\wechat\mpweixin\Qrcode($mp_weixin_param);
// 定义临时文件存储路径
$file_dirname = './temp';
// 生成小程序码下载到服务器
$result = $qrcode_class->getQRCode($path, $file_dirname);
// 记录日志
platformLog([
'path' => $path,
'file_dirname' => $file_dirname,
'file_name' => '',
'optional' => []
], $result, 'easy_wechat_mp_weixin_get_qrcode_to_server_uid_' . $this->mid);
// 定义小程序码object
$oss_file_dirname = 'mpweixincode/' . date("Ymd");
// 将本地小程序码上传到OSS
$result = $oss_class->uploadFile($result, $oss_file_dirname);
return $result['url'];
}
/**
* 生成小程序二维码并上传至OSS
* @param string $path 扫码进入的小程序页面路径,最大长度 128 字节,不能为空
* @date 2022-08-24
*/
public function createQrcodeToOss($path)
{
$mp_weixin_param = get_mp_weixin_config();
$oss_param = get_ali_oss_config();
$oss_class = new \ali\oss\Oss($oss_param);
$qrcode_class = new \tencent\wechat\mpweixin\Qrcode($mp_weixin_param);
// 定义临时文件存储路径
$file_dirname = './temp';
// 生成小程序二维码下载到服务器
$result = $qrcode_class->createQRCode($path, $file_dirname);
// 记录日志
platformLog([
'path' => $path,
'file_dirname' => $file_dirname,
'file_name' => '',
'width' => ''
], $result, 'easy_wechat_mp_weixin_create_qrcode_to_server_uid_' . $this->mid);
// 定义小程序码object
$oss_file_dirname = 'qrcode/' . date("Ymd");
// 将本地小程序码上传到OSS
$result = $oss_class->uploadFile($result, $oss_file_dirname);
return $result['url'];
}
/**
* 获取不限制的小程序码并上传至OSS
* @param string $path 扫码进入的小程序页面路径,最大长度 128 字节,不能为空
* @date 2022-08-24
*/
public function getUnlimitedQRCode($path, $scene)
{
$mp_weixin_param = get_mp_weixin_config();
$oss_param = get_ali_oss_config();
$oss_class = new \ali\oss\Oss($oss_param);
$qrcode_class = new \tencent\wechat\mpweixin\Qrcode($mp_weixin_param);
// 定义临时文件存储路径
$file_dirname = './temp';
// 生成不限制的小程序码下载到服务器
$result = $qrcode_class->getUnlimitedQRCode($path, $scene, $file_dirname);
// 记录日志
platformLog([
'path' => $path,
'scene' => $scene,
'file_dirname' => $file_dirname,
'file_name' => '',
'optional' => []
], $result, 'easy_wechat_mp_weixin_get_unlimited_qrcode_to_server_uid_' . $this->mid);
// 定义小程序码object
$oss_file_dirname = 'mpweixinunlimitedcode/' . date("Ymd");
// 将本地小程序码上传到OSS
$result = $oss_class->uploadFile($result, $oss_file_dirname);
return $result['url'];
}
}