|
@@ -284,51 +284,8 @@ class CommonServer
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- * 图片上传OSS
|
|
|
- * @param $img
|
|
|
- * @param string $path
|
|
|
- * @param $is_compress
|
|
|
- * @return string
|
|
|
- */
|
|
|
- function uploadingImg($img, $path = 'headimgurl',$is_compress=true)
|
|
|
- {
|
|
|
- $base64_image_content = file_get_contents($img);
|
|
|
- $upload_path = "storage" . DIRECTORY_SEPARATOR . $path . DIRECTORY_SEPARATOR . date('Ymd', time()) . DIRECTORY_SEPARATOR;
|
|
|
- $img_url = md5(uniqid() . time()) . '.png';
|
|
|
- $upload_path1 = public_path($upload_path);
|
|
|
- if (!is_dir($upload_path1)) {
|
|
|
- mkdir($upload_path1, 0777, true);
|
|
|
- }
|
|
|
- $oss = Storage::disk('oss');
|
|
|
- $pathA = "{$upload_path}{$img_url}";
|
|
|
- $update = $oss->put($pathA, $base64_image_content);
|
|
|
- if (!$update) {
|
|
|
- file_put_contents($upload_path1 . $img_url, base64_decode($base64_image_content));
|
|
|
- }
|
|
|
- return $update ? ($oss->url($pathA) . ($is_compress?'?x-oss-process=image/auto-orient,1/quality,q_85':'')) : asset($pathA);
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- * OSS图片压缩
|
|
|
- * @param $img
|
|
|
- * @param int $resize (3,10,30,50)
|
|
|
- * @param int $type 1原比例压缩,2固定高宽比列压缩(300*300)
|
|
|
- * @return string|string[]
|
|
|
- */
|
|
|
- function ossCompress($img, $resize = 10, $type = 1)
|
|
|
- {
|
|
|
- $old_str=strrchr($img, '?');
|
|
|
- if($old_str)$img=str_replace($old_str, '', $img);
|
|
|
- if ($type == 1) {
|
|
|
- return $img . '?x-oss-process=image/auto-orient,1/resize,p_' . $resize . '/quality,q_90';
|
|
|
- } elseif ($type == 2) {
|
|
|
- return $img . '?x-oss-process=image/auto-orient,1/resize,m_fill,w_300,h_300/quality,q_90';
|
|
|
- } elseif ($type == 3) {
|
|
|
- return $img . '?x-oss-process=image/auto-orient,1/resize,m_lfit,w_780/quality,q_100';
|
|
|
- }
|
|
|
- return $img;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
* 保留2为小数
|
|
@@ -356,165 +313,10 @@ class CommonServer
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
- * oss图片删除
|
|
|
- * @param $path
|
|
|
- * @return bool
|
|
|
- */
|
|
|
- function delImg($path)
|
|
|
- {
|
|
|
- $path_num = stripos($path, '?');
|
|
|
- if ($path_num !== false) {
|
|
|
- $path = substr($path, 0, $path_num);
|
|
|
- }
|
|
|
- $path = str_replace('https://jhnewshop.oss-cn-chengdu.aliyuncs.com', '', $path);
|
|
|
- $oss = Storage::disk('oss');
|
|
|
- $update = $oss->delete($path);
|
|
|
- return $update;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- * 获取阿里云sts临时权限
|
|
|
- */
|
|
|
- function getAliSts()
|
|
|
- {
|
|
|
- $data = RedisDataServer::creatServer()->getData('sts_data');
|
|
|
- if ($data) {
|
|
|
- $data = json_decode($data, true);
|
|
|
- } else {
|
|
|
- $accessKeyId = env('ALI_OSS_ACCESS_ID');
|
|
|
- $accessSecret = env('ALI_OSS_ACCESS_KEY');
|
|
|
- AlibabaCloud::accessKeyClient($accessKeyId, $accessSecret)->regionId('cn-hangzhou')->asDefaultClient();
|
|
|
-
|
|
|
- try {
|
|
|
- $result = AlibabaCloud::rpc()
|
|
|
- ->product('Sts')
|
|
|
- ->scheme('https')
|
|
|
- ->version('2015-04-01')
|
|
|
- ->action('AssumeRole')
|
|
|
- ->method('POST')
|
|
|
- ->host('sts.aliyuncs.com')
|
|
|
- ->options([
|
|
|
- 'query' => [
|
|
|
- 'RegionId' => "cn-chengdu",
|
|
|
- 'RoleArn' => "acs:ram::1470797691368660:role/oss-js",
|
|
|
- 'RoleSessionName' => "js-oss-serve",
|
|
|
- 'DurationSeconds' => 900,
|
|
|
- ],
|
|
|
- ])
|
|
|
- ->request();
|
|
|
- $result = $result->toArray();
|
|
|
- if (empty($result['Credentials'])) {
|
|
|
- return ['code' => 0, 'msg' => '获取token信息失败'];
|
|
|
- }
|
|
|
- $data = $result['Credentials'];
|
|
|
- unset($data['Expiration']);
|
|
|
- RedisDataServer::creatServer()->setData('sts_data', $data, 'json', 800);
|
|
|
- } catch (ClientException $e) {
|
|
|
- return ['code' => 0, 'msg' => $e->getErrorMessage()];
|
|
|
- } catch (ServerException $e) {
|
|
|
- return ['code' => 0, 'msg' => $e->getErrorMessage()];
|
|
|
- }
|
|
|
- }
|
|
|
- return ['code' => 1, 'msg' => '获取信息成功', 'data' => $data];
|
|
|
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- * 阿里云图片鉴定
|
|
|
- * @param $imges
|
|
|
- * @return array|bool
|
|
|
- * @throws ClientException
|
|
|
- * @throws ServerException
|
|
|
- */
|
|
|
- function sendAliImgAuth($imges)
|
|
|
- {
|
|
|
- if (is_string($imges)) $imges = [$imges];
|
|
|
- $tasks = [];
|
|
|
- $auth_status = 1;
|
|
|
- foreach ($imges as $key => $img) {
|
|
|
- $tasks[] = [
|
|
|
- 'dataId' => $key . '-img' . rand(10000000, 99999999) . '-' . time(),
|
|
|
- 'url' => $img,
|
|
|
- 'status' => 0,
|
|
|
- ];
|
|
|
- }
|
|
|
- $accessKeyId = env('ALI_OSS_ACCESS_ID');
|
|
|
- $accessSecret = env('ALI_OSS_ACCESS_KEY');
|
|
|
- AlibabaCloud::accessKeyClient($accessKeyId, $accessSecret)->regionId('cn-shanghai')->asDefaultClient();
|
|
|
- $request = Green::v20180509()->ImageSyncScan();
|
|
|
- $request->method('POST')
|
|
|
- ->scheme('https')
|
|
|
- ->body(json_encode([
|
|
|
- 'scenes' => ['porn', 'terrorism'],
|
|
|
- 'tasks' => $tasks,
|
|
|
- ]));
|
|
|
- $ret = $request->request();
|
|
|
- $ret_data = $ret->toArray();
|
|
|
- if (empty($ret_data['code']) || $ret_data['code'] != 200) {
|
|
|
- return $auth_status;
|
|
|
- } else {
|
|
|
- foreach ($ret_data['data'] as $key => $item) {
|
|
|
- $status = 1;
|
|
|
- if ($auth_status != 1) {
|
|
|
- break;
|
|
|
- }
|
|
|
- foreach ($item['results'] as $value) {
|
|
|
- if ($value['suggestion'] == 'review') {
|
|
|
- $status = 0;
|
|
|
- $auth_status = 0;
|
|
|
- break;
|
|
|
- } elseif ($value['suggestion'] == 'block') {
|
|
|
- $status = 2;
|
|
|
- $auth_status = 2;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- $tasks[$key]['status'] = $status;
|
|
|
- }
|
|
|
- }
|
|
|
- return ['auth_status' => $auth_status, 'tasks' => $tasks];
|
|
|
|
|
|
- }
|
|
|
|
|
|
-
|
|
|
- * 阿里云视频鉴定
|
|
|
- * @param $video 视频地址
|
|
|
- * @param int $type 鉴定类型
|
|
|
- * @param int $id 任务ID
|
|
|
- * @return bool
|
|
|
- * @throws ClientException
|
|
|
- * @throws ServerException
|
|
|
- */
|
|
|
- function sendAliVideoAuth($video, $type = 1, $id = 0)
|
|
|
- {
|
|
|
- $tasks = [
|
|
|
- [
|
|
|
- 'dataId' => $id . '-video' . rand(10000000, 99999999) . '-' . time(),
|
|
|
- 'url' => $video,
|
|
|
- 'interval' => 5,
|
|
|
- ]
|
|
|
- ];
|
|
|
- $accessKeyId = env('ALI_OSS_ACCESS_ID');
|
|
|
- $accessSecret = env('ALI_OSS_ACCESS_KEY');
|
|
|
- AlibabaCloud::accessKeyClient($accessKeyId, $accessSecret)->regionId('cn-shanghai')->asDefaultClient();
|
|
|
- $request = Green::v20180509()->videoAsyncScan();
|
|
|
- $request->method('POST')
|
|
|
- ->scheme('https')
|
|
|
- ->body(json_encode([
|
|
|
- 'callback' => route('notify.video-auth', ['type' => $type, 'id' => $id]),
|
|
|
- 'seed' => $id . '-video' . rand(10000000, 99999999),
|
|
|
- 'scenes' => ['porn', 'terrorism'],
|
|
|
- 'tasks' => $tasks,
|
|
|
- ]));
|
|
|
- $ret = $request->request();
|
|
|
- $ret_data = $ret->toArray();
|
|
|
- if (empty($ret_data['code']) || $ret_data['code'] != 200) {
|
|
|
- ErrorRecord::create(['msg' => '视频鉴定任务提交失败', 'data' => json_encode(compact('id', 'type', 'video'))]);
|
|
|
- return false;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
|
|
|
|
|
|
* 获取文件名
|
|
@@ -528,4 +330,61 @@ class CommonServer
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+ * 身份证号码验证
|
|
|
+ * @param $id
|
|
|
+ * @return bool
|
|
|
+ */
|
|
|
+ public static function isIdcard($id)
|
|
|
+ {
|
|
|
+ $id = strtoupper($id);
|
|
|
+ $regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
|
|
|
+ $arr_split = array();
|
|
|
+ if (!preg_match($regx, $id)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ if (15 == strlen($id))
|
|
|
+ {
|
|
|
+ $regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";
|
|
|
+
|
|
|
+ @preg_match($regx, $id, $arr_split);
|
|
|
+
|
|
|
+ $dtm_birth = "19" . $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
|
|
|
+ if (!strtotime($dtm_birth)) {
|
|
|
+ return FALSE;
|
|
|
+ } else {
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+ } else
|
|
|
+ {
|
|
|
+ $regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
|
|
|
+ @preg_match($regx, $id, $arr_split);
|
|
|
+ $dtm_birth = $arr_split[2] . '/' . $arr_split[3] . '/' . $arr_split[4];
|
|
|
+ if (!strtotime($dtm_birth))
|
|
|
+ {
|
|
|
+ return FALSE;
|
|
|
+ } else {
|
|
|
+
|
|
|
+
|
|
|
+ $arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
|
|
|
+ $arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
|
|
|
+ $sign = 0;
|
|
|
+ for ($i = 0; $i < 17; $i++) {
|
|
|
+ $b = (int)$id[$i];
|
|
|
+ $w = $arr_int[$i];
|
|
|
+ $sign += $b * $w;
|
|
|
+ }
|
|
|
+ $n = $sign % 11;
|
|
|
+ $val_num = $arr_ch[$n];
|
|
|
+ if ($val_num != substr($id, 17, 1)) {
|
|
|
+ return FALSE;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|