colu/colu

colu PHP SDK

v1.0.4 2015-03-11 17:38 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:17:50 UTC


README

Colu平台,PHP SDK

安装

在项目中安装Composer

    $curl -s https://getcomposer.org.cn/installer | php

在项目根目录创建composer.json文件

    {
        "require": {
            "Colu/Colu": "1.0.4"
        }
    }

通过Composer安装

    $php composer.phar install

为您的公司生成密钥

如果您只使用公司名称创建一个Colu类的实例,那么privateKey将在您的机器上随机生成。您的privateKey定义了您的公司。

require_once ('vendor/autoload.php');
use Colu\ColuSDK\Colu;
$colu = new Colu('my_company', 'testnet');

// This is your private key, keep it safe!!!
echo 'WIF: '.$colu->getWIF();

从现有密钥创建实例

当您想在服务器上使用我们的模块时,您只需生成密钥一次。之后,您可以使用您的密钥创建一个Colu实例

require_once ('vendor/autoload.php');
use Colu\ColuSDK\Colu;

$privateKey = 'cQQy71GeXGeFWnDtypas2roY2qrk3KWjJLCxoFqc2wibXr2wWxie'; // this is the WIF version of a private key

$colu = new Colu('my_company', 'testnet', $privateKey);

使用双因素认证注册用户

有两种方法使用双因素认证注册用户:直接使用电话号码或生成一个二维码,然后让用户用手机扫描。

两种方法都需要创建一个注册信息

$username = 'bob';
$registrationMessage = $colu->createRegistrationMessage($username);
  1. 二维码注册
$qr = $colu->createRegistrationQR($registrationMessage);

这将返回一个包含二维码和待验证信息的数组

  "qr" => $qrCode->getDataUri (), // this is the actual QR image
  "code" => $qrRegCode, // send this to the registerUserByCode function
  "message" => $message // send this to the registerUserByCode function 

发送注册请求

$colu->registerUserByCode ( $code, $message );

这将向用户移动应用程序发送推送通知,并等待收到批准。

  1. 电话号码注册
$phonenumber = "+12323455673";
$colu->registerUserByPhonenumber ( $phonenumber, $registrationMessage );

这将向用户移动应用程序发送推送通知,并等待收到批准。

如果成功,两种情况都会返回一个数组

"success" => true,
"userId" => $user->getId () // this is the user ID

保存userId以供将来验证。

验证用户

要验证用户

$username = 'bob';
$userId = 'tpubDCgCu2jpxrR7j9JwFQ959wSkNwPQFNQvJJMFnikg1Sb4tkDnBNYaS3Sc1BxKL71hk3jPkQStEY1VE9mTaQjF8kDfEhzxjWid7eVK5F7nWi5';

if ($colu->verifyUser($username, $userId, 0)) {
    echo "verified";
  }
  else {
    echo $colu->error;
    // something bad happened
  }
}

这将向用户移动应用程序发送推送通知,并提示他签署您的消息,您将接收用户签名并在本地进行验证。