call-up-io/callup

此包最新版本(dev-main)没有可用的许可证信息。

dev-main 2021-09-06 12:10 UTC

This package is auto-updated.

Last update: 2024-09-06 19:20:49 UTC


README

PHP库,用于与CallUp服务交互。

内容

输入数据

CallUp 对象接受3个参数

  • params - 参数数组
  • dir - 配置文件目录
  • filename - 配置文件名称
new CallUp($params, $dir, $filename);

重要:如果没有指定params数组,则从文件中获取数据。如果文件参数未指定,则从项目根目录的.env文件中获取默认数据

示例

生成代码需要使用函数verify(string $phone)

其中

$phone - 需要发送验证码的手机号

try {
  $callUp = new CallUp();
  $r = $callUp->verify($phone);
  if ($r->hasErrors() === true) {
    throw new Exception($r->getErrors());
  }
} catch (Exception $e) {
  // some actions after catching the error
}

用于认证的函数是signIn(string $id, string $code)

其中

$id - 订单标识符

$code - 4位数字代码

try {
  $callUp = new CallUp();
  $r = $callUp->signIn($id, $code);
  if ($r->hasErrors() === true) {
    throw new Exception($r->getErrors());
  }
  if ($r->getData()['success'] === true) {
    // actions after successful authorization
  };
} catch (Exception $e) {
  // some actions after catching the error
}

测试

用于测试的库是PHPUnit 9

运行单元测试需要执行命令

> ./vendor/bin/phpunit tests

运行单独的单元测试需要执行命令

> ./vendor/bin/phpunit tests ./tests/unit/path/to/file.php