{"id":33997089,"url":"https://github.com/smile-yi/ytil","last_synced_at":"2026-05-29T22:32:47.277Z","repository":{"id":57053886,"uuid":"180527009","full_name":"smile-yi/Ytil","owner":"smile-yi","description":"PHP常用工具包","archived":false,"fork":false,"pushed_at":"2019-08-04T10:12:02.000Z","size":34,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-23T12:20:52.203Z","etag":null,"topics":["http","image","secret","upload","utils"],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/smile-yi.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-04-10T07:31:04.000Z","updated_at":"2019-08-04T10:12:04.000Z","dependencies_parsed_at":"2022-08-24T05:21:26.663Z","dependency_job_id":null,"html_url":"https://github.com/smile-yi/Ytil","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/smile-yi/Ytil","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smile-yi%2FYtil","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smile-yi%2FYtil/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smile-yi%2FYtil/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smile-yi%2FYtil/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smile-yi","download_url":"https://codeload.github.com/smile-yi/Ytil/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smile-yi%2FYtil/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":27702793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-13T02:00:09.769Z","response_time":147,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","image","secret","upload","utils"],"created_at":"2025-12-13T08:53:32.487Z","updated_at":"2025-12-13T08:53:37.743Z","avatar_url":"https://github.com/smile-yi.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Ytil\n\n### PHP常用工具包(网络调用、参数校验)\n\n#### 安装方法\n```\ncomposer require smileyi/ytil\n```\n\n#### 基础配置\n```\nuse SmileYi\\Ytil\\Config;\n\nConfig::set([\n    'log' =\u003e [\n        // 日志存储路径\n        'dir' =\u003e dirname(__FILE__) . '/../extra/log/',\n    ],\n    'common' =\u003e [\n        //加密盐值\n        'salt' =\u003e '4ckNt8GrgvqXYg1u',\n    ],\n    'base64' =\u003e [\n        // 编码表\n        // 'map' =\u003e 'OBrsYZabgQRSTUtu3JnoPDChijklWApqKLM6Evw7Ncde45mxGHIfXyz012FV89+/',\n        'map' =\u003e 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',\n    ],\n    'upload' =\u003e [\n        // 上传目录\n        'dir' =\u003e dirname(__FILE__) . '/../extra/upload/',\n        // 允许的文件类型\n        'exts' =\u003e ['jpg', 'png', 'jpeg'], // 不限制: ['*']\n        // 文件大小限制\n        'size' =\u003e 1024 * 1024 * 2,\n    ],\n])\n```\n\n#### 工具列表\n-  网络调用\n-  参数验证\n-  Base64编码\n-  加密解密\n-  文件上传\n-  日志写入\n\n#### 具体用法\n##### Http调用\n```\nuse SmileYi\\Ytil\\Http;\nuse SmileYi\\Ytil\\Exception;\n\n$url = 'http://192.144.150.100/api.php?method=get\u0026task_id=1001';\n$header = [\n    'Content-type' =\u003e 'application/json',\n    'User-agent' =\u003e 'utils/http'\n];\n$body = [\n    'param1' =\u003e 'value1'\n];\n\n//代理配置\n//$proxy = 'http://xxx.xxx.xxx.xxx:8080'\n$proxy = null;\n\n//证书配置\n// $cert = [\n//     'ssl_cert' =\u003e 'path',\n//     'ssl_key' =\u003e 'path',\n//     'ca_info' =\u003e 'path'\n// ];\n$cert = null;\n\ntry {\n    //GET调用\n    $result = Http::get($url, $header, $proxy, $cert);\n    var_dump($result);\n\n    //POST调用\n    $result = Http::post($url, $body, $header, $proxy, $cert);\n    var_dump($result);\n\n    //并行调用\n    $multi = [];\n    $multi['name1'] = [\n        'method' =\u003e Http::METHOD_GET,\n        'url' =\u003e $url,\n        'header' =\u003e $header\n    ];\n    $multi['name2'] = [\n        'method' =\u003e Http::METHOD_POST,\n        'url' =\u003e $url,\n        'header' =\u003e $header,\n        'body' =\u003e $body\n    ];\n\n    $result = Http::multi($multi);\n    var_dump($result);\n}catch(Exception $e){\n    echo \"Errno:\" . $e-\u003egetCode() . \" Error:\" . $e-\u003egetMessage().\"\\n\";\n}\n```\n\n##### 日志写入\n```\nuse SmileYi\\Ytil\\Log;\n\nLog::getInstance()-\u003eput('user', ['nickname' =\u003e 'smileyi', 'sex' =\u003e 1]);\n```\n\n##### 常用工具\n```\nuse SmileYi\\Ytil\\Common;\n\n# 加密解密\n$t = 'hahaha';\n$dt = Common::encrypt($t);\n$et = Common::decrypt($dt);\necho \"secret text:\" . $dt . \"\\n\";\necho \"text:\" . $et . \"\\n\\n\";\n\n# 耗时计算\nCommon::exeTime('_start');\nsleep(0.1);\nCommon::exeTime('_end');\necho \"Exe time is:\" . Common::exeTime('_start', '_end') . \"s\\n\\n\";\n\n# 获取随机长度字符串\necho \"random string is:\" . Common::randStr(10) . \"\\n\\n\";\n\n# 获取客户端IP\necho \"client ip is:\" . Common::getClientIp() . \"\\n\\n\";\n```\n\n##### Base64编码解码\n```\nuse SmileYi\\Ytil\\Base64;\n\n$text = 'smileyi';\n\n# 编码\n$dt = Base64::encode($text);\n# 解码\n$et = Base64::decode($dt);\n\necho \"text base64 encode is:\" . $dt . \"\\n\";\necho \"text is:\" . $et . \"\\n\\n\";\n```\n\n##### 参数校验\n```\nuse SmileYi\\Ytil\\Format;\n\n# 邮箱\n$bool = Format::isEmail('haha@gmail.com');\n\n# 手机号\n$bool = Format::isMobile('188xxxxxxxx');\n\n# url\n$bool = Format::isUrl('http://www.github.com/');\n\n# 身份证号\n$bool = Format::isIdCard('1775443288743221234');\n\n# 整数\n$bool = Format::isInteger(1001);\n\n# json\n$bool = Format::isJson('{\"name\":\"smileyi\"}');\n\n# 用户名(6-16位数字+字母+_)\n$bool = Format::isUsername('smileyi');\n\n# 密码(6-20位数字+字母+_)\n$bool = Format::isPassword('haha1234');\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmile-yi%2Fytil","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmile-yi%2Fytil","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmile-yi%2Fytil/lists"}