AlihealthService.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Services;
  3. use AlibabaAlihealthSynergyYzwQuerysealdrugreportRequest;
  4. use TopClient;
  5. class AlihealthService
  6. {
  7. private $client;
  8. private $config;
  9. public function __construct()
  10. {
  11. $this->config = config('taobao');
  12. $this->client = new TopClient;
  13. $this->client->appkey = $this->config['app_key'];
  14. $this->client->secretKey = $this->config['secret_key'];
  15. $this->client->format = "json";
  16. }
  17. /**
  18. * 查询上传报告信息接口(@link https://open.taobao.com/api.htm?docId=70145&docType=2&scopeId=30361)
  19. * @param string $beginTime
  20. * @param string $endTime
  21. * @param int $page
  22. * @param int $pageSize
  23. * @param int $isSeal
  24. * @return array
  25. * @throws \Exception
  26. */
  27. public function querySealDrugReport(string $beginTime, string $endTime, int $page = 1, int $pageSize = 20, int $isSeal = 0): array
  28. {
  29. $req = new AlibabaAlihealthSynergyYzwQuerysealdrugreportRequest;
  30. $req->setRefEntId($this->config['enterprise_id']);
  31. $req->setBeginTime($beginTime);
  32. $req->setEndTime($endTime);
  33. $req->setPage($page);
  34. $req->setPageSize($pageSize);
  35. if ($isSeal) {
  36. $req->setStatus($isSeal);
  37. }
  38. $resp = $this->client->execute($req);
  39. if ('SUCCESS' <> $resp->result->msg_code) {
  40. throw new \Exception($resp->result->msg_info);
  41. }
  42. $data = json_decode(json_encode(
  43. $resp->result->model->result_list->ocr_seal_drug_report_d_t_o
  44. ), true);
  45. app(DrugReportInfoService::class)->bulkInsert($data);
  46. return (array)$resp;
  47. }
  48. }