PHP code example of zicai / hongbao

1. Go to this page and download the library: Download zicai/hongbao library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

zicai / hongbao example snippets




use Hongbao\Hongbao;

/**
 * 生成随机红包
 */
$options = [
    'total_money' => 1000, // 总金额
    'total_number' => 1000, // 总红包数量
    'minimum_val' => 0.01, // 最小随机红包金额
    'maximum_val' => 20, // 最大随机红包金额
];

//通过try catch获取可能出现的参数设置错误信息
try {
    $hongbao = Hongbao::getInstance()->randomAmount($options);
    foreach ($hongbao as $result) {
        echo "<pre/>";
        print_r($result);
    }
} catch (\Exception $e) {
    $error = $e->getMessage();
    var_dump($error);
}



use Hongbao\Hongbao;

/**
 * 生成固定红包
 */

$options = [
    'total_money' => 1000, // 总金额
    'total_number' => 1000, // 总红包数量
    'val' => 0.01, // 单个红包金额
];

//通过try catch获取可能出现的参数设置错误信息
try {
    $hongbao = Hongbao::getInstance()->fixedAmount($options);
    foreach ($hongbao as $result) {
        echo "<pre/>";
        print_r($result);
    }
} catch (\Exception $e) {
    $error = $e->getMessage();
    var_dump($error);
}