FulianService.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\service;
  3. use think\facade\Log;
  4. class FulianService
  5. {
  6. //网址
  7. const BASE_URL = 'https://woman_odd_job.jucai.gov.cn/linggong';
  8. // const BASE_URL = 'http://bd.woman_odd_job.com/linggong';
  9. //要发送的数据
  10. private $_data = [];
  11. //日志名
  12. private $_log_name = '';
  13. /**
  14. * 构造函数
  15. * @param array $data 要发送的数据
  16. */
  17. public function __construct($data = [])
  18. {
  19. $this->_data = $data;
  20. }
  21. /**
  22. * 设置参数
  23. * @param $data
  24. */
  25. public function setData($data)
  26. {
  27. foreach ($data as $k => $v) {
  28. $this->_data[$k] = $v;
  29. }
  30. }
  31. /**
  32. * 岗位信息库提交
  33. */
  34. public function jobInfo()
  35. {
  36. $this->_log_name = '同步岗位给妇联';
  37. $url = self::BASE_URL . '/getJob.html';
  38. $res = $this->_send($url);
  39. return $res;
  40. }
  41. /**
  42. * 岗位信息库提交
  43. */
  44. public function jobInfos()
  45. {
  46. $this->_log_name = '同步岗位列表给妇联';
  47. $url = self::BASE_URL . '/getJobs.html';
  48. $res = $this->_send($url);
  49. return $res;
  50. }
  51. /**
  52. * 发送数据
  53. * @param $url
  54. * @return mixed
  55. */
  56. private function _send($url)
  57. {
  58. Log::info($this->_log_name . ':' . json_encode($this->_data));
  59. //请求头
  60. $header = [
  61. 'Content-Type: application/json',
  62. ];
  63. //发送数据
  64. $response = http_request($url, 'POST', json_encode($this->_data), $header);
  65. Log::info($this->_log_name . '返回数据:' . $response);
  66. //重置默认值,方便下一次使用
  67. $this->_data = [];
  68. $this->_log_name = '';
  69. return json_decode($response,true);
  70. }
  71. }