调试图片上传和识别
This commit is contained in:
parent
f9d969c85c
commit
e6e0eaadab
@ -11,6 +11,12 @@ use app\admin\validate\store_product\StoreProductValidate;
|
|||||||
use app\common\model\store_branch_product\StoreBranchProduct;
|
use app\common\model\store_branch_product\StoreBranchProduct;
|
||||||
use app\common\model\store_product\StoreProduct;
|
use app\common\model\store_product\StoreProduct;
|
||||||
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
use app\common\model\warehouse_product_storege\WarehouseProductStorege;
|
||||||
|
use TencentCloud\Common\Credential;
|
||||||
|
use TencentCloud\Common\Profile\ClientProfile;
|
||||||
|
use TencentCloud\Common\Profile\HttpProfile;
|
||||||
|
use TencentCloud\Tiia\V20190529\Models\CreateImageRequest;
|
||||||
|
use TencentCloud\Tiia\V20190529\Models\SearchImageRequest;
|
||||||
|
use TencentCloud\Tiia\V20190529\TiiaClient;
|
||||||
use Webman\RedisQueue\Redis;
|
use Webman\RedisQueue\Redis;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,6 +27,7 @@ use Webman\RedisQueue\Redis;
|
|||||||
class StoreProductController extends BaseAdminController
|
class StoreProductController extends BaseAdminController
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public $notNeedLogin = ['upload', 'recognition'];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @notes 获取商品列表列表
|
* @notes 获取商品列表列表
|
||||||
@ -151,4 +158,49 @@ class StoreProductController extends BaseAdminController
|
|||||||
return $this->success('删除成功', [], 1, 1);
|
return $this->success('删除成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function upload()
|
||||||
|
{
|
||||||
|
$file = $this->request->file('file');
|
||||||
|
$cred = new Credential(getenv('TENCENT_SECRET_ID'), getenv('TENCENT_SECRET_KEY'));
|
||||||
|
$httpProfile = new HttpProfile();
|
||||||
|
$httpProfile->setEndpoint("tiia.tencentcloudapi.com");
|
||||||
|
$clientProfile = new ClientProfile();
|
||||||
|
$clientProfile->setHttpProfile($httpProfile);
|
||||||
|
$client = new TiiaClient($cred, "ap-guangzhou", $clientProfile);
|
||||||
|
$req = new CreateImageRequest();
|
||||||
|
$file = file_get_contents(public_path() . '/可口可乐.jpg');
|
||||||
|
$params = [
|
||||||
|
'GroupId' => 'default',
|
||||||
|
'EntityId' => '可口可乐_330ml_听装',
|
||||||
|
'PicName' => '可口可乐.jpg',
|
||||||
|
'ImageBase64' => base64_encode($file)
|
||||||
|
];
|
||||||
|
$req->fromJsonString(json_encode($params));
|
||||||
|
$resp = $client->CreateImage($req);
|
||||||
|
$result = json_decode($resp->toJsonString(), true);
|
||||||
|
return $this->data($result);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function recognition()
|
||||||
|
{
|
||||||
|
$cred = new Credential(getenv('TENCENT_SECRET_ID'), getenv('TENCENT_SECRET_KEY'));
|
||||||
|
$httpProfile = new HttpProfile();
|
||||||
|
$httpProfile->setEndpoint("tiia.tencentcloudapi.com");
|
||||||
|
$clientProfile = new ClientProfile();
|
||||||
|
$clientProfile->setHttpProfile($httpProfile);
|
||||||
|
$client = new TiiaClient($cred, "ap-guangzhou", $clientProfile);
|
||||||
|
$req = new SearchImageRequest();
|
||||||
|
$file = file_get_contents(public_path() . '/可口可乐.jpg');
|
||||||
|
// $file = file_get_contents(public_path() . '/可口可乐2.jpg');
|
||||||
|
// $file = file_get_contents(public_path() . '/百事可乐.jpg');
|
||||||
|
$params = [
|
||||||
|
'GroupId' => 'default',
|
||||||
|
'ImageBase64' => base64_encode($file)
|
||||||
|
];
|
||||||
|
$req->fromJsonString(json_encode($params));
|
||||||
|
$resp = $client->SearchImage($req);
|
||||||
|
$result = json_decode($resp->toJsonString(), true);
|
||||||
|
return $this->data($result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,4 +24,9 @@ class StoreProductPrice extends BaseModel
|
|||||||
// 不生成该表的日志
|
// 不生成该表的日志
|
||||||
public $doNotRecordLog = true;
|
public $doNotRecordLog = true;
|
||||||
|
|
||||||
|
public function product()
|
||||||
|
{
|
||||||
|
return $this->hasOne(StoreProduct::class, 'id', 'product_id')->field('id,store_name,top_cate_id,two_cate_id,cate_id');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user