RensheService.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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['bcz018'] = $info['emp_code'];
  87. $item['bcz011'] = $info['is_worry'];
  88. $item['bcz015'] = $info['longitude'];
  89. $item['bcz016'] = $info['latitude'];
  90. $item['bye002'] = $info['updatetime'];
  91. $item = array_filter($item);
  92. $item['aae100'] = $info['status'] == 3 ? 1 : 0;
  93. $list[] = $item;
  94. $send['list'] = $list;
  95. $this->setData($send);
  96. }
  97. /**
  98. * 岗位信息库提交
  99. */
  100. public function jobInfo()
  101. {
  102. $this->_log_name = '岗位信息库';
  103. $url = self::BASE_URL . '/dayjob/submitJobInfo.html';
  104. $res = $this->_send($url);
  105. return $res;
  106. }
  107. /**
  108. * 岗位信息库提交ComId
  109. */
  110. public function jobInfoByComId($id)
  111. {
  112. //线上环境才同步
  113. if (env('APP_DEBUG')) {
  114. return ['code' => 200];
  115. }
  116. $this->_jobInfoData($id);
  117. $res = $this->jobInfo();
  118. return $res;
  119. }
  120. /**
  121. * 岗位撮合信息结果信息提交
  122. */
  123. public function matchSubmit()
  124. {
  125. $this->_log_name = '岗位撮合';
  126. $url = self::BASE_URL . '/dayjob/submitLaborRelations.html';
  127. $res = $this->_send($url);
  128. return $res;
  129. }
  130. /**
  131. * 参数加密
  132. * @return string
  133. */
  134. private function _enDataCbc()
  135. {
  136. $data = $this->_time . json_encode($this->_data);
  137. return base64_encode(http_request('http://10.10.10.63/sm4_en.php', 'POST', ['data' => $data]));
  138. // return base64_encode(openssl_encrypt($data, "SM4", self::KEY, 0, self::IV));
  139. }
  140. /**
  141. * 参数解密
  142. * @param $data
  143. * @return mixed
  144. */
  145. private function _deDataCbc($data)
  146. {
  147. $res = http_request('http://10.10.10.63/sm4_de.php', 'POST', ['data' => base64_decode($data)]);
  148. // $res = openssl_decrypt(base64_decode($data), "SM4", self::KEY, 0, self::IV);
  149. if ($res[0] != "{") {
  150. $res = mb_substr($res, 14, strlen($res), 'UTF-8');
  151. }
  152. return json_decode($res, true);
  153. }
  154. /**
  155. * 发送数据
  156. * @param $url
  157. * @return mixed
  158. */
  159. private function _send($url)
  160. {
  161. Log::info($this->_log_name . ':' . json_encode($this->_data));
  162. //请求头
  163. $enTime = base64_encode(http_request('http://10.10.10.63/sm4_en.php', 'POST', ['data' => $this->_time]));
  164. // $enTime = base64_encode(openssl_encrypt($this->_time, "SM4", self::KEY, 0, self::IV));
  165. $header = [
  166. 'Content-Type: application/json',
  167. 'Author-source: 1',
  168. 'Author-token: ' . $enTime,
  169. 'Author-version: ' . self::VERSION,
  170. ];
  171. //发送数据
  172. $enData = $this->_enDataCbc();
  173. $response = http_request($url, 'POST', $enData, $header);
  174. $deData = $this->_deDataCbc($response);
  175. Log::info($this->_log_name . '返回数据:' . json_encode($deData));
  176. //重置默认值,方便下一次使用
  177. $this->_data = [];
  178. $this->_time = date('YmdHis');
  179. return $deData;
  180. }
  181. }