dmitriymikheev/yii2-odysseq

用于在Yii2项目中集成Odysseq服务的工具包

安装: 2

依赖: 0

建议者: 0

安全性: 0

星标: 1

关注者: 1

分支: 0

开放问题: 0

类型:yii2-extension

1.1.1 2022-09-14 11:48 UTC

This package is auto-updated.

Last update: 2024-09-14 16:13:41 UTC


README

用于操作Odysseq服务的扩展

官方API文档

https://odysseq.com/api

安装

安装此扩展的首选方式是通过composer

运行以下命令之一:

composer require --prefer-dist dmitriymikheev/yii2-odysseq "*"

或者将以下内容添加到你的composer.json文件的require部分:

"dmitriymikheev/yii2-odysseq": "*"

to the require section of your composer.json file.

用法

将组件添加到你的应用程序配置文件中。

return [
    //some config code
    'components' => [
        'odysseq' => [
            'class' => 'dmitriymikheev\odysseq\OdysseqComponent',
            'access_token' => 'your_access_token',
            'notification_secret_key' => 'your_notification_secret_key',
        ],
    ]
    //some config code
];

要配置关于投标状态变化的通知,请在控制器中添加以下代码

1. 添加一个操作

public function actions()
{
    return [
        'odysseq-callback' => [
            'class' => \dmitriymikheev\odysseq\actions\CallbackAction::class,
            'callback' => [$this, 'successCallback'],
            'component_id' => 'odysseq' //component id that was specified in the config file
        ]
    ];
}

2. 添加VerbFilter

public function behaviors()
{
    return [
        'verbs' => [
            'class' => VerbFilter::className(),
            'actions' => [
                'odysseq-callback' => ['post'],
            ],
        ],
    ];
}

3. 禁用回调操作的csrf验证,如下所示

public function beforeAction($action)
{
    if ($action->id == 'odysseq-callback') {
        $this->enableCsrfValidation = false;
    }
    return parent::beforeAction($action);
}

4. 在控制器中添加一个回调函数。如果请求不是假的,它将被调用。

$model属性

  • orderId - 合作伙伴系统中投标的id
  • type - 操作类型 (IN | OUT)
  • amount - 交易金额
  • status - 操作状态 (WAITING | SENDING | SUCCESS | CANCELED)
  • errorCode - 错误代码
  • errorMessage - 错误信息
public function successCallback($model)
{
    //here you can change the status of the bid in your database
    
    //Remember that to inform the service about the successful processing of the notification, please return a json response {"status": 200}
    //Example:
    $response = Yii::$app->getResponse();
    $response->format = yii\web\Response::FORMAT_JSON;
    $response->data = ['status' => 200];
    return $response->send();
}

可用的公共方法