分享链接和验证
Showing
5 changed files
with
108 additions
and
2 deletions
... | @@ -48,3 +48,50 @@ if (!function_exists('coverData')) { | ... | @@ -48,3 +48,50 @@ if (!function_exists('coverData')) { |
48 | return join(' ', $rs); | 48 | return join(' ', $rs); |
49 | } | 49 | } |
50 | } | 50 | } |
51 | |||
52 | if (!function_exists('crc64Table')) { | ||
53 | /** | ||
54 | * @return array | ||
55 | */ | ||
56 | function crc64Table() { | ||
57 | $crc64tab = array(); | ||
58 | // ECMA polynomial | ||
59 | $poly64rev = (0xC96C5795 << 32) | 0xD7870F42; | ||
60 | // ISO polynomial | ||
61 | // $poly64rev = (0xD8 << 56); | ||
62 | for ($i = 0; $i < 256; $i++) | ||
63 | { | ||
64 | for ($part = $i, $bit = 0; $bit < 8; $bit++) { | ||
65 | if ($part & 1) { | ||
66 | $part = (($part >> 1) & ~(0x8 << 60)) ^ $poly64rev; | ||
67 | } else { | ||
68 | $part = ($part >> 1) & ~(0x8 << 60); | ||
69 | } | ||
70 | } | ||
71 | $crc64tab[$i] = $part; | ||
72 | } | ||
73 | return $crc64tab; | ||
74 | } | ||
75 | } | ||
76 | |||
77 | if (!function_exists('crc64')) { | ||
78 | /** | ||
79 | * @param $string | ||
80 | * @param $format | ||
81 | * @return string | ||
82 | */ | ||
83 | function crc64($string, $format = '%x'){ | ||
84 | static $crc64tab; | ||
85 | if ($crc64tab === null) { | ||
86 | $crc64tab = crc64Table(); | ||
87 | } | ||
88 | |||
89 | $crc = 0; | ||
90 | for ($i = 0; $i < strlen($string); $i++) { | ||
91 | $crc = ~$crc; | ||
92 | $crc = $crc64tab[($crc ^ ord($string[$i])) & 0xff] ^ (($crc >> 8) & ~(0xff << 56)); | ||
93 | $crc = ~$crc; | ||
94 | } | ||
95 | return sprintf($format, $crc); | ||
96 | } | ||
97 | } | ... | ... |
app/Models/Legal/PropertyShare.php
0 → 100644
... | @@ -5,6 +5,7 @@ namespace App\Services; | ... | @@ -5,6 +5,7 @@ namespace App\Services; |
5 | use App\Helper\CosHelper; | 5 | use App\Helper\CosHelper; |
6 | use App\Helper\Response; | 6 | use App\Helper\Response; |
7 | use App\Models\Legal\Contract; | 7 | use App\Models\Legal\Contract; |
8 | use App\Models\Legal\PropertyShare; | ||
8 | use App\Models\Legal\PropertyShareVerification; | 9 | use App\Models\Legal\PropertyShareVerification; |
9 | use App\Models\Legal\PropertyTrack; | 10 | use App\Models\Legal\PropertyTrack; |
10 | use App\Models\Legal\PropertyTrackFile; | 11 | use App\Models\Legal\PropertyTrackFile; |
... | @@ -12,6 +13,7 @@ use App\Models\Legal\StakeholderContract; | ... | @@ -12,6 +13,7 @@ use App\Models\Legal\StakeholderContract; |
12 | use App\Models\Legal\Treaty; | 13 | use App\Models\Legal\Treaty; |
13 | use App\Models\Musician\AppCompany; | 14 | use App\Models\Musician\AppCompany; |
14 | use App\Models\Musician\AppCompanyUser; | 15 | use App\Models\Musician\AppCompanyUser; |
16 | use Carbon\Carbon; | ||
15 | use Illuminate\Database\Eloquent\Builder; | 17 | use Illuminate\Database\Eloquent\Builder; |
16 | use Illuminate\Http\Request; | 18 | use Illuminate\Http\Request; |
17 | use Qcloud\Cos\Client; | 19 | use Qcloud\Cos\Client; |
... | @@ -97,7 +99,7 @@ class PropertyTrackService extends Service | ... | @@ -97,7 +99,7 @@ class PropertyTrackService extends Service |
97 | 'expire_time' => '', | 99 | 'expire_time' => '', |
98 | ]; | 100 | ]; |
99 | 101 | ||
100 | if ($share = PropertyShareVerification::query()->where(['pf_id'=>$this->request->input('pf_id')])->orderByDesc('id')->first()) { | 102 | if ($share = PropertyShare::query()->where(['pf_id'=>$this->request->input('pf_id')])->orderByDesc('id')->first()) { |
101 | $data['phone'] = $share->phone; | 103 | $data['phone'] = $share->phone; |
102 | $data['share_url'] = $share->share_url; | 104 | $data['share_url'] = $share->share_url; |
103 | $data['expire_time']= $share->expire_time; | 105 | $data['expire_time']= $share->expire_time; |
... | @@ -105,4 +107,42 @@ class PropertyTrackService extends Service | ... | @@ -105,4 +107,42 @@ class PropertyTrackService extends Service |
105 | 107 | ||
106 | return Response::success($data); | 108 | return Response::success($data); |
107 | } | 109 | } |
110 | |||
111 | /** | ||
112 | * 生成链接 | ||
113 | * @return \Illuminate\Http\JsonResponse | ||
114 | */ | ||
115 | public function shareCreate() | ||
116 | { | ||
117 | $propertyConfig = config('musician.property'); | ||
118 | $share = $propertyConfig['base_url'].uniqid(); | ||
119 | $share_url_hash = crc64($share); | ||
120 | $expire_time = time() + $propertyConfig['token_valid']; | ||
121 | |||
122 | if (PropertyShare::query()->insertGetId([ | ||
123 | 'pf_id' => $this->request->input('track_id'), | ||
124 | 'phone' => $this->request->input('phone'), | ||
125 | 'share_url' => $share, | ||
126 | 'share_url_hash'=> $share_url_hash, | ||
127 | 'expire_time' => date('Y-m-d H:i:s', $expire_time), | ||
128 | 'from' => $this->request->input('from'), | ||
129 | 'create_admin' => $this->request->input('user_id'), //用户 | ||
130 | 'created_at' => $this->now, | ||
131 | ])) { | ||
132 | return Response::success(['url'=>$share]); | ||
133 | } else { | ||
134 | return Response::error(); | ||
135 | } | ||
136 | } | ||
137 | |||
138 | /** | ||
139 | * 验证分享登录有效期 | ||
140 | * @return \Illuminate\Http\JsonResponse | ||
141 | */ | ||
142 | public function shareCheck() | ||
143 | { | ||
144 | |||
145 | |||
146 | return Response::success(); | ||
147 | } | ||
108 | } | 148 | } | ... | ... |
... | @@ -7,6 +7,8 @@ return [ | ... | @@ -7,6 +7,8 @@ return [ |
7 | ], | 7 | ], |
8 | 8 | ||
9 | 'property'=>[ | 9 | 'property'=>[ |
10 | 'valid_day'=>env('PROPERTY_SHARE_DAY', 3), | 10 | 'base_url' => env('PROPERTY_SHARE_URL', 'https://musician-test.hikoon.com/#/share/'), |
11 | 'valid_day' => env('PROPERTY_SHARE_DAY', 3), | ||
12 | 'token_valid'=> env('PROPERTY_SHARE_TOKEN', 86400), | ||
11 | ], | 13 | ], |
12 | ]; | 14 | ]; | ... | ... |
... | @@ -22,10 +22,12 @@ Route::group(["prefix"=>"property", "middleware"=>['auth.identifier']], function | ... | @@ -22,10 +22,12 @@ Route::group(["prefix"=>"property", "middleware"=>['auth.identifier']], function |
22 | 22 | ||
23 | Route::group(["prefix"=>"property"], function (){ | 23 | Route::group(["prefix"=>"property"], function (){ |
24 | Route::get('/track/share', 'PropertyTrackController@share'); | 24 | Route::get('/track/share', 'PropertyTrackController@share'); |
25 | Route::post('/track/shareCreate', 'PropertyTrackController@shareCreate'); | ||
25 | }); | 26 | }); |
26 | 27 | ||
27 | //资产-分享链接 | 28 | //资产-分享链接 |
28 | Route::group(["prefix"=>"property", "middleware"=>['auth.share']], function (){ | 29 | Route::group(["prefix"=>"property", "middleware"=>['auth.share']], function (){ |
30 | Route::get('/track/shareCheck', 'PropertyTrackController@shareCheck'); | ||
29 | 31 | ||
30 | }); | 32 | }); |
31 | 33 | ... | ... |
-
Please register or sign in to post a comment