99 lines
3.1 KiB
PHP
99 lines
3.1 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @author Any
|
|
* @description KISS
|
|
* @date 2021年6月2日
|
|
* @version 1.0.0
|
|
*
|
|
* _____LOG_____
|
|
*
|
|
*/
|
|
namespace app\controllers\notify;
|
|
//use app\controllers\Controller;
|
|
|
|
use app\components\YopointApi;
|
|
|
|
class YopointNotifyController extends \yii\web\Controller
|
|
{
|
|
|
|
public function init() {
|
|
parent::init();
|
|
$this->enableCsrfValidation = false;
|
|
}
|
|
|
|
/**
|
|
* showdoc
|
|
*/
|
|
public function actionData()
|
|
{
|
|
$appid = \Yii::$app->request->post('appid','');
|
|
$method = \Yii::$app->request->post('method','');
|
|
$biz_content = \Yii::$app->request->post('biz_content','');
|
|
$timestamp = \Yii::$app->request->post('timestamp',0);
|
|
$sign_type = \Yii::$app->request->post('sign_type','');
|
|
$sign = \Yii::$app->request->post('sign','');
|
|
$yopoint_obj = new YopointApi();
|
|
$arr = [
|
|
'method' => $method,
|
|
'biz_content' => $biz_content,
|
|
'appid' => $yopoint_obj->appid,
|
|
'sign_type' => 'md5',
|
|
'timestamp' => $timestamp,
|
|
];
|
|
$sign_res = $yopoint_obj->getSign($arr);
|
|
if($sign_res != $sign){
|
|
return json_encode(['error_code'=>1,'error_msg'=>'sign verification fails']);
|
|
}
|
|
switch ($method){
|
|
case "notify.activity.voucher.exchangecode": # 当兑换码兑换成功并已出货的情况下触发
|
|
break;
|
|
case "notify.consumer.order.simple": # 当售货机有交易的时候触发
|
|
return json_encode(['error_code'=>1,'error_msg'=>'skip']); # 不进行操作
|
|
break;
|
|
case "notify.terminal.cargo.supplement": # 当售货机补货的时候触发
|
|
break;
|
|
case "notify.depot.pickup.return": # 当补货员向仓库发起退货时触发
|
|
break;
|
|
case "notify.depot.changed": # 当仓库库存发生变化时触发
|
|
break;
|
|
case "notify.close.door": # 当自取柜关门成功后时触发
|
|
$this->notifyCloseDoor($biz_content);
|
|
break;
|
|
case "notify.cabinet.order.simple": # 当自取柜支付成功的时候触发
|
|
return json_encode(['error_code'=>1,'error_msg'=>'skip']); # 不进行操作
|
|
break;
|
|
}
|
|
$obj = new \app\models\YopointNotify();
|
|
$obj->appid = $appid;
|
|
$obj->method = $method;
|
|
$obj->biz_content = $biz_content;
|
|
$obj->timestamp = $timestamp;
|
|
$obj->sign_type = $sign_type;
|
|
$obj->sign = $sign;
|
|
$obj->created_at = time();
|
|
$obj->return_data = "";
|
|
$obj->type = 2;
|
|
$obj->save();
|
|
return json_encode(['error_code'=>0,'error_msg'=>'SUCCESS']);
|
|
}
|
|
|
|
/**
|
|
* 关柜后回调
|
|
*/
|
|
public function notifyCloseDoor($data){
|
|
if(empty($data)){
|
|
return false;
|
|
}
|
|
$json_de = json_decode($data,true);
|
|
if(empty($json_de)){
|
|
return false;
|
|
}
|
|
$redis_name = "cxgyc:YopointNotify:list";
|
|
\Yii::$app->redis->lpush($redis_name,$json_de['ReceiptNo']);
|
|
return true;
|
|
}
|
|
|
|
}
|
|
|