Ver código fonte

拉卡拉调试

shizhongqi 1 mês atrás
pai
commit
f1e3ec543d

+ 3 - 2
app-ghs/controllers/LakalaAccountController.php

@@ -128,9 +128,10 @@ class LakalaAccountController extends BaseController
     {
         $form = new FormDataForm();
         $form->loadAndValidate();
+        util::complete();
 
-        $submit = LakalaAccountService::submit((int)$form->id, $this->mainId, $this->shopId, $form->getFormData());
-        util::success($submit);
+        // $submit = LakalaAccountService::submit((int)$form->id, $this->mainId, $this->shopId, $form->getFormData());
+        // util::success($submit);
     }
 
     public function actionRefresh()

+ 15 - 0
biz-ghs/lakala/services/LakalaAccountService.php

@@ -113,6 +113,21 @@ class LakalaAccountService
         }
         $object = 'lakala-onboarding/' . $mainId . '/' . date('Ymd') . '/' . $id . '/' . stringUtil::uniqueFileName() . '.jpg';
         oss::uploadContent($object, $content);
+
+        $info = getimagesizefromstring($content);
+        $allowMime = [
+            'image/jpeg',
+            'image/png',
+            'image/gif',
+            'image/webp'
+        ];
+        if (in_array($info['mime'], $allowMime)) {
+            Yii::info('允许上传 -- ' . $info['mime']);
+        } else {
+            Yii::error('不允许上传');
+            util::fail('图片出错,不允许上传');
+        }
+
         $response = (new LakalaOnboardingClient())->upload($base64, $imgType, (bool)$ocr);
         return [
             'ossPath' => $object,

+ 11 - 1
common/components/lakala/LakalaOnboardingClient.php

@@ -90,7 +90,7 @@ class LakalaOnboardingClient
                 'raw' => $raw,
             ];
         } catch (\Throwable $e) {
-            Yii::error('Lakala onboarding ' . $path . ': ' . $e->getResponseHeaders() . $e->getMessage()); // . $e->getResponseHeaders()
+            Yii::error('Lakala onboarding ' . $path . ': ' . $e->getMessage()); // . $e->getResponseHeaders()
             throw new \RuntimeException('拉卡拉接口请求失败:' . $e->getMessage());
         }
     }
@@ -98,6 +98,14 @@ class LakalaOnboardingClient
     public function upload($base64, $imgType, $ocr = false)
     {
         $base = $base64;
+        $data = [
+            'file_base64' => $base,
+            'img_type' => $imgType,
+            //'prefix' => 'reg',
+            'sourcechnl' => 0,
+            'is_ocr' => $ocr ? 'true' : 'false',
+        ];
+        Yii::info(json_encode($data));
         return $this->call('/api/v3/tkbs/customer/file/upload', [
             'file_base64' => $base,
             'img_type' => $imgType,
@@ -109,6 +117,8 @@ class LakalaOnboardingClient
 
     public function ocr($batchNo, $imgType)
     {
+        $data = ['batch_no' => $batchNo, 'img_type' => $imgType];
+        Yii::info(json_encode($data));
         return $this->call('/api/v3/tkbs/ocr_result', ['batch_no' => $batchNo, 'img_type' => $imgType]);
     }