ScenicArea.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <?php
  2. namespace App\Servers\Wenlv;
  3. use \Exception;
  4. /**
  5. * 获取景点信息API接口
  6. * @author 唐远望
  7. * @version 1.0
  8. * @date 2026-01-06
  9. */
  10. class ScenicArea
  11. {
  12. private $app_key;
  13. private $app_id;
  14. private $app_secret;
  15. private $header;
  16. private $baseUrl = 'https://jt-open-platform.jt-health.cn/management/api';
  17. /**
  18. * 构造函数
  19. * @throws Exception 当API密钥未设置时抛出异常
  20. *
  21. */
  22. public function __construct()
  23. {
  24. $time_string = date('Y-m-d', time());
  25. $this->header = [
  26. 'time_string:' . $time_string,
  27. ];
  28. }
  29. /**
  30. * 发送http post请求
  31. * @param string $url 请求地址
  32. * @param array $headers 请求头
  33. * @param json $postdata 请求数据
  34. * @param array $options curl配置项
  35. */
  36. public static function curl_post($url = '', $headers = '', $postdata = '', $options = array())
  37. {
  38. $ch = curl_init($url);
  39. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  40. curl_setopt($ch, CURLOPT_POST, 1);
  41. curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
  42. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  43. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  44. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
  45. if (!empty($headers)) {
  46. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  47. }
  48. if (!empty($options)) {
  49. curl_setopt_array($ch, $options);
  50. }
  51. $data = curl_exec($ch);
  52. return $data;
  53. }
  54. /**
  55. * 发送http get请求
  56. */
  57. public static function curl_get($url = '', $headers = '', $options = array())
  58. {
  59. $ch = curl_init($url);
  60. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  61. curl_setopt($ch, CURLOPT_TIMEOUT, 5);
  62. if (!empty($headers)) {
  63. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  64. }
  65. if (!empty($options)) {
  66. curl_setopt_array($ch, $options);
  67. }
  68. $data = curl_exec($ch);
  69. return $data;
  70. }
  71. /**
  72. * 提交设备采样数据接口
  73. * @author 唐远望
  74. * @version 1.0
  75. * @date 2026-01-06
  76. */
  77. public function submitDeviceData($request_data)
  78. {
  79. $url = $this->baseUrl . '/report/submitReport';
  80. $response = self::curl_post($url, $this->header, json_encode($request_data));
  81. $response_data = json_decode($response, true);
  82. return $response_data;
  83. }
  84. /**
  85. * 获取报告接口
  86. * @author 唐远望
  87. * @version 1.0
  88. * @date 2026-01-06
  89. */
  90. public function getReport($request_data)
  91. {
  92. $url = $this->baseUrl . '/report/getReport';
  93. $response = self::curl_post($url, $this->header, json_encode($request_data));
  94. $response_data = json_decode($response, true);
  95. return $response_data;
  96. }
  97. /**
  98. * 获取报告18大风险对应的商品推荐
  99. * @author 唐远望
  100. * @version 1.0
  101. * @date 2026-01-06
  102. */
  103. public function getDeviceData($request_data)
  104. {
  105. $url = $this->baseUrl . '/report/getRiskCommodityList';
  106. $response = self::curl_post($url, $this->header, json_encode($request_data));
  107. $response_data = json_decode($response, true);
  108. return $response_data;
  109. }
  110. /**
  111. * 体质卡兑换
  112. * @author 唐远望
  113. * @version 1.0
  114. * @date 2026-01-06
  115. */
  116. public function exchangeHealthCard($request_data)
  117. {
  118. $url = $this->baseUrl . '/physiqueCard/exchangePhysiqueCard';
  119. $response = self::curl_post($url, $this->header, json_encode($request_data));
  120. $response_data = json_decode($response, true);
  121. return $response_data;
  122. }
  123. /**
  124. * 获取近两天报告
  125. * @author 唐远望
  126. * @version 1.0
  127. * @date 2026-01-06
  128. */
  129. public function getTwoDayReport($request_data)
  130. {
  131. $url = $this->baseUrl . '/report/getDaysReportsList';
  132. $response = self::curl_post($url, $this->header, json_encode($request_data));
  133. $response_data = json_decode($response, true);
  134. return $response_data;
  135. }
  136. /**
  137. * 获取近一周报告
  138. * @author 唐远望
  139. * @version 1.0
  140. * @date 2026-01-06
  141. */
  142. public function getOneWeekReport($request_data)
  143. {
  144. $url = $this->baseUrl . '/report/getWeeksReportsList';
  145. $response = self::curl_post($url, $this->header, json_encode($request_data));
  146. $response_data = json_decode($response, true);
  147. return $response_data;
  148. }
  149. /**
  150. * 两笔报告对比
  151. * @author 唐远望
  152. * @version 1.0
  153. * @date 2026-01-06
  154. */
  155. public function compareTwoReport($request_data)
  156. {
  157. $url = $this->baseUrl . '/report/getReportContrast';
  158. $response = self::curl_post($url, $this->header, json_encode($request_data));
  159. $response_data = json_decode($response, true);
  160. return $response_data;
  161. }
  162. /**
  163. * 激活设备
  164. * @author 唐远望
  165. * @version 1.0
  166. * @date 2026-01-08
  167. */
  168. public function activateDevice($request_data){
  169. $url = $this->baseUrl . '/report/activateCode';
  170. $response = self::curl_post($url, $this->header, json_encode($request_data));
  171. $response_data = json_decode($response, true);
  172. return $response_data;
  173. }
  174. /**
  175. * 获取设备信息
  176. * @author 唐远望
  177. * @version 1.0
  178. * @date 2026-01-08
  179. */
  180. public function getDeviceInfo($request_data){
  181. $url = $this->baseUrl . '/report/getDeviceInfo';
  182. $response = self::curl_post($url, $this->header, json_encode($request_data));
  183. $response_data = json_decode($response, true);
  184. return $response_data;
  185. }
  186. }