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.
123 lines
3.8 KiB
123 lines
3.8 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
|
|
namespace app\admin\model\wechat;
|
|
|
|
|
|
use traits\ModelTrait;
|
|
use basic\ModelBasic;
|
|
use service\WechatService;
|
|
|
|
/**
|
|
* 获取二维码
|
|
* Class WechatQrcode
|
|
* @package app\admin\model\wechat
|
|
*/
|
|
class WechatQrcode extends ModelBasic
|
|
{
|
|
use ModelTrait;
|
|
|
|
const times = 2592000;
|
|
|
|
/**
|
|
* 创建临时二维码 有效期 30天
|
|
*
|
|
* 修改时 要使用的主键id $qtcode_id
|
|
* @param $id
|
|
* @param $type
|
|
* @param string $qtcode_id
|
|
*/
|
|
public static function createTemporaryQrcode($id, $type, $qtcode_id = '')
|
|
{
|
|
$qrcode = WechatService::qrcodeService();
|
|
$data = $qrcode->temporary($id, self::times)->toArray();
|
|
$data['qrcode_url'] = $data['url'];
|
|
$data['expire_seconds'] = $data['expire_seconds'] + time();
|
|
$data['url'] = $qrcode->url($data['ticket']);
|
|
$data['status'] = 1;
|
|
$data['third_id'] = $id;
|
|
$data['third_type'] = $type;
|
|
if ($qtcode_id) {
|
|
self::edit($data, $qtcode_id);
|
|
} else {
|
|
$data['add_time'] = time();
|
|
self::set($data);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 创建永久二维码
|
|
* @param $id
|
|
* @param $type
|
|
*/
|
|
public static function createForeverQrcode($id, $type)
|
|
{
|
|
$qrcode = WechatService::qrcodeService();
|
|
$data = $qrcode->forever($id)->toArray();
|
|
$data['qrcode_url'] = $data['url'];
|
|
$data['url'] = $qrcode->url($data['ticket']);
|
|
$data['expire_seconds'] = 0;
|
|
$data['status'] = 1;
|
|
$data['third_id'] = $id;
|
|
$data['third_type'] = $type;
|
|
$data['add_time'] = time();
|
|
self::set($data);
|
|
}
|
|
|
|
/**
|
|
* 获取临时二维码
|
|
* @param $type
|
|
* @param $id
|
|
* @return array|false|\PDOStatement|string|\think\Model
|
|
*/
|
|
public static function getTemporaryQrcode($type, $id)
|
|
{
|
|
$res = self::where('third_id', $id)->where('third_type', $type)->find();
|
|
if (empty($res)) {
|
|
self::createTemporaryQrcode($id, $type);
|
|
$res = self::getTemporaryQrcode($type, $id);
|
|
} else if (empty($res['expire_seconds']) || $res['expire_seconds'] < time()) {
|
|
self::createTemporaryQrcode($id, $type, $res['id']);
|
|
$res = self::getTemporaryQrcode($type, $id);
|
|
}
|
|
if (!$res['ticket']) exception('临时二维码获取错误');
|
|
return $res;
|
|
}
|
|
|
|
/**
|
|
* 获取永久二维码
|
|
* @param $type
|
|
* @param $id
|
|
* @return array|false|\PDOStatement|string|\think\Model
|
|
*/
|
|
public static function getForeverQrcode($type, $id)
|
|
{
|
|
$res = self::where('third_id', $id)->where('third_type', $type)->find();
|
|
if (empty($res)) {
|
|
self::createForeverQrcode($id, $type);
|
|
$res = self::getForeverQrcode($type, $id);
|
|
}
|
|
if (!$res['ticket']) exception('临时二维码获取错误');
|
|
return $res;
|
|
}
|
|
|
|
public static function getQrcode($id, $type = 'id')
|
|
{
|
|
return self::where($type, $id)->find();
|
|
}
|
|
|
|
public static function scanQrcode($id, $type = 'id')
|
|
{
|
|
return self::where($type, $id)->setInc('scan');
|
|
}
|
|
|
|
}
|
|
|