Skip to content

Commit c48d6b8

Browse files
committed
更新防止解析回来的数据带空格导致 json 解析失败。
1 parent f51c736 commit c48d6b8

File tree

4 files changed

+25
-19
lines changed

4 files changed

+25
-19
lines changed

composer.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
"name": "imactool\/gjpzyx",
33
"description": "管家婆ERP 管家婆章鱼侠API",
44
"license": "MIT",
5+
"keywords": [
6+
"管家婆ERP open api",
7+
"管家婆章鱼侠API",
8+
"php sdk"
9+
],
510
"authors": [
611
{
712
"name": "iMactool",
813
"email": "[email protected]"
914
}
1015
],
1116
"require": {
12-
"guzzlehttp/guzzle": "^6.5"
17+
"guzzlehttp/guzzle": "^6.5|^7.0.1"
1318
},
1419
"autoload": {
1520
"psr-4": {

src/Aes.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class Aes
1212
{
13-
protected $iv = '000000000000000000'; //密钥偏移量IV,可自定义
13+
protected $iv = '1200kds000001233fd'; //密钥偏移量IV,可自定义
1414
protected $encryptKey = '7e4e615af165fe63cbf40e52abbc79e8';//AESkey,可自定义
1515

1616
/**
@@ -32,8 +32,8 @@ public function setAesKey($key){
3232
//加密
3333
public function encrypt($encryptStr){
3434
error_reporting(E_ALL & ~E_DEPRECATED); //兼容管家婆使用过时 ASE 加密方式
35-
$localIV = $this->iv;
36-
$encryptKey = $this->encryptKey;
35+
$localIV = trim($this->iv);
36+
$encryptKey = trim($this->encryptKey);
3737
$encryptStr = trim($encryptStr);
3838
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
3939
mcrypt_generic_init($module, $encryptKey, $localIV);
@@ -49,11 +49,11 @@ public function encrypt($encryptStr){
4949
//解密
5050
public function decrypt($encryptStr) {
5151
error_reporting(E_ALL & ~E_DEPRECATED); //兼容管家婆使用过时 ASE 加密方式
52-
$localIV = $this->iv;
53-
$encryptKey = $this->encryptKey;
52+
$localIV = trim($this->iv);
53+
$encryptKey = trim($this->encryptKey);
5454
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
5555
mcrypt_generic_init($module, $encryptKey, $localIV);
56-
$encryptedData = base64_decode($encryptStr);
56+
$encryptedData = base64_decode(trim($encryptStr));
5757
$encryptedData = mdecrypt_generic($module, $encryptedData);
5858
return $encryptedData;
5959
}

src/Base/Base.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,14 @@ public function getTokenInfo(string $auth_code)
8282

8383
try {
8484
$result = (new Http())->setApiUrl($this->config['apiUrl'])->httpPost($postData,'token');
85-
8685
if ($result['iserror']){
8786
return ['code'=>$result['errorcode'],'msg'=>$result['errormessage'].',requestid : '.$result['requestid']];
8887
}
89-
$response = rtrim($result['response']['response']);
88+
$response = trim($result['response']['response']);
9089
$tokenInfo = $this->aesFace()->decrypt($response);
91-
$tokenInfo = rtrim($tokenInfo);
92-
93-
return \json_decode($tokenInfo,true);
90+
$tokenInfo = trim($tokenInfo);
91+
preg_match('/^\{("\w+":"(.*?)",?)+\}/', $tokenInfo,$match);
92+
return \json_decode($match[0],true);
9493
}catch (\Exception $e){
9594
throw new HttpException($e->getMessage(),$e->getCode(),$e);
9695
}
@@ -103,7 +102,7 @@ public function getTokenInfo(string $auth_code)
103102
* @return array|mixed
104103
* @throws HttpException
105104
*/
106-
public function refreshToken($refresh_token){
105+
public function refreshToken(string $refresh_token){
107106

108107
$params = [
109108
'TimeStamp'=>date('Y-m-d H:i:s'),
@@ -123,9 +122,10 @@ public function refreshToken($refresh_token){
123122
if ($result['iserror']){
124123
return ['code'=>$result['errorcode'],'msg'=>$result['errormessage'].',requestid : '.$result['requestid']];
125124
}
126-
$response = $result['response']['response'];
125+
$response = trim($result['response']['response']);
127126
$tokenInfo = $this->aesFace()->decrypt($response);
128-
return json_decode($tokenInfo,true);
127+
preg_match('/^\{("\w+":"(.*?)",?)+\}/', $tokenInfo,$match);
128+
return \json_decode($match[0],true);
129129
}catch (\Exception $e){
130130
throw new HttpException($e->getMessage(),$e->getCode(),$e);
131131
}

src/Factory.php

+5-4
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,19 @@ public static function testZyxDefaultConfig(){
120120
'appKey' => '68943923115886070418838901844741',
121121
'appSecret' => 'ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7',
122122
'signKey' => 'lezitiancheng',
123-
'token' => '0I7dHCByoGxlxAHU8I50MzpPVbN0Nl56goE2YGdP',
123+
'token' => 'mMwbS4x1jMTyiw4wiuD1mDDm1yuOcATiMyQ9vGp7',
124124
'shopKey' => '2345678sdfg',
125125
//公司名称
126126
'CompanyName'=>'TestMall',
127127
//用户名
128128
'UserId' => 'test',
129129
//密码
130130
'Password' => 'grasp@101',
131-
'refreshToken' => '548BGezYm6wfTCzeazuk0d0UeR39AUMYJAJv3pGH',
131+
'refreshToken' => 'RAM5VwheS4RWFkApJzxDtjC4GzPWa7C4FRgNr175',
132132
//线上登录获取授权认证码的地址
133-
'loginUrl'=>'http://ca.mygjp.com:666/account/login?',
134-
'apiUrl'=>'http://ca.mygjp.com:8002/api/',
133+
'loginUrl'=>'http://d7.mygjp.com.cn:666/account/login?',
134+
//线上接口调用的地址
135+
'apiUrl'=>'http://d7.mygjp.com.cn:8002/api',
135136
//线上章鱼侠云erp登录地址
136137
'onlineLoginUrl'=>'http://login.zhangyuxia.com.cn'
137138
];

0 commit comments

Comments
 (0)