From f51c7361097bffd6202f49c5eb6dccdd1b8f8c11 Mon Sep 17 00:00:00 2001 From: weslee Date: Thu, 9 Sep 2021 15:49:00 +0800 Subject: [PATCH 1/2] update --- README.md | 55 +++++++++++++++++++++++++++++++++++++++++++++-- src/Base/Base.php | 37 +++++++++++-------------------- src/Factory.php | 18 ++++++++-------- 3 files changed, 74 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 3cef6cb..4e225e7 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/Base/Base.php b/src/Base/Base.php index f1116f0..3ca7ce5 100644 --- a/src/Base/Base.php +++ b/src/Base/Base.php @@ -22,7 +22,7 @@ public function __construct(array $config) } /** - * 接口获取授权认证码 + * 接口获取授权认证码 [废弃] * @return mixed * @throws HttpException */ @@ -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); @@ -86,26 +86,11 @@ public function getTokenInfo() if ($result['iserror']){ return ['code'=>$result['errorcode'],'msg'=>$result['errormessage'].',requestid : '.$result['requestid']]; } - - $response = $result['response']['response']; - + $response = rtrim($result['response']['response']); $tokenInfo = $this->aesFace()->decrypt($response); + $tokenInfo = rtrim($tokenInfo); - /** - * 返回解析之后的结果 - 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); + return \json_decode($tokenInfo,true); }catch (\Exception $e){ throw new HttpException($e->getMessage(),$e->getCode(),$e); } @@ -147,6 +132,7 @@ public function refreshToken($refresh_token){ } /** + * 步骤1 获取授权认证码 * 站点登录获取授权认证码 * 组装授权登录参数,访问授权登录地址,输入erp账号,认证成功后 ,在回调地址返回auth_code * @param $redirect_url 授权成功后跳转的地址,主域名必须和申请应用时的主域名一致 @@ -224,6 +210,7 @@ public function queryOrderStatus(array $params){ return $this->httpRequest($post); } + //--------------------------------------------------- // 库存 start //--------------------------------------------------- diff --git a/src/Factory.php b/src/Factory.php index 9e18f41..1b8d4d6 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -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); } } @@ -71,7 +71,7 @@ public static function testGjpDefaultConfig(){ 'appKey' => '68943923115886070418838901844741', 'appSecret' => 'ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7', 'signKey' => 'lezitiancheng', - 'token' => 'WjKsfpVHkPYtKPWkxICIQ7BWLYBvU5jfAL8Wofe3', + 'token' => 'cEb6ARwqhyfQeoF4gL8eSEXyAo0nDOL51MtLryce', 'shopKey' => '92a01da5-3e1a-45bb-9277-c29a0586685e', //公司名称 'CompanyName'=>'TestMall', @@ -79,11 +79,11 @@ public static function testGjpDefaultConfig(){ '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/' ]; @@ -121,7 +121,7 @@ public static function testZyxDefaultConfig(){ 'appSecret' => 'ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7', 'signKey' => 'lezitiancheng', 'token' => '0I7dHCByoGxlxAHU8I50MzpPVbN0Nl56goE2YGdP', - 'shopKey' => 'e7c5289b-07ee-492f-b84f-97ee9659c8b7', + 'shopKey' => '2345678sdfg', //公司名称 'CompanyName'=>'TestMall', //用户名 From c48d6b8ae1a90a37c9a817a9957538b90dc98791 Mon Sep 17 00:00:00 2001 From: weslee Date: Thu, 9 Sep 2021 17:35:19 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=98=B2=E6=AD=A2?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=9B=9E=E6=9D=A5=E7=9A=84=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=B8=A6=E7=A9=BA=E6=A0=BC=E5=AF=BC=E8=87=B4=20json=20?= =?UTF-8?q?=E8=A7=A3=E6=9E=90=E5=A4=B1=E8=B4=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- composer.json | 7 ++++++- src/Aes.php | 12 ++++++------ src/Base/Base.php | 16 ++++++++-------- src/Factory.php | 9 +++++---- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 5bef7ff..567edec 100644 --- a/composer.json +++ b/composer.json @@ -2,6 +2,11 @@ "name": "imactool\/gjpzyx", "description": "管家婆ERP 管家婆章鱼侠API", "license": "MIT", + "keywords": [ + "管家婆ERP open api", + "管家婆章鱼侠API", + "php sdk" + ], "authors": [ { "name": "iMactool", @@ -9,7 +14,7 @@ } ], "require": { - "guzzlehttp/guzzle": "^6.5" + "guzzlehttp/guzzle": "^6.5|^7.0.1" }, "autoload": { "psr-4": { diff --git a/src/Aes.php b/src/Aes.php index 8f37c4d..00f0372 100644 --- a/src/Aes.php +++ b/src/Aes.php @@ -10,7 +10,7 @@ class Aes { - protected $iv = '000000000000000000'; //密钥偏移量IV,可自定义 + protected $iv = '1200kds000001233fd'; //密钥偏移量IV,可自定义 protected $encryptKey = '7e4e615af165fe63cbf40e52abbc79e8';//AESkey,可自定义 /** @@ -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); @@ -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; } diff --git a/src/Base/Base.php b/src/Base/Base.php index 3ca7ce5..b2288ea 100644 --- a/src/Base/Base.php +++ b/src/Base/Base.php @@ -82,15 +82,14 @@ public function getTokenInfo(string $auth_code) 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 = rtrim($result['response']['response']); + $response = trim($result['response']['response']); $tokenInfo = $this->aesFace()->decrypt($response); - $tokenInfo = rtrim($tokenInfo); - - 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); } @@ -103,7 +102,7 @@ public function getTokenInfo(string $auth_code) * @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'), @@ -123,9 +122,10 @@ 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); } diff --git a/src/Factory.php b/src/Factory.php index 1b8d4d6..a9b5631 100644 --- a/src/Factory.php +++ b/src/Factory.php @@ -120,7 +120,7 @@ public static function testZyxDefaultConfig(){ 'appKey' => '68943923115886070418838901844741', 'appSecret' => 'ONxYDyNaCoyTzsp83JoQ3YYuMPHxk3j7', 'signKey' => 'lezitiancheng', - 'token' => '0I7dHCByoGxlxAHU8I50MzpPVbN0Nl56goE2YGdP', + 'token' => 'mMwbS4x1jMTyiw4wiuD1mDDm1yuOcATiMyQ9vGp7', 'shopKey' => '2345678sdfg', //公司名称 'CompanyName'=>'TestMall', @@ -128,10 +128,11 @@ public static function testZyxDefaultConfig(){ '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' ];