RensheService.php 2.2 KB

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