-
Notifications
You must be signed in to change notification settings - Fork 0
/
tt.php
85 lines (76 loc) · 2.33 KB
/
tt.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* User: cos800
* Date: 2018/4/9
* Time: 下午5:57
*/
class tt
{
static function ff() {
echo 'ffff';
}
static function up($path, $width=FALSE, $height=FALSE, $type=3) {
// 外链直接输出
if (!$path or !strncasecmp('http://', $path, 7)) {
return $path;
}
// 多图 处理第一张图片
if ($tmp = strpos($path, ',')) {
$path = substr($path, 0, $tmp);
}
if ($path{0}==='/') {
$uploadPath = '.';
$uploadUrl = '';
}else{
$uploadPath = config('app.upload.root_path');
$uploadUrl = config('app.upload.base_url');
}
if ($width and $height) {
// 缩略图路径
$newPath = substr_replace($path, "_{$width}x{$height}", strrpos($path,'.'), 0);
$newRealPath = $uploadPath.$newPath; // 缩略图完整路径
$realPath = $uploadPath.$path; // 原图完成路径
// 不存在则生成缩略图
if (!is_file($newRealPath) and is_file($realPath)) {
// $Img = new Think\Image();
// $Img->open($realPath);
$Img = \think\Image::open($realPath);
try{
$Img->thumb($width, $height, $type);
$Img->save($newRealPath);
} catch (Exception $e) {
// echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
return $uploadUrl.$newPath;
}
return $uploadUrl.$path; // 返回原图URL
}
static function wxmp($appid='', $secret='') {
if (empty($appid) and empty($secret)) {
$appid = config('app.wxmp.appid');
$secret = config('app.wxmp.secret');
}
$wxmp = new \tt\Weixin($appid, $secret);
return $wxmp;
}
static function json($arr) {
header('Content-type: application/json');
echo json_encode($arr, JSON_UNESCAPED_UNICODE);
exit;
}
static function success($data=[], $msg='') {
static::json([
'ok' => 1,
'msg' => $msg,
'data' => $data,
]);
}
static function error($msg='', $data=[]) {
static::json([
'ok' => 0,
'msg' => $msg,
'data' => $data,
]);
}
}