123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace app\common\service;
- use OneSm\Sm4;
- class RensheService
- {
- //网址
- const BASE_URL = 'https://12333.jinjiang.gov.cn/interface-jjlgsc-wbjk';
- //密钥
- const KEY = 'be2daba9afed4b75';
- //偏移量
- const IV = 'b33f8ac8cca782b9';
- //版本号
- const VERSION = 'lgyz1.0';
- //要发送的数据
- private $_data = [];
- //sm4对象
- private $_sm4Obj = null;
- //当前时间
- private $_time = 0;
- /**
- * 构造函数
- * @param array $data 要发送的数据
- */
- public function __construct($data = [])
- {
- $this->_data = $data;
- $this->_sm4Obj = new Sm4(self::KEY, self::IV);
- $this->_time = date('YmdHis');
- }
- /**
- * 设置参数
- * @param $data
- */
- public function setData($data)
- {
- foreach ($data as $k => $v) {
- $this->_data[$k] = $v;
- }
- }
- /**
- * 岗位信息库提交
- */
- public function JobInfo()
- {
- $url = self::BASE_URL . '/dayjob/submitJobInfo.html';
- $res = $this->_send($url);
- return $res;
- }
- /**
- * 参数加密
- * @return string
- */
- private function _enDataCbc()
- {
- $data = $this->_time . json_encode($this->_data);
- $res = $this->_sm4Obj->encrypt($data);
- return $res;
- }
- /**
- * 参数解密
- * @param $data
- * @return mixed
- */
- private function _deDataCbc($data)
- {
- $res = $this->_sm4Obj->decrypt($data);
- if ($res[0] != "{") {
- $res = mb_substr($res,14,strlen($res),'UTF-8');
- }
- return json_decode($res, true);
- }
- /**
- * 发送数据
- * @param $url
- * @return mixed
- */
- private function _send($url)
- {
- //请求头
- $enTime = $this->_sm4Obj->encrypt($this->_time);
- $header = [
- 'Content-Type: application/json',
- 'Author-source: 1',
- 'Author-token: ' . $enTime,
- 'Author-version: ' . self::VERSION,
- ];
- //发送数据
- $enData = $this->_enDataCbc();
- $response = http_request($url, 'POST', $enData, $header);
- $deData = $this->_deDataCbc($response);
- return $deData;
- }
- }
|