Commit ee619c36 ee619c36c14bee99fba1b97757e568fbbfba508e by lemon

分享链接和验证

1 parent ed51d0e3
......@@ -48,3 +48,50 @@ if (!function_exists('coverData')) {
return join(' ', $rs);
}
}
if (!function_exists('crc64Table')) {
/**
* @return array
*/
function crc64Table() {
$crc64tab = array();
// ECMA polynomial
$poly64rev = (0xC96C5795 << 32) | 0xD7870F42;
// ISO polynomial
// $poly64rev = (0xD8 << 56);
for ($i = 0; $i < 256; $i++)
{
for ($part = $i, $bit = 0; $bit < 8; $bit++) {
if ($part & 1) {
$part = (($part >> 1) & ~(0x8 << 60)) ^ $poly64rev;
} else {
$part = ($part >> 1) & ~(0x8 << 60);
}
}
$crc64tab[$i] = $part;
}
return $crc64tab;
}
}
if (!function_exists('crc64')) {
/**
* @param $string
* @param $format
* @return string
*/
function crc64($string, $format = '%x'){
static $crc64tab;
if ($crc64tab === null) {
$crc64tab = crc64Table();
}
$crc = 0;
for ($i = 0; $i < strlen($string); $i++) {
$crc = ~$crc;
$crc = $crc64tab[($crc ^ ord($string[$i])) & 0xff] ^ (($crc >> 8) & ~(0xff << 56));
$crc = ~$crc;
}
return sprintf($format, $crc);
}
}
......
<?php
namespace App\Models\Legal;
use App\Models\BaseModel;
/**
* Class PropertyShare
* @package App\Models\Legal
*/
class PropertyShare extends BaseModel
{
protected $updated_at = false;
protected $guarded = [];
}
......@@ -5,6 +5,7 @@ namespace App\Services;
use App\Helper\CosHelper;
use App\Helper\Response;
use App\Models\Legal\Contract;
use App\Models\Legal\PropertyShare;
use App\Models\Legal\PropertyShareVerification;
use App\Models\Legal\PropertyTrack;
use App\Models\Legal\PropertyTrackFile;
......@@ -12,6 +13,7 @@ use App\Models\Legal\StakeholderContract;
use App\Models\Legal\Treaty;
use App\Models\Musician\AppCompany;
use App\Models\Musician\AppCompanyUser;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Http\Request;
use Qcloud\Cos\Client;
......@@ -97,7 +99,7 @@ class PropertyTrackService extends Service
'expire_time' => '',
];
if ($share = PropertyShareVerification::query()->where(['pf_id'=>$this->request->input('pf_id')])->orderByDesc('id')->first()) {
if ($share = PropertyShare::query()->where(['pf_id'=>$this->request->input('pf_id')])->orderByDesc('id')->first()) {
$data['phone'] = $share->phone;
$data['share_url'] = $share->share_url;
$data['expire_time']= $share->expire_time;
......@@ -105,4 +107,42 @@ class PropertyTrackService extends Service
return Response::success($data);
}
/**
* 生成链接
* @return \Illuminate\Http\JsonResponse
*/
public function shareCreate()
{
$propertyConfig = config('musician.property');
$share = $propertyConfig['base_url'].uniqid();
$share_url_hash = crc64($share);
$expire_time = time() + $propertyConfig['token_valid'];
if (PropertyShare::query()->insertGetId([
'pf_id' => $this->request->input('track_id'),
'phone' => $this->request->input('phone'),
'share_url' => $share,
'share_url_hash'=> $share_url_hash,
'expire_time' => date('Y-m-d H:i:s', $expire_time),
'from' => $this->request->input('from'),
'create_admin' => $this->request->input('user_id'), //用户
'created_at' => $this->now,
])) {
return Response::success(['url'=>$share]);
} else {
return Response::error();
}
}
/**
* 验证分享登录有效期
* @return \Illuminate\Http\JsonResponse
*/
public function shareCheck()
{
return Response::success();
}
}
......
......@@ -7,6 +7,8 @@ return [
],
'property'=>[
'valid_day'=>env('PROPERTY_SHARE_DAY', 3),
'base_url' => env('PROPERTY_SHARE_URL', 'https://musician-test.hikoon.com/#/share/'),
'valid_day' => env('PROPERTY_SHARE_DAY', 3),
'token_valid'=> env('PROPERTY_SHARE_TOKEN', 86400),
],
];
......
......@@ -22,10 +22,12 @@ Route::group(["prefix"=>"property", "middleware"=>['auth.identifier']], function
Route::group(["prefix"=>"property"], function (){
Route::get('/track/share', 'PropertyTrackController@share');
Route::post('/track/shareCreate', 'PropertyTrackController@shareCreate');
});
//资产-分享链接
Route::group(["prefix"=>"property", "middleware"=>['auth.share']], function (){
Route::get('/track/shareCheck', 'PropertyTrackController@shareCheck');
});
......