|
@@ -17,8 +17,6 @@ class RensheService
|
|
|
|
|
|
//要发送的数据
|
|
|
private $_data = [];
|
|
|
- //sm4对象
|
|
|
- private $_sm4Obj = null;
|
|
|
//当前时间
|
|
|
private $_time = 0;
|
|
|
|
|
@@ -28,9 +26,8 @@ class RensheService
|
|
|
*/
|
|
|
public function __construct($data = [])
|
|
|
{
|
|
|
- $this->_data = $data;
|
|
|
- $this->_sm4Obj = new Sm4(self::KEY, self::IV);
|
|
|
- $this->_time = date('YmdHis');
|
|
|
+ $this->_data = $data;
|
|
|
+ $this->_time = date('YmdHis');
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -62,9 +59,7 @@ class RensheService
|
|
|
private function _enDataCbc()
|
|
|
{
|
|
|
$data = $this->_time . json_encode($this->_data);
|
|
|
- $res = $this->_sm4Obj->encrypt($data);
|
|
|
-
|
|
|
- return $res;
|
|
|
+ return base64_encode(openssl_encrypt($data, "sm4", self::KEY, 0, self::IV));
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -74,9 +69,9 @@ class RensheService
|
|
|
*/
|
|
|
private function _deDataCbc($data)
|
|
|
{
|
|
|
- $res = $this->_sm4Obj->decrypt($data);
|
|
|
+ $res = openssl_decrypt(base64_decode($data), "sm4", self::KEY, 0, self::IV);
|
|
|
if ($res[0] != "{") {
|
|
|
- $res = mb_substr($res,14,strlen($res),'UTF-8');
|
|
|
+ $res = mb_substr($res, 14, strlen($res), 'UTF-8');
|
|
|
}
|
|
|
|
|
|
return json_decode($res, true);
|
|
@@ -90,7 +85,7 @@ class RensheService
|
|
|
private function _send($url)
|
|
|
{
|
|
|
//请求头
|
|
|
- $enTime = $this->_sm4Obj->encrypt($this->_time);
|
|
|
+ $enTime = base64_encode(openssl_encrypt($this->_time, "sm4", self::KEY, 0, self::IV));
|
|
|
$header = [
|
|
|
'Content-Type: application/json',
|
|
|
'Author-source: 1',
|