Skip to content

Commit 4ebe659

Browse files
authored
Merge pull request #1 from iMactool/develop
v1.0.0-release
2 parents ca3b9a9 + c48d6b8 commit 4ebe659

File tree

5 files changed

+96
-52
lines changed

5 files changed

+96
-52
lines changed

README.md

+53-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,59 @@ $refundOrder = [
111111
$result = $app->pushOrderRefund($refundOrder);
112112

113113
```
114-
115-
其他具体可以查看代码
114+
115+
## 管家婆API 列表
116+
117+
### 商品管理
118+
- pushProduct() 宝贝上载
119+
- queryProduct() 商品详情查询
120+
121+
### 订单交易
122+
- pushOrder() 订单批量上载/更新接口
123+
- queryOrderStatus() 查询订单处理状态
124+
- querySaleOrder() 订单查询
125+
126+
### 售后场景
127+
- pushOrderRefund() 售后单上载
128+
- queryOrderRefund() 售后详情查询
129+
130+
### 库存管理
131+
- queryQtyInfo() 仓库详情查询
132+
- querySaleQty() 商品库存查询
133+
- queryMoreSaleQty() 批量库存查询
134+
135+
### 全渠道场景/门店
136+
- pushStoreInfo() 门店信息上载
137+
138+
----
139+
140+
分割线: 目前由于章鱼侠相关的测试接口无法正常使用。暂不支持。管家婆相关接口正常
141+
142+
----
143+
144+
##章鱼侠 API 列表
145+
146+
### 商品管理
147+
- pushProduct() 宝贝上载
148+
- queryProduct() 商品详情查询
149+
150+
### 订单交易
151+
- pushOrder() 订单批量上载/更新接口
152+
- queryOrderStatus() 查询订单处理状态
153+
- querySaleOrder() 订单查询
154+
155+
### 售后场景
156+
- pushOrderRefund() 售后单上载
157+
- queryOrderRefund() 售后详情查询
158+
159+
### 库存管理
160+
- queryQtyInfo() 仓库详情查询
161+
- querySaleQty() 商品库存查询
162+
- queryMoreSaleQty() 批量库存查询
163+
164+
### 全渠道场景/门店
165+
- pushStoreInfo() 门店信息上载
166+
116167

117168
TODO
118169

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

+17-30
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(array $config)
2222
}
2323

2424
/**
25-
* 接口获取授权认证码
25+
* 接口获取授权认证码 [废弃]
2626
* @return mixed
2727
* @throws HttpException
2828
*/
@@ -58,20 +58,20 @@ public function getAuthCode()
5858
}
5959

6060
/**
61+
* 步骤2 利用授权认证码获取token信息
6162
* 接口获取授权认证码 token
63+
* @param string $auth_code
6264
* @return array|mixed
6365
* @throws HttpException
66+
* @author cc
6467
*/
65-
public function getTokenInfo()
68+
public function getTokenInfo(string $auth_code)
6669
{
67-
$code = $this->getAuthCode();
68-
if (is_array($code)){
69-
return ['code'=>$code['errorcode'],'msg'=>$code['errormessage'].',requestid : '.$code['requestid']];
70-
}
70+
7171
$params = [
7272
'TimeStamp'=>date('Y-m-d H:i:s'),
7373
'GrantType'=>'auth_token',
74-
'AuthParam'=>trim($code)
74+
'AuthParam'=>trim($auth_code)
7575
];
7676
$param = $this->makeSecretData($params);
7777

@@ -82,30 +82,14 @@ public function getTokenInfo()
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-
90-
$response = $result['response']['response'];
91-
88+
$response = trim($result['response']['response']);
9289
$tokenInfo = $this->aesFace()->decrypt($response);
93-
94-
/**
95-
* 返回解析之后的结果
96-
array (size=8)
97-
'appkey' => string '68831364318015642713205516431221' (length=32)
98-
'auth_token' => string 'hDFhehHplEYslTsIUPSPODIHhKdqNXJrsGz0Mn14' (length=40)
99-
'profileid' => string '515867705654726157' (length=18)
100-
'employee_id' => string '515867705767072864' (length=18)
101-
'expires_in' => float 864000
102-
'refresh_token' => string 'QErAUm3YsfMUA4VPvA6eMY9KUFThlCOJWvyVmltr' (length=40)
103-
're_expires_in' => float 15552000
104-
'timestamp' => string '2020/11/17 16:52:07' (length=19)
105-
* 调用授权接口授权获得的token有效期是10天,token过期前可以调用token刷新接口进行接口刷新操作。
106-
* 刷新token时不需要登录erp系统,刷新token最多可用180天。然后就必须使用使用授权接口登录erp进行授权
107-
*/
108-
return json_decode($tokenInfo,true);
90+
$tokenInfo = trim($tokenInfo);
91+
preg_match('/^\{("\w+":"(.*?)",?)+\}/', $tokenInfo,$match);
92+
return \json_decode($match[0],true);
10993
}catch (\Exception $e){
11094
throw new HttpException($e->getMessage(),$e->getCode(),$e);
11195
}
@@ -118,7 +102,7 @@ public function getTokenInfo()
118102
* @return array|mixed
119103
* @throws HttpException
120104
*/
121-
public function refreshToken($refresh_token){
105+
public function refreshToken(string $refresh_token){
122106

123107
$params = [
124108
'TimeStamp'=>date('Y-m-d H:i:s'),
@@ -138,15 +122,17 @@ public function refreshToken($refresh_token){
138122
if ($result['iserror']){
139123
return ['code'=>$result['errorcode'],'msg'=>$result['errormessage'].',requestid : '.$result['requestid']];
140124
}
141-
$response = $result['response']['response'];
125+
$response = trim($result['response']['response']);
142126
$tokenInfo = $this->aesFace()->decrypt($response);
143-
return json_decode($tokenInfo,true);
127+
preg_match('/^\{("\w+":"(.*?)",?)+\}/', $tokenInfo,$match);
128+
return \json_decode($match[0],true);
144129
}catch (\Exception $e){
145130
throw new HttpException($e->getMessage(),$e->getCode(),$e);
146131
}
147132
}
148133

149134
/**
135+
* 步骤1 获取授权认证码
150136
* 站点登录获取授权认证码
151137
* 组装授权登录参数,访问授权登录地址,输入erp账号,认证成功后 ,在回调地址返回auth_code
152138
* @param $redirect_url 授权成功后跳转的地址,主域名必须和申请应用时的主域名一致
@@ -224,6 +210,7 @@ public function queryOrderStatus(array $params){
224210
return $this->httpRequest($post);
225211
}
226212

213+
227214
//---------------------------------------------------
228215
// 库存 start
229216
//---------------------------------------------------

src/Factory.php

+14-13
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ public static function make($name, array $config)
2323
$application = "\\Imactool\\Gjpzyx\\{$namespace}\\{$namespace}";
2424

2525
if('gjp' == strtolower($name)){
26-
if (!$config['debug']){
26+
if (isset($config['debug']) && !$config['debug']){
2727
$config = array_merge($config,self::gjpDefaultConfig());
2828
}else{
2929
$config = array_merge(self::testGjpDefaultConfig(),$config);
3030
}
3131

3232
}else if('zyx' == strtolower($name)){
33-
if (!$config['debug']){
33+
if (isset($config['debug']) && !$config['debug']){
3434
$config = array_merge($config,self::zyxDefaultConfig());
3535
}else{
36-
$config = array(self::testZyxDefaultConfig(),$config);
36+
$config = array_merge(self::testZyxDefaultConfig(),$config);
3737
}
3838
}
3939

@@ -71,19 +71,19 @@ public static function testGjpDefaultConfig(){
7171
'appKey' => '68943923115886070418838901844741',
7272
'appSecret' => 'ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7',
7373
'signKey' => 'lezitiancheng',
74-
'token' => 'WjKsfpVHkPYtKPWkxICIQ7BWLYBvU5jfAL8Wofe3',
74+
'token' => 'cEb6ARwqhyfQeoF4gL8eSEXyAo0nDOL51MtLryce',
7575
'shopKey' => '92a01da5-3e1a-45bb-9277-c29a0586685e',
7676
//公司名称
7777
'CompanyName'=>'TestMall',
7878
//用户名
7979
'UserId' => 'test9',
8080
//密码
8181
'Password' => 'grasp@909',
82-
'refreshToken' => 'BwfoCBHxPiR8BCY4OtMTDeoDTosLs8dgRxHQg5fd',
83-
//线上登录获取授权认证码的地址
84-
'loginUrl'=>'http://ca.mygjp.com:666/account/login?',
82+
'refreshToken' => 'hIViTJcMiHBwOCEK1fEEvbd7lXlI8uu995tHrDEO',
83+
// 测试环境登录地址
84+
'loginUrl'=>'http://d7.mygjp.com.cn:666/account/login?',
8585
//线上接口调用的地址
86-
'apiUrl'=>'http://ca.mygjp.com:8002/api/',
86+
'apiUrl'=>'http://d7.mygjp.com.cn:8002/api',
8787
//线上管家婆云erp登录地址
8888
'onlineLoginUrl'=>'http://login.wsgjp.com/'
8989
];
@@ -120,18 +120,19 @@ public static function testZyxDefaultConfig(){
120120
'appKey' => '68943923115886070418838901844741',
121121
'appSecret' => 'ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7',
122122
'signKey' => 'lezitiancheng',
123-
'token' => '0I7dHCByoGxlxAHU8I50MzpPVbN0Nl56goE2YGdP',
124-
'shopKey' => 'e7c5289b-07ee-492f-b84f-97ee9659c8b7',
123+
'token' => 'mMwbS4x1jMTyiw4wiuD1mDDm1yuOcATiMyQ9vGp7',
124+
'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)