snappdoctor / drcoder
1.0.3
2021-01-04 17:07 UTC
This package is auto-updated.
Last update: 2024-09-05 01:35:24 UTC
README
SnappDoctor 编码器包
此包处理并编码/解码任何数据。该包提供了一些用于编码/解码数据的驱动程序,以下将进行说明。
安装
首先,开发者必须知道哪个编码器类使用内置的哈希函数进行处理,因此根据您的PHP版本,您必须在设置中配置适当的哈希驱动程序;目前我们假设您使用的是PHP版本< 7.0,否则您必须手动启用基于您当前版本的mcrypt扩展。
通过composer安装
$ composer require snappdoctor/drcoder
如果需要,然后使用以下命令
$ php artisan vendor:publish
此包使用环境变量,编码/解码过程需要它才能工作,因此您必须将这些变量添加到您的.env文件中
ENCODER_SERVICE_IV=SECRET_IV ENCODER_SERVICE_KEY=SECRET_KEY ENCODER_SERVICE_MODE=SECRET_MODE ENCODER_SERVICE_SIGN=SECRET_SIGN ENCODER_SERVICE_BLOCK_SIZE=BLOCK_SIZE
最后,将您的包服务提供者注册到config/app.php提供者数组中。
它如何工作?
首先,调用服务
use DrCoder\EncoderService;
用于编码
$first = "encode_me_1"; $second = "encode_me_2"; $base64_encoded_array = EncoderService::driver(EncoderService::DRIVER_BASE64) ->encode([$first, $second]); $first_base64_encoded = $base64_encoded_array[0]; $second_base64_encoded = $base64_encoded_array[1]; $aes_encoded_array = EncoderService::driver(EncoderService::DRIVER_AES_SSL) ->encode([$first, $second]); $first_aes_encoded = $aes_encoded_array[0]; $second_aes_encoded = $aes_encoded_array[1];
用于解码
$first = "decode_me_1"; $second = "decode_me_2"; $base64_decoded_array = EncoderService::driver(EncoderService::DRIVER_BASE64) ->decode([$first, $second]); $first_base64_decoded = $base64_decoded_array[0]; $second_base64_decoded = $base64_decoded_array[1]; $aes_decoded_array = EncoderService::driver(EncoderService::DRIVER_BASE64) ->decode([$first, $second]); $first_aes_decoded = $aes_decoded_array[0]; $second_aes_decoded = $aes_decoded_array[1];
您还可以使用关联数组,并使用相同的索引键获取响应。更多示例文件请参阅这里以获取此包的更详细信息。