RensheService.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. namespace app\common\service;
  3. class RensheService
  4. {
  5. //网址
  6. const BASE_URL = 'https://12333.jinjiang.gov.cn/interface-jjlgsc-wbjk';
  7. //密钥
  8. const KEY = 'be2daba9afed4b75';
  9. //偏移量
  10. const IV = 'b33f8ac8cca782b9';
  11. //版本号
  12. const VERSION = 'lgyz1.0';
  13. //要发送的数据
  14. private $_data = [];
  15. //当前时间
  16. private $_time = 0;
  17. /**
  18. * 构造函数
  19. * @param array $data 要发送的数据
  20. */
  21. public function __construct($data = [])
  22. {
  23. $this->_data = $data;
  24. $this->_time = date('YmdHis');
  25. }
  26. /**
  27. * 设置参数
  28. * @param $data
  29. */
  30. public function setData($data)
  31. {
  32. foreach ($data as $k => $v) {
  33. $this->_data[$k] = $v;
  34. }
  35. }
  36. /**
  37. * 岗位信息库提交
  38. */
  39. public function JobInfo()
  40. {
  41. $url = self::BASE_URL . '/dayjob/submitJobInfo.html';
  42. $res = $this->_send($url);
  43. return $res;
  44. }
  45. /**
  46. * 参数加密
  47. * @return string
  48. */
  49. private function _enDataCbc()
  50. {
  51. $data = $this->_time . json_encode($this->_data);
  52. return base64_encode(http_request('http://192.168.1.91/sm4_en.php', 'POST', ['data' => $data]));
  53. // return base64_encode(openssl_encrypt($data, "SM4", self::KEY, 0, self::IV));
  54. }
  55. /**
  56. * 参数解密
  57. * @param $data
  58. * @return mixed
  59. */
  60. private function _deDataCbc($data)
  61. {
  62. $res = http_request('http://192.168.1.91/sm4_de.php', 'POST', ['data' => base64_decode($data)]);
  63. // $res = openssl_decrypt(base64_decode($data), "SM4", self::KEY, 0, self::IV);
  64. if ($res[0] != "{") {
  65. $res = mb_substr($res, 14, strlen($res), 'UTF-8');
  66. }
  67. return json_decode($res, true);
  68. }
  69. /**
  70. * 发送数据
  71. * @param $url
  72. * @return mixed
  73. */
  74. private function _send($url)
  75. {
  76. //请求头
  77. $enTime = base64_encode(http_request('http://192.168.1.91/sm4_en.php', 'POST', ['data' => $this->_time]));
  78. // $enTime = base64_encode(openssl_encrypt($this->_time, "SM4", self::KEY, 0, self::IV));
  79. $header = [
  80. 'Content-Type: application/json',
  81. 'Author-source: 1',
  82. 'Author-token: ' . $enTime,
  83. 'Author-version: ' . self::VERSION,
  84. ];
  85. //发送数据
  86. $enData = $this->_enDataCbc();
  87. $response = http_request($url, 'POST', $enData, $header);
  88. $deData = $this->_deDataCbc($response);
  89. return $deData;
  90. }
  91. }