Skip to content

Commit

Permalink
Merge pull request #1 from iMactool/develop
Browse files Browse the repository at this point in the history
v1.0.0-release
  • Loading branch information
iMactool authored Sep 9, 2021
2 parents ca3b9a9 + c48d6b8 commit 4ebe659
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 52 deletions.
55 changes: 53 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,59 @@ $refundOrder = [
$result = $app->pushOrderRefund($refundOrder);

```

其他具体可以查看代码

## 管家婆API 列表

### 商品管理
- pushProduct() 宝贝上载
- queryProduct() 商品详情查询

### 订单交易
- pushOrder() 订单批量上载/更新接口
- queryOrderStatus() 查询订单处理状态
- querySaleOrder() 订单查询

### 售后场景
- pushOrderRefund() 售后单上载
- queryOrderRefund() 售后详情查询

### 库存管理
- queryQtyInfo() 仓库详情查询
- querySaleQty() 商品库存查询
- queryMoreSaleQty() 批量库存查询

### 全渠道场景/门店
- pushStoreInfo() 门店信息上载

----

分割线: 目前由于章鱼侠相关的测试接口无法正常使用。暂不支持。管家婆相关接口正常

----

##章鱼侠 API 列表

### 商品管理
- pushProduct() 宝贝上载
- queryProduct() 商品详情查询

### 订单交易
- pushOrder() 订单批量上载/更新接口
- queryOrderStatus() 查询订单处理状态
- querySaleOrder() 订单查询

### 售后场景
- pushOrderRefund() 售后单上载
- queryOrderRefund() 售后详情查询

### 库存管理
- queryQtyInfo() 仓库详情查询
- querySaleQty() 商品库存查询
- queryMoreSaleQty() 批量库存查询

### 全渠道场景/门店
- pushStoreInfo() 门店信息上载


TODO

Expand Down
7 changes: 6 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
"name": "imactool\/gjpzyx",
"description": "管家婆ERP 管家婆章鱼侠API",
"license": "MIT",
"keywords": [
"管家婆ERP open api",
"管家婆章鱼侠API",
"php sdk"
],
"authors": [
{
"name": "iMactool",
"email": "[email protected]"
}
],
"require": {
"guzzlehttp/guzzle": "^6.5"
"guzzlehttp/guzzle": "^6.5|^7.0.1"
},
"autoload": {
"psr-4": {
Expand Down
12 changes: 6 additions & 6 deletions src/Aes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

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

/**
Expand All @@ -32,8 +32,8 @@ public function setAesKey($key){
//加密
public function encrypt($encryptStr){
error_reporting(E_ALL & ~E_DEPRECATED); //兼容管家婆使用过时 ASE 加密方式
$localIV = $this->iv;
$encryptKey = $this->encryptKey;
$localIV = trim($this->iv);
$encryptKey = trim($this->encryptKey);
$encryptStr = trim($encryptStr);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
mcrypt_generic_init($module, $encryptKey, $localIV);
Expand All @@ -49,11 +49,11 @@ public function encrypt($encryptStr){
//解密
public function decrypt($encryptStr) {
error_reporting(E_ALL & ~E_DEPRECATED); //兼容管家婆使用过时 ASE 加密方式
$localIV = $this->iv;
$encryptKey = $this->encryptKey;
$localIV = trim($this->iv);
$encryptKey = trim($this->encryptKey);
$module = mcrypt_module_open(MCRYPT_RIJNDAEL_128, '', MCRYPT_MODE_CBC, $localIV);
mcrypt_generic_init($module, $encryptKey, $localIV);
$encryptedData = base64_decode($encryptStr);
$encryptedData = base64_decode(trim($encryptStr));
$encryptedData = mdecrypt_generic($module, $encryptedData);
return $encryptedData;
}
Expand Down
47 changes: 17 additions & 30 deletions src/Base/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(array $config)
}

/**
* 接口获取授权认证码
* 接口获取授权认证码 [废弃]
* @return mixed
* @throws HttpException
*/
Expand Down Expand Up @@ -58,20 +58,20 @@ public function getAuthCode()
}

/**
* 步骤2 利用授权认证码获取token信息
* 接口获取授权认证码 token
* @param string $auth_code
* @return array|mixed
* @throws HttpException
* @author cc
*/
public function getTokenInfo()
public function getTokenInfo(string $auth_code)
{
$code = $this->getAuthCode();
if (is_array($code)){
return ['code'=>$code['errorcode'],'msg'=>$code['errormessage'].',requestid : '.$code['requestid']];
}

$params = [
'TimeStamp'=>date('Y-m-d H:i:s'),
'GrantType'=>'auth_token',
'AuthParam'=>trim($code)
'AuthParam'=>trim($auth_code)
];
$param = $this->makeSecretData($params);

Expand All @@ -82,30 +82,14 @@ public function getTokenInfo()

try {
$result = (new Http())->setApiUrl($this->config['apiUrl'])->httpPost($postData,'token');

if ($result['iserror']){
return ['code'=>$result['errorcode'],'msg'=>$result['errormessage'].',requestid : '.$result['requestid']];
}

$response = $result['response']['response'];

$response = trim($result['response']['response']);
$tokenInfo = $this->aesFace()->decrypt($response);

/**
* 返回解析之后的结果
array (size=8)
'appkey' => string '68831364318015642713205516431221' (length=32)
'auth_token' => string 'hDFhehHplEYslTsIUPSPODIHhKdqNXJrsGz0Mn14' (length=40)
'profileid' => string '515867705654726157' (length=18)
'employee_id' => string '515867705767072864' (length=18)
'expires_in' => float 864000
'refresh_token' => string 'QErAUm3YsfMUA4VPvA6eMY9KUFThlCOJWvyVmltr' (length=40)
're_expires_in' => float 15552000
'timestamp' => string '2020/11/17 16:52:07' (length=19)
* 调用授权接口授权获得的token有效期是10天,token过期前可以调用token刷新接口进行接口刷新操作。
* 刷新token时不需要登录erp系统,刷新token最多可用180天。然后就必须使用使用授权接口登录erp进行授权
*/
return json_decode($tokenInfo,true);
$tokenInfo = trim($tokenInfo);
preg_match('/^\{("\w+":"(.*?)",?)+\}/', $tokenInfo,$match);
return \json_decode($match[0],true);
}catch (\Exception $e){
throw new HttpException($e->getMessage(),$e->getCode(),$e);
}
Expand All @@ -118,7 +102,7 @@ public function getTokenInfo()
* @return array|mixed
* @throws HttpException
*/
public function refreshToken($refresh_token){
public function refreshToken(string $refresh_token){

$params = [
'TimeStamp'=>date('Y-m-d H:i:s'),
Expand All @@ -138,15 +122,17 @@ public function refreshToken($refresh_token){
if ($result['iserror']){
return ['code'=>$result['errorcode'],'msg'=>$result['errormessage'].',requestid : '.$result['requestid']];
}
$response = $result['response']['response'];
$response = trim($result['response']['response']);
$tokenInfo = $this->aesFace()->decrypt($response);
return json_decode($tokenInfo,true);
preg_match('/^\{("\w+":"(.*?)",?)+\}/', $tokenInfo,$match);
return \json_decode($match[0],true);
}catch (\Exception $e){
throw new HttpException($e->getMessage(),$e->getCode(),$e);
}
}

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


//---------------------------------------------------
// 库存 start
//---------------------------------------------------
Expand Down
27 changes: 14 additions & 13 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ public static function make($name, array $config)
$application = "\\Imactool\\Gjpzyx\\{$namespace}\\{$namespace}";

if('gjp' == strtolower($name)){
if (!$config['debug']){
if (isset($config['debug']) && !$config['debug']){
$config = array_merge($config,self::gjpDefaultConfig());
}else{
$config = array_merge(self::testGjpDefaultConfig(),$config);
}

}else if('zyx' == strtolower($name)){
if (!$config['debug']){
if (isset($config['debug']) && !$config['debug']){
$config = array_merge($config,self::zyxDefaultConfig());
}else{
$config = array(self::testZyxDefaultConfig(),$config);
$config = array_merge(self::testZyxDefaultConfig(),$config);
}
}

Expand Down Expand Up @@ -71,19 +71,19 @@ public static function testGjpDefaultConfig(){
'appKey' => '68943923115886070418838901844741',
'appSecret' => 'ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7',
'signKey' => 'lezitiancheng',
'token' => 'WjKsfpVHkPYtKPWkxICIQ7BWLYBvU5jfAL8Wofe3',
'token' => 'cEb6ARwqhyfQeoF4gL8eSEXyAo0nDOL51MtLryce',
'shopKey' => '92a01da5-3e1a-45bb-9277-c29a0586685e',
//公司名称
'CompanyName'=>'TestMall',
//用户名
'UserId' => 'test9',
//密码
'Password' => 'grasp@909',
'refreshToken' => 'BwfoCBHxPiR8BCY4OtMTDeoDTosLs8dgRxHQg5fd',
//线上登录获取授权认证码的地址
'loginUrl'=>'http://ca.mygjp.com:666/account/login?',
'refreshToken' => 'hIViTJcMiHBwOCEK1fEEvbd7lXlI8uu995tHrDEO',
// 测试环境登录地址
'loginUrl'=>'http://d7.mygjp.com.cn:666/account/login?',
//线上接口调用的地址
'apiUrl'=>'http://ca.mygjp.com:8002/api/',
'apiUrl'=>'http://d7.mygjp.com.cn:8002/api',
//线上管家婆云erp登录地址
'onlineLoginUrl'=>'http://login.wsgjp.com/'
];
Expand Down Expand Up @@ -120,18 +120,19 @@ public static function testZyxDefaultConfig(){
'appKey' => '68943923115886070418838901844741',
'appSecret' => 'ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7',
'signKey' => 'lezitiancheng',
'token' => '0I7dHCByoGxlxAHU8I50MzpPVbN0Nl56goE2YGdP',
'shopKey' => 'e7c5289b-07ee-492f-b84f-97ee9659c8b7',
'token' => 'mMwbS4x1jMTyiw4wiuD1mDDm1yuOcATiMyQ9vGp7',
'shopKey' => '2345678sdfg',
//公司名称
'CompanyName'=>'TestMall',
//用户名
'UserId' => 'test',
//密码
'Password' => 'grasp@101',
'refreshToken' => '548BGezYm6wfTCzeazuk0d0UeR39AUMYJAJv3pGH',
'refreshToken' => 'RAM5VwheS4RWFkApJzxDtjC4GzPWa7C4FRgNr175',
//线上登录获取授权认证码的地址
'loginUrl'=>'http://ca.mygjp.com:666/account/login?',
'apiUrl'=>'http://ca.mygjp.com:8002/api/',
'loginUrl'=>'http://d7.mygjp.com.cn:666/account/login?',
//线上接口调用的地址
'apiUrl'=>'http://d7.mygjp.com.cn:8002/api',
//线上章鱼侠云erp登录地址
'onlineLoginUrl'=>'http://login.zhangyuxia.com.cn'
];
Expand Down

0 comments on commit 4ebe659

Please sign in to comment.