1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?php
- namespace app\common\service;
- use think\facade\Log;
- class FulianService
- {
- //网址
- const BASE_URL = 'https://woman_odd_job.jucai.gov.cn/linggong';
- // const BASE_URL = 'http://bd.woman_odd_job.com/linggong';
- //要发送的数据
- private $_data = [];
- //日志名
- private $_log_name = '';
- /**
- * 构造函数
- * @param array $data 要发送的数据
- */
- public function __construct($data = [])
- {
- $this->_data = $data;
- }
- /**
- * 设置参数
- * @param $data
- */
- public function setData($data)
- {
- foreach ($data as $k => $v) {
- $this->_data[$k] = $v;
- }
- }
- /**
- * 岗位信息库提交
- */
- public function jobInfo()
- {
- $this->_log_name = '同步岗位给妇联';
- $url = self::BASE_URL . '/getJob.html';
- $res = $this->_send($url);
- return $res;
- }
- /**
- * 岗位信息库提交
- */
- public function jobInfos()
- {
- $this->_log_name = '同步岗位列表给妇联';
- $url = self::BASE_URL . '/getJobs.html';
- $res = $this->_send($url);
- return $res;
- }
- /**
- * 发送数据
- * @param $url
- * @return mixed
- */
- private function _send($url)
- {
- Log::info($this->_log_name . ':' . json_encode($this->_data));
- //请求头
- $header = [
- 'Content-Type: application/json',
- ];
- //发送数据
- $response = http_request($url, 'POST', json_encode($this->_data), $header);
- Log::info($this->_log_name . '返回数据:' . $response);
- //重置默认值,方便下一次使用
- $this->_data = [];
- $this->_log_name = '';
- return json_decode($response,true);
- }
- }
|