承接 sanchobbdo/codes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sanchobbdo/codes

Composer 安装命令:

composer require sanchobbdo/codes

包简介

Promotional codes generator and validator.

README 文档

README

A PHP code generator and validator. Can be use for promotions, sweepstakes, coupons or any other application which needs to validate codes provided by users.

Installing

Create a composer.json file in the project root:

{
    "require": {
        "sanchobbdo/codes": "~1.0"
    }
}

Then download composer.phar and run the install command:

curl -s http://getcomposer.org/installer | php && ./composer.phar install

Initialize

// Include composer's autoload
require 'vendor/autoload.php';

// Include codes builder
use SanchoBBDO\Codes\CodesBuilder;

// Create a Codes instance using the CodesBuilder.
$codes = CodesBuilder::buildCodes(array(
    'offset'     => 100,         // Start from
    'limit'      => 1000,        // How many codes to generate
    'coder'      => array(       // Coder settings
        'secret_key' => 'secret-key',    // Coder secret key
        'key_length' => 4,               // Code's key length
        'mac_length' => 6,               // Code's mac length
        'algo'       => 'sha1'           // Hash hmac algorithm
    )
));

The default coder generates codes composed of a key and a mac; the key identifies codes while the mac is used to validate them. The mac_length and key_length determine how long the code will be.

The mac is generated using the hash_hmac php function. The algorithm used is determined by algo. To see available algorithms check the hash_algos php function.

Validating codes

// Validate the given code using the coder
if ($codes->getCoder()->isValid($_POST['code'])) {
    // Do something on success
} else {
    // Do something on failure
}

Generating codes

From the command line:

Install symfony/console, symfony/yaml and sonata-project/exporter packages using composer:

composer require symfony/console:2.2.* \
                 symfony/yaml:2.2.* \
                 sonata-project/exporter:1.2.*

Create a config file somewhere in your project:

# /path/to/your/project/codes.yml

offset: 0
limit: 1000
coder:
    secret_key: your-secret-key
    key_length: 4
    mac_length: 6

From your project root:

# Dump to csv
./vendor/bin/codes dump:csv file.csv your/config/file.yml

# Dump to xls
./vendor/bin/codes dump:xls file.xls your/config/file.yml

From code:

Here is an example using the sonata-project/exporter (you can roll you're own implementation):

// On top of your file include required classes
use Exporter\Handler;
use Exporter\Writer\CsvWriter;
use SanchoBBDO\Codes\CodesSource;
$codesSource = new CodesSource($codes);
$writer = new CsvWriter('your-file.csv');
Handler::create($codesSource, $writer)->export();

Disclaimer

The software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.

License

Licensed under the MIT license.

统计信息

  • 总下载量: 73
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 9
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 8
  • Watchers: 3
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-03-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固