RensheService.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace app\common\service;
  3. use app\common\model\WorkerThird;
  4. use think\facade\Log;
  5. use app\common\model\Comjobs as ComjobsModel;
  6. class RensheService
  7. {
  8. //网址
  9. const BASE_URL = 'https://12333.jinjiang.gov.cn/interface-jjlgsc-wbjk';
  10. //密钥
  11. const KEY = 'be2daba9afed4b75';
  12. //偏移量
  13. const IV = 'b33f8ac8cca782b9';
  14. //版本号
  15. const VERSION = 'lgyz1.0';
  16. //要发送的数据
  17. private $_data = [];
  18. //当前时间
  19. private $_time = 0;
  20. //日志名称
  21. private $_log_name = '';
  22. /**
  23. * 构造函数
  24. * @param array $data 要发送的数据
  25. */
  26. public function __construct($data = [])
  27. {
  28. $this->_data = $data;
  29. $this->_time = date('YmdHis');
  30. }
  31. /**
  32. * 设置参数
  33. * @param $data
  34. */
  35. public function setData($data)
  36. {
  37. foreach ($data as $k => $v) {
  38. $this->_data[$k] = $v;
  39. }
  40. }
  41. private function _jobInfoData($id)
  42. {
  43. $info = ComjobsModel::with([
  44. 'worker',
  45. 'comjobsCate',
  46. 'ageCode' => function ($query) {
  47. $query->where('type', 'age');
  48. }, 'educationCode' => function ($query) {
  49. $query->where('type', 'education');
  50. }])->find($id);
  51. //数据重组
  52. $list = $item = [];
  53. $item['baz367'] = $info['id'];
  54. if (!empty($info['comjobsCate']['code'])) {
  55. $item['aca111'] = $info['comjobsCate']['code'];
  56. }
  57. $item['aca112'] = $info['title'];
  58. $item['bcz002'] = $info['wtype'];
  59. $item['bcz017'] = $info['zwagall'];
  60. if (!empty($info['community'])) {
  61. $item['cae006'] = $info['community'];
  62. }
  63. $item['cae007'] = $info['province'] . $info['city'] . $info['district'] . $info['address'];
  64. if (!empty($info['educationCode']['code'])) {
  65. $item['aac011'] = $info['educationCode']['code'];
  66. }
  67. if (!empty($info['ageCode']['code'])) {
  68. $item['bcz006'] = $info['ageCode']['code'];
  69. }
  70. $item['bcz019'] = implode(',', $info['tags']);
  71. // $item['caa004s'] = $info['tags_code'];
  72. $item['bcz007'] = $info['comdetails'];
  73. $item['bcz008'] = $info['requirement'];
  74. $item['bcz009'] = $info['worker']['wtype'];
  75. if (empty($info['third_id'])) {
  76. $item['aab069'] = $info['worker']['title'];
  77. $item['aae004'] = $info['worker']['realname'];
  78. $item['aae006'] = $info['worker']['province'] . $info['worker']['city'] . $info['worker']['district'] . $info['worker']['address'];
  79. } else {
  80. $third = WorkerThird::where('id', $info['third_id'])->find();
  81. $item['aab069'] = $third['name'];
  82. $item['aae004'] = $third['contact'];;
  83. $item['aae006'] = $info['worker']['province'] . $info['worker']['city'] . $info['worker']['district'] . $info['worker']['address'];
  84. }
  85. $item['aae005'] = $info['telephone'];
  86. $item['bcz005'] = $info['recruit_num'];
  87. $item['bcz018'] = $info['emp_code'];
  88. $item['bcz011'] = $info['is_worry'];
  89. $item['bcz015'] = $info['longitude'];
  90. $item['bcz016'] = $info['latitude'];
  91. $item['bye002'] = $info['updatetime'];
  92. $item = array_filter($item);
  93. $item['aae100'] = $info['status'] == 3 ? 1 : 0;
  94. $list[] = $item;
  95. $send['list'] = $list;
  96. $this->setData($send);
  97. }
  98. /**
  99. * 岗位信息库提交
  100. */
  101. public function jobInfo()
  102. {
  103. $this->_log_name = '岗位信息库';
  104. $url = self::BASE_URL . '/dayjob/submitJobInfo.html';
  105. $res = $this->_send($url);
  106. return $res;
  107. }
  108. /**
  109. * 岗位信息库提交ComId
  110. */
  111. public function jobInfoByComId($id)
  112. {
  113. //线上环境才同步
  114. if (env('APP_DEBUG')) {
  115. return ['code' => 200];
  116. }
  117. $this->_jobInfoData($id);
  118. $res = $this->jobInfo();
  119. return $res;
  120. }
  121. /**
  122. * 岗位撮合信息结果信息提交
  123. */
  124. public function matchSubmit()
  125. {
  126. $this->_log_name = '岗位撮合';
  127. $url = self::BASE_URL . '/dayjob/submitLaborRelations.html';
  128. $res = $this->_send($url);
  129. return $res;
  130. }
  131. /**
  132. * 参数加密
  133. * @return string
  134. */
  135. private function _enDataCbc()
  136. {
  137. $data = $this->_time . json_encode($this->_data);
  138. return base64_encode(http_request('http://sm4.jinjianghc.com/encode.php', 'POST', ['data' => $data]));
  139. // return base64_encode(openssl_encrypt($data, "SM4", self::KEY, 0, self::IV));
  140. }
  141. /**
  142. * 参数解密
  143. * @param $data
  144. * @return mixed
  145. */
  146. private function _deDataCbc($data)
  147. {
  148. $res = http_request('http://sm4.jinjianghc.com/decode.php', 'POST', ['data' => base64_decode($data)]);
  149. // $res = openssl_decrypt(base64_decode($data), "SM4", self::KEY, 0, self::IV);
  150. if ($res[0] != "{") {
  151. $res = mb_substr($res, 14, strlen($res), 'UTF-8');
  152. }
  153. return json_decode($res, true);
  154. }
  155. /**
  156. * 发送数据
  157. * @param $url
  158. * @return mixed
  159. */
  160. private function _send($url)
  161. {
  162. Log::info($this->_log_name . ':' . json_encode($this->_data));
  163. //请求头
  164. $enTime = base64_encode(http_request('http://sm4.jinjianghc.com/encode.php', 'POST', ['data' => $this->_time]));
  165. // $enTime = base64_encode(openssl_encrypt($this->_time, "SM4", self::KEY, 0, self::IV));
  166. $header = [
  167. 'Content-Type: application/json',
  168. 'Author-source: 1',
  169. 'Author-token: ' . $enTime,
  170. 'Author-version: ' . self::VERSION,
  171. ];
  172. //发送数据
  173. $enData = $this->_enDataCbc();
  174. $response = http_request($url, 'POST', $enData, $header);
  175. $deData = $this->_deDataCbc($response);
  176. Log::info($this->_log_name . '返回数据:' . json_encode($deData));
  177. //重置默认值,方便下一次使用
  178. $this->_data = [];
  179. $this->_time = date('YmdHis');
  180. return $deData;
  181. }
  182. }