增加回传确认callback

This commit is contained in:
ZweiCD 2020-03-20 18:15:53 +08:00
parent 3e0b0bea6f
commit 3d60732610
4 changed files with 207 additions and 10 deletions

View File

@ -397,4 +397,9 @@ class GwallWms extends BaseWms implements WmsInterface
}, $params);
return $params;
}
public function callback($params)
{
}
}

View File

@ -19,4 +19,6 @@ Interface WmsInterface
public function stockInCreate(array $params, int $type);
public function stockOutCreate(array $params);
public function callback(array $params);
}

View File

@ -52,4 +52,9 @@ class WmsStrategy
public function stockOutCreate($params) {
return $this->wmsClient->stockOutCreate($params);
}
public static function callback($params) {
$client = new XinyiWms();
return $client->callback($params);
}
}

View File

@ -2,6 +2,11 @@
namespace PdWms;
use App\Service\Goods\GoodsWarehouseService;
use App\Service\Order\OrderItemLackReportService;
use App\Service\Order\OrderProcessReportService;
use App\Service\Order\OrderService;
use App\Service\Order\RefundService;
use PdWms\Service\Array2XML;
use PdWms\Service\XML2Array;
use GuzzleHttp\Client;
@ -447,6 +452,185 @@ class XinyiWms extends BaseWms implements WmsInterface
return $ret;
}
public function xmlPost($method, $params)
{
$xml = Array2XML::createXML('request', $params);
$body = $xml->saveXML();
$res = $this->createSign($method, $body);
$result = $this->post($body, $res);
$isSuccess = (empty($result) || !is_array($result) || $result['response']['flag'] != 'success') ? false : true;
$response = [
'success' => $isSuccess,
'response' => $isSuccess ? $result['response'] : $result,
];
return $response;
}
/**
* 确认回传方法
* @var array
*/
private static $callbackMethods = [
'taobao.qimen.deliveryorder.confirm' => 'saleOrderConfirm',
'taobao.qimen.entryorder.confirm' => 'stockInConfirm',
'taobao.qimen.itemlack.report' => 'itemLackReport',
'taobao.qimen.orderprocess.report' => 'orderProcessReport',
'taobao.qimen.returnorder.confirm' => 'saleReturnOrderConfirm',
'taobao.qimen.stockchange.report' => 'stockChangeReport',
'taobao.qimen.stockout.confirm' => 'stockOutConfirm',
];
public function callback($params)
{
if (!isset($params['method']) || empty($params['method'])) {
return $this->response('缺少参数method', false);
}
if (!isset($params['timestamp']) || empty($params['timestamp'])) {
return $this->response('缺少参数timestamp', false);
}
if (!isset($params['format']) || empty($params['format'])) {
return $this->response('缺少参数format', false);
}
if (!isset($params['app_key']) || empty($params['app_key'])) {
return $this->response('缺少参数key', false);
}
if (!isset($params['v']) || empty($params['v'])) {
return $this->response('缺少版本参数', false);
}
if (!isset($params['sign']) || empty($params['sign'])) {
return $this->response('缺少参数sign', false);
}
if (!isset($params['sign_method']) || empty($params['sign_method'])) {
return $this->response('缺少加密方式', false);
}
if (!isset($params['customerId']) || empty($params['customerId'])) {
return $this->response('缺少参数customerId', false);
}
if (empty(($params['body']))) {
return $this->response('缺少消息body', false);
}
$method = $params['method'];
if (!array_key_exists($method, self::$callbackMethods)) {
return $this->response('调用的方法不存在', false);
}
if (!$this->checkSign($params)) {
return $this->response('签名错误', false);
}
$body = XML2Array::createArray($params['body']);
if (!isset($body['request']) || empty($body['request'])) {
return $this->response('消息body错误', false);
}
$result = call_user_func([$this, self::$callbackMethods[$method]], $body['request']);
return $result;
}
/**
* 发货单确认
* @param $params
* @return array
*/
private function saleOrderConfirm ($params)
{
$service = new OrderService();
$result = $service->deliverOrderConfirm($params);
if (!$result) {
return $this->response('失败', false);
}
return $this->response();
}
/**
* 入库单确认
* @param $params
* @return array
*/
private function stockInConfirm($params)
{
$service = new GoodsWarehouseService();
$result = $service->entryorderConfirm($params);
if (!$result) {
return $this->response('失败', false);
}
return $this->response();
}
/**
* 发货单缺货通知
* @param $params
* @return array
*/
private function itemLackReport($params)
{
$service = new OrderItemLackReportService();
$result = $service->createReceipts($params);
if (!$result) {
return $this->response('失败', false);
}
return $this->response();
}
/**
* 订单流水通知
* @param $params
* @return array
*/
private function orderProcessReport($params)
{
$service = new OrderProcessReportService();
$result = $service->orderProcessReport($params);
if (!$result) {
return $this->response('失败', false);
}
return $this->response();
}
/**
* 退货入库单确认
* @param $params
* @return array
*/
private function saleReturnOrderConfirm($params)
{
$service = new RefundService();
$result = $service->refundOrderConfirm($params);
if (!$result) {
return $this->response('失败', false);
}
return $this->response();
}
/**
* 库存异动通知
* @param $params
* @return array
*/
private function stockChangeReport($params)
{
$service = new GoodsWarehouseService();
$result = $service->StockChangeReport($params);
if (!$result) {
return $this->response('失败', false);
}
return $this->response();
}
/**
* 出库单确认
* @param $params
* @return array
*/
private function stockOutConfirm($params)
{
$service = new OrderService();
$result = $service->stockOutOrderConfirm($params);
if (!$result) {
return $this->response('失败', false);
}
return $this->response();
}
/**
* @检查签名
* @param $params
@ -469,18 +653,19 @@ class XinyiWms extends BaseWms implements WmsInterface
return true;
}
public function xmlPost($method, $params)
public function response($message = '成功', $flag = true)
{
$xml = Array2XML::createXML('request', $params);
$body = $xml->saveXML();
$res = $this->createSign($method, $body);
$result = $this->post($body, $res);
$isSuccess = (empty($result) || !is_array($result) || $result['response']['flag'] != 'success') ? false : true;
$response = [
'success' => $isSuccess,
'response' => $isSuccess ? $result['response'] : $result,
'flag' => $flag ? 'success' : 'failure',
'code' => $flag ? '001' : '002',
'message' => $message,
];
$xml = Array2XML::createXML('response', $response);
$body = $xml->saveXML();
return [
'content' => $body,
'status' => 200,
'headers' => ['Content-Type' => 'xml'],
];
return $response;
}
}