PHP code example of haleyleozhang / php_libary
1. Go to this page and download the library: Download haleyleozhang/php_libary 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/ */
haleyleozhang / php_libary example snippets
use HaleyLeoZhang\Helpers\ArrayHelper;
use HaleyLeoZhang\Helpers\CurlRequest;
use HaleyLeoZhang\Helpers\ExpectValue;
use HaleyLeoZhang\Helpers\Filter;
use HaleyLeoZhang\Helpers\Location;
use HaleyLeoZhang\Helpers\Token;
use HaleyLeoZhang\ThirdApi\ExpressDeliveryApi;
use HaleyLeoZhang\ThirdApi\KugouMusicApi;
use HaleyLeoZhang\ThirdApi\TuringRobotApi;
class App
{
public function run()
{
$this->token();
$this->___gap();
$this->expect_value();
$this->___gap();
$this->filter();
$this->___gap();
$this->get_ip();
$this->___gap();
$this->array_helper();
$this->___gap();
// ------------------- API类示例,请手动解开注释测试 -------------------
// $this->curl(); // 示例上传图片到 sm.ms
// $this->___gap();
// $this->delivery(); // 快递查询
// $this->___gap();
// $this->kugou(); // 酷狗音乐
// $this->___gap();
// $this->turning(); // 图灵机器人
// $this->___gap();
}
public function token()
{
echo "---- 测试随机数 ---- 即将输出: " . Token::rand_str();
}
public function expect_value()
{
$values = [5, 7, 9, 10, 6, 77, 1, 6, 33, 99, 1, 4, 7, 1, 5, 7, 20];
$expect = ExpectValue::compute($values);
echo "预期值: " . $expect;
}
public function filter()
{
$param = [
'id' => 1,
'name' => 'I am the bone of my sword',
];
try {
Filter::request($param, ['field' => 'id', 'type' => 'int', 'min' => 1, ' XMLHttpRequest",
'x-forward-for: 154.34.6.54',
];
$api = $base_api . '?' . http_build_query($get_param);
$content = CurlRequest::run($api, $post_param, $header);
echo '---当前上传结果---' . PHP_EOL;
echo $content;
}
public function delivery()
{
echo '---正在拉取快递信息---' . PHP_EOL;
try {
$track_number = 'YT4126633106250';
$list = ExpressDeliveryApi::run($track_number);
echo '---快递信息如下---' . PHP_EOL;
var_dump($list);
} catch (\Exception $exception) {
echo '---快递信息拉取.失败---' . PHP_EOL;
echo '异常:' . $exception->getMessage() . PHP_EOL;
echo '编号:' . $exception->getCode() . PHP_EOL;
echo '文件:' . $exception->getFile() . PHP_EOL;
echo '行数:' . $exception->getLine() . PHP_EOL;
}
}
public function kugou()
{
echo '---正在获取歌曲信息---' . PHP_EOL;
try {
$keyword = '刚好遇见你';
$singer = '曲肖冰';
$play_url = KugouMusicApi::run($keyword, $singer);
echo '---播放地址如下---' . PHP_EOL;
echo $play_url;
} catch (\Exception $exception) {
echo '---获取歌曲信息.失败---' . PHP_EOL;
echo '异常:' . $exception->getMessage() . PHP_EOL;
echo '编号:' . $exception->getCode() . PHP_EOL;
echo '文件:' . $exception->getFile() . PHP_EOL;
echo '行数:' . $exception->getLine() . PHP_EOL;
}
}
public function turning()
{
echo '---正在与图灵机器人对话---' . PHP_EOL;
try {
$trans_id = Token::uuid();
$question = '你叫什么名字';
$res = TuringRobotApi::get_instance()
->set_trans_id($trans_id)
->set_sentence($question)
->request(TuringRobotApi::API_TYPE_PUBLIC);
echo '---与图灵机器人对话结果如下---' . PHP_EOL;
var_dump($res);
} catch (\Exception $exception) {
echo '---与图灵机器人对话.失败---' . PHP_EOL;
echo '异常:' . $exception->getMessage() . PHP_EOL;
echo '编号:' . $exception->getCode() . PHP_EOL;
echo '文件:' . $exception->getFile() . PHP_EOL;
echo '行数:' . $exception->getLine() . PHP_EOL;
}
}
// ------------------------------------- Lib -------------------------------------
public function __construct()
{
//
}
protected function ___gap()
{
echo PHP_EOL . PHP_EOL . PHP_EOL . PHP_EOL;
}