├── .env ├── .gitignore ├── .htaccess ├── Dockerfile ├── LICENSE ├── README.md ├── app ├── admin │ └── ctrl │ │ └── monitor.php ├── cache │ ├── log │ │ └── .gitkeep │ └── tpl │ │ └── .gitkeep ├── common.php ├── common │ ├── BasePlatform.php │ ├── Encrypt.php │ ├── Error.php │ ├── PlatformLogin.php │ ├── api │ │ ├── BaiduPlatform.php │ │ ├── BilibiliPlatform.php │ │ ├── ChinaUnicomPlatform.php │ │ ├── V2EXPlatform.php │ │ └── WangyiPlatform.php │ ├── ctrl │ │ └── authCtrl.php │ └── model │ │ ├── log.php │ │ ├── platform.php │ │ └── user.php ├── index │ ├── common.php │ ├── config.php │ ├── ctrl │ │ ├── index.php │ │ └── user.php │ ├── model │ │ └── task.php │ └── tpl │ │ ├── index │ │ ├── bottom.html │ │ ├── index.html │ │ └── register.html │ │ └── user │ │ └── index.html └── install.php ├── db.sql ├── docker-compose.yml ├── icf ├── common │ └── common.php ├── config.php ├── functions.php ├── index.php ├── lib │ ├── db.php │ ├── db │ │ ├── mysql.php │ │ └── query.php │ ├── info │ │ ├── AliSms.php │ │ └── smtp.php │ ├── log.php │ ├── model.php │ ├── other │ │ ├── HttpHelp.php │ │ ├── ImageVerifyCode.php │ │ └── http.php │ ├── route.php │ └── view.php └── loader.php ├── index.php ├── start.php └── static └── js └── jquery-3.3.1.min.js /.env: -------------------------------------------------------------------------------- 1 | DB_HOST=localhost 2 | DB_NAME=test 3 | DB_USER=root 4 | DB_PASSWORD= 5 | DB_PREFIX=cas_ 6 | DB_PORT=3306 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | /app/cache/tpl/*.php 3 | *.log 4 | /icf/res 5 | config.php 6 | .env 7 | 8 | -------------------------------------------------------------------------------- /.htaccess: -------------------------------------------------------------------------------- 1 | 2 | Options +FollowSymlinks 3 | RewriteEngine On 4 | 5 | RewriteCond %{REQUEST_FILENAME} !-d 6 | RewriteCond %{REQUEST_FILENAME} !-f 7 | RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L] 8 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM codfrm/nginx-php 2 | 3 | LABEL maintainer="CodFrm " 4 | 5 | WORKDIR /var/www 6 | 7 | ENV DB_HOST='127.0.0.1'\ 8 | DB_USER='root'\ 9 | DB_PASSWORD=''\ 10 | DB_NAME='cas' \ 11 | DB_PREFIX='cas_'\ 12 | DB_PORT='3306' 13 | 14 | RUN apk add --no-cache git \ 15 | && rm -rf html/ \ 16 | && git clone https://github.com/CodFrm/cas.git /var/www/html \ 17 | && cd html \ 18 | && apk del git \ 19 | && chown www .env 20 | 21 | ENTRYPOINT php-fpm && nginx && cd html/ \ 22 | && echo -e "DB_HOST=${DB_HOST}\nDB_USER=${DB_USER}\nDB_NAME=${DB_NAME}\nDB_PASSWORD=${DB_PASSWORD}\nDB_PREFIX=${DB_PREFIX}\nDB_PORT=${DB_PORT}" > .env \ 23 | && php app/install.php \ 24 | && php start.php 25 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![](https://images.microbadger.com/badges/image/codfrm/cas.svg)](https://microbadger.com/images/codfrm/cas "Get your own image badge on microbadger.com") 2 | [![](https://images.microbadger.com/badges/version/codfrm/cas.svg)](https://microbadger.com/images/codfrm/cas "Get your own version badge on microbadger.com") 3 | [![GitHub stars](https://img.shields.io/github/stars/CodFrm/cas.svg)](https://github.com/CodFrm/cas/stargazers) 4 | [![GitHub license](https://img.shields.io/github/license/CodFrm/cas.svg)](https://github.com/CodFrm/cas/blob/master/LICENSE) 5 | 6 | 7 | # 云签到 8 | 9 | > cas(cloud add sign) 10 | > 11 | > emmmm....... 12 | 13 | 主要是利用php来设置一个定时任务,实现每日签到 14 | 15 | 然后就是签到的封包了 16 | 17 | 不过php是单线程的,效率挺低,后面可以改成多进程的模式提高效率 18 | 19 | 监控文件:app\admin\ctrl\monitor.php 20 | 21 | 使用cli模式运行 22 | 23 | 总之现在是一个很不完善的玩意=_= 24 | 25 | ## 安装 26 | 将源码克隆至自己的服务器,根目录下的db.sql为数据库结构文件 27 | 28 | 利用phpmyadmin或其他工具将db.sql导入到数据库 29 | 30 | 修改更目录下的```.env```文件,修改数据库配置部分 31 | 32 | config为读取数据库cas_config中的pwd_encode_salt字段 33 | 34 | ### 启动 35 | 使用php运行目录下的start.php文件,即可启动监控 36 | 37 | ```base 38 | php start.php 39 | //注意后台运行 40 | nohup php start.php > /dev/null 2>&1 & 41 | ``` 42 | 43 | 在```app/cache/log/year/month/```目录下,可以看到运行日志 44 | 45 | 在表```cas_log```中可以看到详细的数据 46 | 47 | 如果启动不成功,请在数据库中修```改cas_config```表的```monitor_status```,值修改为0,重新启动 48 | 49 | 0为未启动,1为启动 50 | 51 | ## 容器 52 | 需要安装```docker```和```docker-compose``` 53 | 54 | 默认外部端口8088,具体可以修改目录下的```docker-compose.yml```文件 55 | ```shell 56 | docker-compose up -d 57 | ``` 58 | 59 | ## 添加平台 60 | 继承```app\common\BasePlatform```抽象类,实现里面的方法 61 | 62 | 在数据库cas_platform表中添加平台的信息,在cas_action中添加操作的信息 63 | 64 | 实现的类要放在app/common/api目录下 65 | 66 | ## 支持平台 67 | > 太久没更新有些失效了... 68 | 69 | - [x] 百度贴吧 70 | - [x] b站直播 71 | - [ ] 联通客户端 72 | **......** 73 | 74 | ## TODO 75 | > 先不挖太多坑了 76 | 77 | - [x] 优化操作流程 78 | - [x] CLI模式启动 79 | - [ ] 平台账号登录,更方便的添加账号 80 | 81 | -------------------------------------------------------------------------------- /app/admin/ctrl/monitor.php: -------------------------------------------------------------------------------- 1 | monitor(); 38 | } else if ($tmp_pid > 0) { 39 | $pid_list[] = $tmp_pid; 40 | } 41 | } 42 | foreach ($pid_list as $p) { 43 | pcntl_wait($p); 44 | } 45 | } else { 46 | $this->monitor(); 47 | } 48 | echo '监控停止'; 49 | } 50 | 51 | private function monitor() { 52 | $log = new log(); 53 | $log->notice('监控开启'); 54 | db::table('action_task')->where('task_status', 4)->update(['task_status' => 1]); 55 | while (1) { 56 | try { 57 | if (config('monitor_status') != 1) { 58 | //停止监控 59 | break; 60 | } 61 | if (date('H') < 3) { 62 | //3点开始 63 | sleep(90); 64 | continue; 65 | } 66 | $row = db::table('action_task') 67 | ->where('task_last_time', strtotime(date('Y/m/d 00:00:00')), '<') 68 | ->where('task_status', 1)->find(); 69 | if ($row) { 70 | db::table('action_task')->where('tid', $row['tid'])->update(['task_status' => 4]); 71 | $task = new task($row['tid']); 72 | $ret = $task->run(); 73 | $user_log = new \app\common\model\log($row['uid']); 74 | $user_log->action(json($ret), $ret['code']); 75 | if ($ret['code'] == 2) { 76 | //2为账号失效,将cookie关联的操作停止 77 | db::table('action_task')->where('puid', $row['puid']) 78 | ->update(['task_status' => 2]); 79 | } else { 80 | db::table('action_task')->where('tid', $row['tid']) 81 | ->update(['task_last_time' => time(), 'task_status' => 1]); 82 | } 83 | continue; 84 | } 85 | } catch (\Exception $e) { 86 | db::reconnect();//数据库重连 87 | $log->error(json(['msg' => '监控错误', 'file' => $e->getFile(), 'line' => $e->getLine(), 'error' => $e->getMessage()])); 88 | } 89 | sleep(10); 90 | } 91 | $log->notice('监控停止'); 92 | config('monitor_status', 0); 93 | } 94 | 95 | } -------------------------------------------------------------------------------- /app/cache/log/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodFrm/cas/eb6e54a28801743f53f3698cfaca0dc5b48fa59e/app/cache/log/.gitkeep -------------------------------------------------------------------------------- /app/cache/tpl/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodFrm/cas/eb6e54a28801743f53f3698cfaca0dc5b48fa59e/app/cache/tpl/.gitkeep -------------------------------------------------------------------------------- /app/common.php: -------------------------------------------------------------------------------- 1 | '; 13 | } 14 | 15 | function _css($file) { 16 | return ''; 17 | } 18 | 19 | /** 20 | * 对变量进行验证 21 | * @author Farmer 22 | * @param $array 23 | * @param $mode 24 | * @return bool 25 | */ 26 | function verify($array, $mode, &$data = '') { 27 | foreach ($mode as $key => $value) { 28 | if (is_string($value)) { 29 | if (empty($array[$key])) { 30 | return $value; 31 | } 32 | } else if (is_array($value)) { 33 | if (empty($array[$key])) { 34 | return $value['msg']; 35 | } 36 | if (!empty($value['regex'])) {//正则 37 | if (!preg_match($value['regex'][0], $array[$key])) { 38 | return $value['regex'][1]; 39 | } 40 | } 41 | if (!empty($value['func'])) {//对函数处理 42 | $tmpFunction = $value['func']; 43 | $funName = $value['func'][0]; 44 | $parameter = array(); 45 | unset($tmpFunction[0]); 46 | $parameter[] = $array[$key]; 47 | foreach ($tmpFunction as $v) { 48 | $parameter[] = $array[$v]; 49 | } 50 | $tmpValue = call_user_func_array($funName, $parameter); 51 | if ($tmpValue !== true) { 52 | return $tmpValue; 53 | } 54 | } 55 | if (!empty($value['enum'])) {//判断枚举类型 56 | if (!in_array($array[$key], $value['enum'][0])) { 57 | return $value['enum'][1]; 58 | } 59 | } 60 | if (!empty($value['sql'])) {//将其复制给sql插入数组 61 | $data[$value['sql']] = $array[$key]; 62 | } 63 | } 64 | } 65 | return true; 66 | } 67 | 68 | /** 69 | * 取中间文本 70 | * @author Farmer 71 | * @param $str 72 | * @param $left 73 | * @param $right 74 | * @return bool|string 75 | */ 76 | function getStrMid($str, $left, $right) { 77 | $lpos = strpos($str, $left); 78 | if ($lpos === false) { 79 | return false; 80 | } 81 | $rpos = strpos($str, $right, $lpos + strlen($left)); 82 | if ($rpos === false) { 83 | return false; 84 | } 85 | return substr($str, $lpos + strlen($left), $rpos - $lpos - strlen($left)); 86 | } 87 | 88 | /** 89 | * 取随机字符串 90 | * @author Farmer 91 | * @param $length 92 | * @param $type 93 | * @return string 94 | */ 95 | function getRandString($length, $type = 2) { 96 | $randString = '1234567890qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM'; 97 | $retStr = ''; 98 | $type = 9 + $type * 26; 99 | for ($n = 0; $n < $length; $n++) { 100 | $retStr .= substr($randString, mt_rand(0, $type), 1); 101 | } 102 | return $retStr; 103 | } 104 | 105 | /** 106 | * 获取/设置配置 107 | * @author Farmer 108 | * @param $key 109 | * @param string $value 110 | * @return int 111 | */ 112 | function config($key, $value = null) { 113 | if (!is_null($value)) { 114 | if (config($key) !== false) { 115 | return \icf\lib\db::table('config')->where(['key' => $key])->update(['value' => $value]); 116 | } else { 117 | return \icf\lib\db::table('config')->insert(['value' => $value, 'key' => $key]); 118 | } 119 | } else { 120 | $rec = \icf\lib\db::table('config')->where(['key' => $key])->find(); 121 | if (!$rec) { 122 | return false; 123 | } 124 | return $rec['value']; 125 | } 126 | } 127 | 128 | /** 129 | * 取出url中的路径 130 | * @return bool|string 131 | */ 132 | function getUrlRoot() { 133 | return substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')); 134 | } 135 | 136 | /** 137 | * 填充0 138 | * @param $str 139 | * @param $len 140 | * @return string 141 | */ 142 | function fillZero($str, $len) { 143 | for ($i = strlen($str); $i < $len; $i++) { 144 | $str = '0' . $str; 145 | } 146 | return $str; 147 | } -------------------------------------------------------------------------------- /app/common/BasePlatform.php: -------------------------------------------------------------------------------- 1 | cookie = $param; 24 | } else { 25 | $this->platAccount = db::table('platform_account')->where($param)->find(); 26 | $this->cookie = $this->platAccount['pu_cookie']; 27 | } 28 | } 29 | 30 | /** 31 | * 验证账号 32 | * @return mixed 33 | */ 34 | abstract public function VerifyAccount(); 35 | 36 | /** 37 | * 验证操作 38 | * @param $action 39 | * @return mixed 40 | */ 41 | abstract public function VerifyAction($action); 42 | 43 | /** 44 | * 验证操作结果 45 | * @param $actionRet 46 | * @return mixed 47 | */ 48 | abstract public function VerifyActionResult($actionRet); 49 | } -------------------------------------------------------------------------------- /app/common/Encrypt.php: -------------------------------------------------------------------------------- 1 | code = $code; 20 | $this->msg = $msg; 21 | $this->param = $param; 22 | } 23 | 24 | public function __toString() { 25 | // TODO: Implement __toString() method. 26 | header('Content-Type: application/json; charset=utf-8'); 27 | $json = array_merge(['code' => $this->code, 'msg' => $this->msg], $this->param); 28 | return json($json); 29 | } 30 | } -------------------------------------------------------------------------------- /app/common/PlatformLogin.php: -------------------------------------------------------------------------------- 1 | httpRequest = new http(); 21 | $this->httpRequest->https(); 22 | } 23 | 24 | public function VerifyAccount() { 25 | // TODO: Implement VerifyAccount() method. 26 | $this->httpRequest->setCookie($this->cookie); 27 | $this->httpRequest->setHeader([ 28 | 'Connection: keep-alive', 29 | 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36', 30 | 'Upgrade-Insecure-Requests: 1' 31 | ]); 32 | $data = $this->httpRequest->get('https://tieba.baidu.com/index/tbwise/forum'); 33 | return getStrMid($data, '?un=', '"'); 34 | } 35 | 36 | public function VerifyAction($action) { 37 | // TODO: Implement VerifyAction() method. 38 | switch ($action) { 39 | case 'SignTieba': 40 | { 41 | $this->httpRequest->setCookie($this->cookie); 42 | $this->httpRequest->setHeader([ 43 | 'Connection: keep-alive', 44 | 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36', 45 | 'Upgrade-Insecure-Requests: 1' 46 | ]); 47 | $data = $this->httpRequest->get('https://tieba.baidu.com/'); 48 | $data = getStrMid($data, "use('spage/widget/forumDirectory',", ");"); 49 | $tieba_arr = json_decode($data, true); 50 | $ret_arr = []; 51 | foreach ($tieba_arr['forums'] as $val) { 52 | $tmp_arr = [$val['forum_name'], $val['forum_id']]; 53 | $ret_arr[] = $tmp_arr; 54 | } 55 | return $ret_arr; 56 | } 57 | } 58 | return false; 59 | } 60 | 61 | public function VerifyActionResult($actionRet) { 62 | // TODO: Implement VerifyActionResult() method. 63 | if (isset($actionRet['ret']['error_msg'][0]['error_code'])) { 64 | if ($actionRet['ret']['error_msg'][0]['error_code'] == 1) { 65 | return 2; 66 | } 67 | return 0; 68 | } else if ($actionRet == []) { 69 | return 0; 70 | } 71 | if ($actionRet == []) { 72 | return 0; 73 | } 74 | return 1; 75 | } 76 | 77 | private $BDUSS; 78 | 79 | public function SignTieba($actMsg) { 80 | if (!($this->BDUSS = getStrMid($actMsg['pu_cookie'], 'BDUSS=', ';'))) { 81 | $this->BDUSS = substr($actMsg['pu_cookie'], strpos($actMsg['pu_cookie'], 'BDUSS=') + 6); 82 | } 83 | $msgJson = []; 84 | foreach ($actMsg['param'] as $value) { 85 | $ret = $this->sign_tieba($value[0], $value[1]); 86 | if ($ret !== true) { 87 | $msgJson['error_list'][] = $value[0]; 88 | $msgJson['error_msg'][] = $ret; 89 | } 90 | } 91 | return $msgJson; 92 | } 93 | 94 | public function getTbs() { 95 | $http = new http('http://tieba.baidu.com/dc/common/tbs'); 96 | $http->setHeader([ 97 | 'User-Agent: bdtb for Android 6.5.8', 'Referer: http://tieba.baidu.com/', 'X-Forwarded-For: 115.28.1.' . mt_rand(1, 255) 98 | ]); 99 | $http->setCookie("BDUSS=" . $this->BDUSS); 100 | $json = json_decode($http->get(), true); 101 | return $json['tbs']; 102 | } 103 | 104 | public function addTiebaSign(&$data) { 105 | $data = array( 106 | '_client_id' => '03-00-DA-59-05-00-72-96-06-00-01-00-04-00-4C-43-01-00-34-F4-02-00-BC-25-09-00-4E-36', 107 | '_client_type' => '4', 108 | '_client_version' => '6.0.1', 109 | '_phone_imei' => '540b43b59d21b7a4824e1fd31b08e9a6', 110 | ) + $data; 111 | $x = ''; 112 | foreach ($data as $k => $v) { 113 | $x .= $k . '=' . $v; 114 | } 115 | $data['sign'] = strtoupper(md5($x . 'tiebaclient!!!')); 116 | } 117 | 118 | public function sign_tieba($name, $fid) { 119 | $tbs = $this->getTbs(); 120 | $time = time() . rand(100, 999); 121 | $sign = 'BDUSS=' . urldecode($this->BDUSS) . 122 | '_client_id=wappc_1519637358655_406_client_type=2_client_version=9.3.8.0_phone_imei=000000000000000cuid=baidutiebaappa638e2bf-d021-4fd0-aa34-4d8e9b5cf991' . 123 | 'fid=' . $fid . 'from=1019960rkw=' . $name . 'model=Android SDK built for x86_64net_type=4stErrorNums=1stMethod=1stMode=1stSize=966stTime=98stTimesNum=1stoken=b399b18b5d887995e96efafadfe4b87186e9fc7b6006bd98333f2201783dae15' . 124 | 'tbs=' . $tbs . 'timestamp=' . $time . 'z_id=609C16C532BDDA19187A48FC6F100F36A5tiebaclient!!!'; 125 | $data = 'BDUSS=' . $this->BDUSS . 126 | '&_client_id=wappc_1519637358655_406&_client_type=2&_client_version=9.3.8.0&_phone_imei=000000000000000&cuid=baidutiebaappa638e2bf-d021-4fd0-aa34-4d8e9b5cf991' . 127 | '&fid=' . $fid . '&from=1019960r&kw=' . urlencode($name) . '&model=Android+SDK+built+for+x86_64&net_type=4&sign=' . md5($sign) . 128 | '&stErrorNums=1&stMethod=1&stMode=1&stSize=966&stTime=98&stTimesNum=1' . 129 | '&stoken=b399b18b5d887995e96efafadfe4b87186e9fc7b6006bd98333f2201783dae15&tbs=' . $tbs . '×tamp=' . $time . '&z_id=609C16C532BDDA19187A48FC6F100F36A5'; 130 | $data = $this->httpRequest->post('http://c.tieba.baidu.com/c/c/forum/sign', $data); 131 | $tmpJson = json_decode($data, true); 132 | if (isset($tmpJson['error_code']) && $tmpJson['error_code'] != 0) { 133 | $tmpJson['sign'] = $sign; 134 | return $tmpJson; 135 | } else { 136 | return true; 137 | } 138 | } 139 | } -------------------------------------------------------------------------------- /app/common/api/BilibiliPlatform.php: -------------------------------------------------------------------------------- 1 | httpRequest = new http(); 21 | $this->httpRequest->https(); 22 | } 23 | 24 | public function VerifyAccount() { 25 | // TODO: Implement VerifyAccount() method. 26 | $this->httpRequest->setCookie($this->cookie); 27 | $data = $this->httpRequest->get('https://api.bilibili.com/x/web-interface/nav'); 28 | return getStrMid($data, 'uname":"', '",'); 29 | } 30 | 31 | public function VerifyAction($action) { 32 | // TODO: Implement VerifyAction() method. 33 | 34 | return true; 35 | } 36 | 37 | public function VerifyActionResult($actionRet) { 38 | // TODO: Implement VerifyActionResult() method. 39 | if (isset($actionRet['code'])) { 40 | if ($actionRet['code'] == -401) { 41 | return 2; 42 | } else if ($actionRet['code'] != 0) { 43 | return 1; 44 | } 45 | return 0; 46 | } 47 | return 1; 48 | } 49 | 50 | public function SignLive($actMsg) { 51 | $cookie = $actMsg['pu_cookie']; 52 | $this->httpRequest->setCookie($cookie); 53 | $msgJson = $this->httpRequest->get('https://api.live.bilibili.com/sign/doSign'); 54 | return json_decode($msgJson, true); 55 | } 56 | 57 | } -------------------------------------------------------------------------------- /app/common/api/ChinaUnicomPlatform.php: -------------------------------------------------------------------------------- 1 | httpRequest = new http(); 25 | $this->httpRequest->https(); 26 | $this->httpRequest->setCookie($this->cookie); 27 | } 28 | 29 | public function VerifyAccount() { 30 | // TODO: Implement VerifyAccount() method. 31 | $u = getStrMid($this->cookie, 'u_account=', ';'); 32 | $data = 'showType=3&version=android%405.62&desmobile=' . urlencode($u); 33 | $data = $this->httpRequest->post('https://m.client.10010.com/mobileService/home/queryUserInfoFive.htm', $data); 34 | $data = json_decode($data, true); 35 | if (isset($data['data'])) { 36 | return $u; 37 | } 38 | return false; 39 | } 40 | 41 | private $resCookie; 42 | 43 | public function VerifyAction($action) { 44 | // TODO: Implement VerifyAction() method. 45 | switch ($action) { 46 | case 'SignLT': 47 | $this->httpRequest->responseHeader(); 48 | $this->httpRequest->setRedirection(0); 49 | $this->httpRequest->get('http://m.client.10010.com/mobileService//thirdRedirect.htm?redirect_uri=https://act.10010.com/SigninApp/signin/querySigninActivity.htm&version=android@5.62&desmobile=' . $this->platAccount['pu_u']); 50 | $location = getStrMid($this->httpRequest->getResponseHeader(), 'Location: ', "\r\n"); 51 | if ($location == '') { 52 | return false; 53 | } 54 | $this->httpRequest->get($location); 55 | $this->resCookie = $this->httpRequest->getCookie(); 56 | return true; 57 | } 58 | return false; 59 | } 60 | 61 | public function VerifyActionResult($actionRet) { 62 | // TODO: Implement VerifyActionResult() method. 63 | if (isset($actionRet['msgCode'])) { 64 | if ($actionRet['msgCode'] == '0008') { 65 | return 1; 66 | } 67 | return 0; 68 | } 69 | return 2; 70 | } 71 | 72 | public function SignLT($actMsg) { 73 | $this->httpRequest->setCookie($this->resCookie); 74 | $this->httpRequest->post("https://act.10010.com/SigninApp/signin/daySign.do", "className=btnPouplePost"); 75 | $data = $this->httpRequest->data(); 76 | return json_decode($data, true); 77 | } 78 | 79 | public function Login($u, $p, &$cookie) { 80 | // TODO: Implement Login() method. 81 | if (strpos($u, '@') !== false) { 82 | $u .= getRandString(6, 0); 83 | } 84 | 85 | $key = <<httpRequest->setCookie($tmpCookie); 108 | $this->httpRequest->setopt(CURLOPT_HEADER, true); 109 | $ret = $this->httpRequest->post('https://m.client.10010.com/mobileService/login.htm', $data); 110 | preg_match_all('/Set-Cookie:(.*);/iU', $ret, $matchCookie); 111 | foreach ($matchCookie[1] as $value) { 112 | $cookie .= $value . ';'; 113 | } 114 | $ret = json_decode(substr($ret, strpos($ret, '{"code"')), true); 115 | if ($ret['code'] == 0 && $ret['dsc'] == '') { 116 | return true; 117 | } 118 | return $ret['dsc']; 119 | } 120 | 121 | } -------------------------------------------------------------------------------- /app/common/api/V2EXPlatform.php: -------------------------------------------------------------------------------- 1 | httpRequest = new http(); 22 | $this->httpRequest->https(); 23 | } 24 | 25 | public function VerifyAccount() { 26 | // TODO: Implement VerifyAccount() method. 27 | $this->httpRequest->setCookie($this->cookie); 28 | $data = $this->httpRequest->get('https://www.v2ex.com/'); 29 | $matches = []; 30 | preg_match('/(.*?)<\/a>/', $data, $matches); 31 | if (isset($matches[2])) { 32 | return $matches[2]; 33 | } 34 | return false; 35 | } 36 | 37 | private $data; 38 | 39 | public function VerifyAction($action) { 40 | // TODO: Implement VerifyAction() method. 41 | switch ($action) { 42 | case 'SignV2EX': 43 | $this->httpRequest->setCookie($this->cookie); 44 | $this->httpRequest->setRedirection(4); 45 | $this->data = $this->httpRequest->get('https://www.v2ex.com/mission/daily'); 46 | if (strpos($this->data, '你要查看的页面需要先登录') !== false) { 47 | return false; 48 | } 49 | break; 50 | } 51 | return true; 52 | } 53 | 54 | public function VerifyActionResult($actionRet) { 55 | // TODO: Implement VerifyActionResult() method. 56 | return $actionRet; 57 | } 58 | 59 | public function SignV2EX($actMsg) { 60 | if ($signUrl = getStrMid($this->data, 'value="领取 X 铜币" onclick="location.href = \'', '\';"')) { 61 | $signUrl = 'https://www.v2ex.com' . $signUrl; 62 | } else { 63 | return 1; 64 | } 65 | $data = $this->httpRequest->get($signUrl); 66 | if (strpos($data, '已成功领取每日登录奖励') >= 0) { 67 | return 0; 68 | } 69 | return 1; 70 | } 71 | } -------------------------------------------------------------------------------- /app/common/api/WangyiPlatform.php: -------------------------------------------------------------------------------- 1 | httpRequest = new http(); 22 | $this->httpRequest->setHeader([ 23 | 'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.119 Safari/537.36', 24 | 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8' 25 | ]); 26 | } 27 | 28 | public function VerifyAccount() { 29 | // TODO: Implement VerifyAccount() method. 30 | $this->httpRequest->setCookie($this->cookie); 31 | $data = $this->httpRequest->get('http://music.163.com/'); 32 | return getStrMid($data, 'nickname:"', '",'); 33 | } 34 | 35 | public function VerifyAction($action) { 36 | // TODO: Implement VerifyAction() method. 37 | return true; 38 | } 39 | 40 | public function VerifyActionResult($actionRet) { 41 | // TODO: Implement VerifyActionResult() method. 42 | if (isset($actionRet['code'])) { 43 | if ($actionRet['code'] != 200) { 44 | if ($actionRet['code'] == 301) { 45 | return 2; 46 | } 47 | return 1; 48 | } 49 | return 0; 50 | } 51 | return 1; 52 | } 53 | 54 | public function SignMusic($actMsg) { 55 | $cookie = $actMsg['pu_cookie']; 56 | $this->httpRequest->setCookie($cookie); 57 | $csrf_token = getStrMid($cookie, '__csrf=', ';'); 58 | $this->httpRequest->setUrl('http://music.163.com/weapi/login/token/refresh?csrf_token=' . $csrf_token); 59 | $this->httpRequest->setCookie($cookie); 60 | $this->httpRequest->setopt(CURLOPT_HEADER, true); 61 | $post = 'params=' . 62 | urlencode(Encrypt::wy_encrypt(Encrypt::wy_encrypt('{"csrf_token":"' . $csrf_token . '"}', 63 | '0CoJUm6Qyw8W8jud'), 'OKZSxCIegROmuPzk')) . '&encSecKey=596a4853ee7618edb0192bc26b8ff9c88992b4e455c16585be0c41125f56f8dd7eeb9394e0bffc412801bf3ef2d86d52c50e5f19d3aab8e3cca724f9a2b0ac98718b961021e0d488fc1d63772a975841593f4094aa187989eae7f59fe68d3b7077393150b2f529f305fb89068f9ea35d2eacab9188ac8891e911e5513c098b3e'; 64 | $data = $this->httpRequest->post($post); 65 | $data = str_replace('__csrf=""', 'error', $data); 66 | $new_csrf_token = getStrMid($data, '__csrf=', ';'); 67 | $cookie = str_replace('__csrf=' . $csrf_token, '__csrf=' . $new_csrf_token, $cookie); 68 | $this->httpRequest->setCookie($cookie); 69 | $csrf_token = $new_csrf_token; 70 | $encText = Encrypt::wy_encrypt('{"type":1,"csrf_token":"' . $csrf_token . '"}', 71 | '0CoJUm6Qyw8W8jud'); 72 | $encText = Encrypt::wy_encrypt($encText, 'OKZSxCIegROmuPzk'); 73 | $this->httpRequest->setHeader(['Referer: http://music.163.com/discover']); 74 | $this->httpRequest->setopt(CURLOPT_HEADER, 0); 75 | $post = 'params=' . urlencode($encText) . '&encSecKey=596a4853ee7618edb0192bc26b8ff9c88992b4e455c16585be0c41125f56f8dd7eeb9394e0bffc412801bf3ef2d86d52c50e5f19d3aab8e3cca724f9a2b0ac98718b961021e0d488fc1d63772a975841593f4094aa187989eae7f59fe68d3b7077393150b2f529f305fb89068f9ea35d2eacab9188ac8891e911e5513c098b3e'; 76 | $msgJson = $this->httpRequest->post('http://music.163.com/weapi/point/dailyTask?csrf_token=' . $csrf_token, $post); 77 | return json_decode($msgJson, true); 78 | } 79 | 80 | } -------------------------------------------------------------------------------- /app/common/ctrl/authCtrl.php: -------------------------------------------------------------------------------- 1 | userMsg = db::table('users')->where('uid', _cookie('uid'))->find(); 26 | $this->uid = _cookie('uid'); 27 | } 28 | } -------------------------------------------------------------------------------- /app/common/model/log.php: -------------------------------------------------------------------------------- 1 | uid = $uid; 22 | $this->data['log_time'] = time(); 23 | } 24 | 25 | public function action($log, $status) { 26 | $this->data = array_merge(['uid' => $this->uid, 'log_content' => $log, 'log_type' => $status + 10], $this->data); 27 | return $this->add(); 28 | } 29 | 30 | public function system($log, $status) { 31 | $this->data = array_merge(['uid' => 0, 'log_content' => $log, 'log_type' => $status + 20], $this->data); 32 | return $this->add(); 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /app/common/model/platform.php: -------------------------------------------------------------------------------- 1 | $pid]); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /app/common/model/user.php: -------------------------------------------------------------------------------- 1 | $uid]); 19 | } 20 | } 21 | 22 | /** 23 | * 验证用户名 24 | * @author Farmer 25 | * @param $user 26 | * @return bool|string 27 | */ 28 | public static function isUser($user, $my = null) { 29 | if ($um = self::getUser($user)) { 30 | if (is_null($my)) { 31 | return '用户名已经被注册'; 32 | } 33 | return ($um['user'] == $my ?: '用户名已经被注册'); 34 | } else { 35 | return true; 36 | } 37 | } 38 | 39 | /** 40 | * 通过 邮箱/用户名/uid 获取用户数据 41 | * @param $user 42 | * @return mixed 43 | */ 44 | public static function getUser($user) { 45 | return db::table('users')->where('uid', $user)->_or()->where('username', $user)->_or()->where('email', $user)->find(); 46 | } 47 | 48 | public static function register($u, $p, $email) { 49 | db::table()->begin(); 50 | db::table('users')->insert([ 51 | 'username' => $u, 52 | 'password' => 'tmp', 53 | 'email' => $email, 54 | 'avatar' => 'default.png', 55 | 'reg_time' => time() 56 | ]); 57 | $uid = db::lastinsertid(); 58 | db::table('users')->where('uid', $uid)->update(['password' => self::encodePwd($uid, $p)]); 59 | db::table()->commit(); 60 | return $uid; 61 | } 62 | 63 | /** 64 | * 通过uid获取用户数据 65 | * @param $uid 66 | * @return mixed 67 | */ 68 | public static function uidUser($uid) { 69 | return db::table('users')->where(['uid' => $uid])->find(); 70 | } 71 | 72 | /** 73 | * 申请一个账号 74 | * @param $postData 75 | * @return bool 76 | */ 77 | public static function applyUser($postData) { 78 | $ret = verify($postData, [ 79 | 'act' => ['func' => [ 80 | function ($act, $email) { 81 | if (user::verifyToken($act, $email, 1)) { 82 | return true; 83 | } 84 | return '错误的令牌'; 85 | }, 'email'], 'msg' => '错误的令牌'], 86 | 'username' => ['func' => ['\app\common\model\user::isUser'], 'regex' => ['/^[\x{4e00}-\x{9fa5}\w\@\.]{2,16}$/u', '用户名格式错误'], 'msg' => '用户名不能为空', 'sql' => 'username'], 87 | 'password' => ['regex' => ['/^[\\~!@#$%^&*()-_=+|{}\[\], .?\/:;\'\"\d\w]{6,16}$/', '密码不符合规范'], 'msg' => '请输入密码', 'sql' => 'password'], 88 | 'email' => ['func' => ['\app\common\model\user::isEmail'], 'regex' => ['/^[\w\.]{1,16}@(qq\.com|foxmail.com|163\.com|outlook\.com)$/', '邮箱格式错误'], 'msg' => '邮箱不能为空', 'sql' => 'email'], 89 | ], $data); 90 | if ($ret === true) { 91 | //添加用户 92 | $data['avatar'] = 'default.png'; 93 | $data['reg_time'] = time(); 94 | db::table('users')->insert($data); 95 | $uid = db::table()->lastinsertid(); 96 | user::deleteToken($postData['act']); 97 | return true; 98 | } 99 | return $ret; 100 | } 101 | 102 | /** 103 | * 创建一个验证令牌 104 | * @param $val 105 | * @param int $type 106 | * @return string 107 | */ 108 | public static function createToken($val, $type = 0) { 109 | $len = 16; 110 | if ($type == 1) { 111 | $len = 64; 112 | \icf\lib\db::table('token')->where(['type' => 1, 'value' => $val])->delete(); 113 | } 114 | $token = ''; 115 | do { 116 | $token = getRandString($len, 2); 117 | } while (\icf\lib\db::table('token')->where('token', $token)->count()); 118 | \icf\lib\db::table('token')->insert(['token' => $token, 'value' => $val, 'time' => time(), 'type' => $type]); 119 | return $token; 120 | } 121 | 122 | /** 123 | * 验证token是否有效,返回token数量 124 | * @param $token 125 | * @param $val 126 | * @param int $type 127 | * @return mixed 128 | */ 129 | public static function verifyToken($token, $val, $type = 0) { 130 | $db = \icf\lib\db::table('token'); 131 | $db->where(['token' => $token, 'value' => $val]); 132 | if ($type == 1) { 133 | $db->where('time', time() - 1800, '>');//30分钟有效期 134 | } else { 135 | $db->where('time', time() - 432000, '>');//5天有效期 136 | } 137 | return $db->count(); 138 | } 139 | 140 | /** 141 | * 删除令牌 142 | * @param $token 143 | */ 144 | public static function deleteToken($token) { 145 | \icf\lib\db::table('token')->where('token', $token)->delete(); 146 | } 147 | 148 | /** 149 | * 验证邮箱 150 | * @author Farmer 151 | * @param $user 152 | * @return bool|string 153 | */ 154 | public static function isEmail($email) { 155 | if (self::getUser($email)) { 156 | return '邮箱已经被注册'; 157 | } else { 158 | return true; 159 | } 160 | } 161 | 162 | /** 163 | * 判断是否登陆 164 | * @return bool|mixed 165 | */ 166 | public static function isLogin() { 167 | if ($uid = _cookie('uid') && $token = _cookie('token')) { 168 | return self::verifyToken(_cookie('token'), _cookie('uid')); 169 | } 170 | return false; 171 | } 172 | 173 | /** 174 | * 编码密码 175 | * @author Farmer 176 | * @param $uid 177 | * @param $pwd 178 | * @return string 179 | */ 180 | public static function encodePwd($uid, $pwd) { 181 | $str = hash('sha256', $uid . $pwd . config('pwd_encode_salt')); 182 | return $str; 183 | } 184 | } -------------------------------------------------------------------------------- /app/index/common.php: -------------------------------------------------------------------------------- 1 | true, 13 | ]; -------------------------------------------------------------------------------- /app/index/ctrl/index.php: -------------------------------------------------------------------------------- 1 | display(); 21 | } 22 | 23 | protected function errorCode($code, $error = '') { 24 | //方便前端通过错误代码提示错误 25 | $errorCode = [ 26 | '登录成功' => 0, 27 | '注册成功' => 0, 28 | '用户名已经被注册' => 10001, 29 | '用户名不能为空' => 10002, 30 | '用户名格式错误' => 10003, 31 | '用户不存在' => 10003, 32 | '密码不符合规范' => 10004, 33 | '密码错误' => 10005, 34 | '请输入密码' => 10006, 35 | '邮箱格式不正确' => 10007, 36 | '错误的令牌' => 10020 37 | ]; 38 | if (empty($error)) { 39 | $error = $code; 40 | $code = -1; 41 | } 42 | if (isset($errorCode[$error])) $code = $errorCode[$error]; 43 | return ['code' => $code, 'msg' => $error]; 44 | } 45 | 46 | public function login() { 47 | $ret = verify($_POST, [ 48 | 'u' => ['msg' => '用户名不能为空', 'sql' => 'username'], 49 | 'p' => ['regex' => ['/^[\\~!@#$%^&*()-_=+|{}\[\], .?\/:;\'\"\d\w]{6,16}$/', '密码不符合规范'], 'msg' => '请输入密码', 'sql' => 'password'] 50 | ], $data); 51 | if ($ret === true) { 52 | if ($userMsg = user::getUser($data['username'])) { 53 | if (user::encodePwd($userMsg['uid'], $data['password']) == $userMsg['password']) { 54 | setcookie('token', user::createToken($userMsg['uid']), time() + 432000, getUrlRoot()); 55 | setcookie('uid', $userMsg['uid'], time() + 432000, getUrlRoot()); 56 | $ret = '登录成功'; 57 | } else { 58 | $ret = '密码错误'; 59 | } 60 | } else { 61 | $ret = '用户不存在'; 62 | } 63 | } 64 | return self::errorCode($ret); 65 | } 66 | 67 | public function register() { 68 | view()->display(); 69 | } 70 | 71 | public function postRegister() { 72 | $ret = verify($_POST, [ 73 | 'u' => ['msg' => '用户名不能为空', 'sql' => 'username'], 74 | 'p' => ['regex' => ['/^[\x20-\x7e]{6,16}$/', '密码不符合规范'], 'msg' => '请输入密码', 'sql' => 'password'], 75 | 'email' => [ 76 | 'regex' => ['/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/', '邮箱格式不正确'], 77 | 'msg' => '请输入邮箱', 78 | 'sql' => 'email' 79 | ] 80 | ], $data); 81 | if ($ret === true) { 82 | if ($userMsg = user::getUser($data['username'])) { 83 | $ret = '用户名已经被注册'; 84 | } else { 85 | if ($uid = user::register($data['username'], $data['password'], $data['email'])) { 86 | setcookie('token', user::createToken($uid), time() + 432000, getUrlRoot()); 87 | setcookie('uid', $userMsg['uid'], time() + 432000, getUrlRoot()); 88 | $ret = '注册成功'; 89 | } else { 90 | $ret = '注册失败'; 91 | } 92 | } 93 | } 94 | return self::errorCode($ret); 95 | } 96 | } -------------------------------------------------------------------------------- /app/index/ctrl/user.php: -------------------------------------------------------------------------------- 1 | assign('task', task::getUserAllTaskMsg($this->uid)); 25 | view()->assign('platform', db::table('platform')->select()->fetchAll()); 26 | view()->assign('account', db::table('platform_account as a') 27 | ->join(':platform as b', 'a.pid=b.pid') 28 | ->where('uid', $this->uid) 29 | ->select()->fetchAll()); 30 | view()->display(); 31 | } 32 | 33 | public function run($tid) { 34 | $task = new task($tid); 35 | $ret = $task->run(); 36 | if (isset($ret['ret']['error_msg'])) { 37 | unset($ret['ret']['error_msg']); 38 | } 39 | return $ret; 40 | } 41 | 42 | public function update_cookie() { 43 | $actDb = db::table('platform_account')->where('uid', $this->uid) 44 | ->where('puid', input('post.puid')); 45 | $ret = $actDb->find(); 46 | if (!$ret) { 47 | return new Error(-1, '没有找到相应的修改记录'); 48 | } 49 | if (input('post.cookie')) { 50 | $pid = $ret['pid']; 51 | $retUser = $this->verify_account($pid); 52 | if (is_array($retUser)) { 53 | $actDb->update(['pu_status' => 1, 'pu_time' => time(), 54 | 'pu_u' => $retUser['u'], 'pu_cookie' => input('post.cookie')]); 55 | db::table('action_task') 56 | ->where('puid', input('post.puid'))->update(['task_status' => 1]); 57 | $ret = new Error(0, '修改成功'); 58 | } else { 59 | $ret = new Error(-1, '错误的账号Cookie'); 60 | } 61 | } else { 62 | $actDb->delete(); 63 | $ret = new Error(1, '删除成功'); 64 | } 65 | return $ret; 66 | } 67 | 68 | public function postAccount() { 69 | $pid = _post('pid'); 70 | if (db::table('platform_account')->where('uid', _cookie('uid'))->where('pid', $pid)->count()) { 71 | return new Error(-1, '已经添加过一个账号'); 72 | } 73 | $ret = $this->verify_account($pid); 74 | if (is_array($ret)) { 75 | db::table('platform_account') 76 | ->insert(['pid' => $pid, 'pu_time' => time(), 'uid' => _cookie('uid'), 'pu_u' => $ret['u'], 77 | 'pu_status' => 1, 'pu_cookie' => _post('cookie')]); 78 | return new Error(0, '添加成功'); 79 | } else { 80 | return new Error(-1, $ret); 81 | } 82 | } 83 | 84 | public function getAction($pid) { 85 | return db::table('action')->where('pid', $pid)->select()->fetchAll(); 86 | } 87 | 88 | public function plogin($pid) { 89 | $plat = new platform($pid); 90 | if ($plat->getData()) { 91 | $platApi = 'app\\common\\api\\' . $plat->_api; 92 | $platApi = new $platApi('') ?: new BaiduPlatform(''); 93 | if ($platApi instanceof PlatformLogin) { 94 | return new Error(0, 'success', ['is_login' => 1]); 95 | } 96 | return new Error(-1, '没有账号登录的接口'); 97 | } 98 | return new Error(-1, '不存在的平台'); 99 | } 100 | 101 | public function postPlogin() { 102 | $plat = new platform(input('post.pid')); 103 | if ($plat->getData()) { 104 | $platApi = 'app\\common\\api\\' . $plat->_api; 105 | $platApi = new $platApi('') ?: new BaiduPlatform(''); 106 | if ($platApi instanceof PlatformLogin) { 107 | $ret = $platApi->Login(input('post.u'), input('post.p'), $cookie); 108 | if ($ret === true) { 109 | return new Error(0, '登录成功', ['cookie' => $cookie]); 110 | } 111 | return new Error(-2, '登录失败', ['status' => $ret]); 112 | } 113 | return new Error(-1, '没有账号登录的接口'); 114 | } 115 | return new Error(-1, '不存在的平台'); 116 | } 117 | 118 | public function postAction() { 119 | $pid = _post('pid'); 120 | $aid = _post('aid'); 121 | if (db::table('action_task')->where('uid', _cookie('uid'))->where('aid', $aid)->count()) { 122 | return new Error(-1, '已经添加过一次'); 123 | } 124 | if (!($accountRow = db::table('platform_account')->where(['pid' => $pid, 'uid' => _cookie('uid')])->find())) { 125 | return new Error(-1, '找不到账号'); 126 | } 127 | $ret = $this->verify_action($pid, $aid); 128 | if (is_array($ret)) { 129 | db::table('action_task') 130 | ->insert(['uid' => _cookie('uid'), 'puid' => $accountRow['puid'], 'aid' => $aid, 131 | 'task_param' => json($ret['param']), 'task_last_time' => 0, 'task_status' => 1]); 132 | return new Error(0, '添加成功'); 133 | } else { 134 | return new Error(-1, $ret); 135 | } 136 | 137 | } 138 | 139 | private function verify_action($pid, $aid) { 140 | $plat = new platform($pid); 141 | if ($plat->getData()) { 142 | if ($actionRow = db::table('action')->where(['aid' => $aid, 'pid' => $pid])->find()) { 143 | $platApi = 'app\\common\\api\\' . $plat->_api; 144 | /** @var BasePlatform $platApi */ 145 | $platApi = new $platApi(['uid' => _cookie('uid'), 'pid' => $pid]); 146 | if ($platData = $platApi->VerifyAction($actionRow['action_api'])) { 147 | return ['param' => $platData]; 148 | } else { 149 | return '操作错误'; 150 | } 151 | } else { 152 | return '操作不存在'; 153 | } 154 | } else { 155 | return '平台不存在'; 156 | } 157 | } 158 | 159 | private function verify_account($pid) { 160 | $plat = new platform($pid); 161 | if ($plat->getData()) { 162 | $platApi = 'app\\common\\api\\' . $plat->_api; 163 | $platApi = new $platApi(_post('cookie')) ?: new BaiduPlatform(_post('cookie')); 164 | if ($platData = $platApi->VerifyAccount()) { 165 | return ['u' => $platData]; 166 | } else { 167 | return '账号错误'; 168 | } 169 | } else { 170 | return '平台不存在'; 171 | } 172 | } 173 | } -------------------------------------------------------------------------------- /app/index/model/task.php: -------------------------------------------------------------------------------- 1 | tid = $tid; 24 | $this->data = db::table('action_task as a') 25 | ->join(':action as b', 'a.aid=b.aid') 26 | ->join(':platform as c', 'b.pid=c.pid') 27 | ->join(':platform_account as d', 'd.puid=a.puid') 28 | ->where('tid', $tid)->find(); 29 | } 30 | 31 | /** 32 | * @param int $uid 33 | * @param array $limit 34 | * @return array 35 | */ 36 | public static function getUserAllTaskMsg($uid, $limit = []) { 37 | return db::table('action_task as a')->join(':action as b', 'a.aid=b.aid') 38 | ->where('uid', $uid)->select()->fetchAll(); 39 | } 40 | 41 | public function getTaskActionApi() { 42 | return $this->data['action_api']; 43 | } 44 | 45 | public function getTaskPlatformApi() { 46 | return $this->data['platform_api']; 47 | } 48 | 49 | public function getCookie() { 50 | return $this->data['pu_cookie']; 51 | } 52 | 53 | public function run() { 54 | $platApi = 'app\\common\\api\\' . $this->getTaskPlatformApi(); 55 | $platApi = new $platApi(['puid' => $this->data['puid']]) ?: new BaiduPlatform(['puid' => $this->data['puid']]); 56 | $param = $platApi->VerifyAction($this->getTaskActionApi()); 57 | if ($param) { 58 | $row = $this->data; 59 | $row['param'] = $param; 60 | $param = json($param); 61 | db::table('action_task')->where('tid', $this->tid)->update(['task_param' => $param]); 62 | $row['task_param'] = $param; 63 | $ret = call_user_func([ 64 | $platApi, $this->getTaskActionApi() 65 | ], $row); 66 | $result = $platApi->VerifyActionResult($ret); 67 | $status = ['成功', '签过到了|错误', '账号失效']; 68 | return ['code' => $result, 'aid' => $this->data['aid'], 'msg' => $status[$result], 'ret' => $ret]; 69 | } else { 70 | return ['code' => 2, 'aid' => $this->data['aid'], 'msg' => '账号失效']; 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /app/index/tpl/index/bottom.html: -------------------------------------------------------------------------------- 1 | 2 |

3 |

主要是利用php来设置一个定时任务,实现每日签到

4 |

然后就是签到的封包了

5 |

不过php是单线程的,效率挺低,后面可以改成多进程的模式提高效率

6 |

监控文件:app\admin\ctrl\monitor.php

7 |

总之现在是一个很不完善的玩意=_=

8 |

详细内容请看github上的说明

9 | 10 | 11 | -------------------------------------------------------------------------------- /app/index/tpl/index/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 云助手 6 | {:_js('jquery-3.3.1.min')} 7 | 8 | 9 |

页面就先随便弄一下,emmm

10 |
开源地址 欢迎给star 11 |

登录:

12 |
13 | 账号: 14 |

15 | 密码: 16 |

17 | 18 | 19 |
20 | 21 | 37 | {include 'bottom'} -------------------------------------------------------------------------------- /app/index/tpl/index/register.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 云助手 6 | {:_js('jquery-3.3.1.min')} 7 | 8 | 9 |

页面就先随便弄一下,emmm

10 | 开源地址 欢迎给star 11 |

注册:

12 |
13 | 账号: 14 |

15 | 密码: 16 |

17 | 邮箱: 18 |

19 | 20 | 21 |
22 | 23 | 39 | {include 'bottom'} -------------------------------------------------------------------------------- /app/index/tpl/user/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 云助手 6 | {:_js('jquery-3.3.1.min')} 7 | 8 | 9 |

添加账号

10 |
11 |
12 | 平台: 13 | 18 |

19 | Cookie: 20 |

21 | 22 |
23 |

添加操作

24 |
25 | 平台: 26 | 31 |

32 | 操作: 33 | 36 |

37 | 38 |
39 |
40 |

账号列表

41 | {foreach $account as $item} 42 |
43 | {$item['platform_name']}:{$item['pu_u']} 44 |
45 | 46 |
47 | {/foreach} 48 | 如果Cookie是空的则为删除 49 |
50 |

任务列表

51 | {foreach $task as $item} 52 |
53 | {$item['action_name']}{if $item['task_status']==2} 操作失效了,可能是你的cookie失效的原因,请更新cookie{/if} 54 |
55 | 56 |
57 | {/foreach} 58 | 59 | 164 | -------------------------------------------------------------------------------- /app/install.php: -------------------------------------------------------------------------------- 1 | query($sql); 36 | } catch (Throwable $exception) { 37 | 38 | } 39 | } 40 | unlink(__ROOT_ . '/app/install.php'); -------------------------------------------------------------------------------- /db.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Navicat MySQL Data Transfer 3 | 4 | Source Server : localhost_3306 5 | Source Server Version : 50505 6 | Source Host : localhost:3306 7 | Source Database : tmp 8 | 9 | Target Server Type : MYSQL 10 | Target Server Version : 50505 11 | File Encoding : 65001 12 | 13 | Date: 2018-04-04 12:52:52 14 | */ 15 | 16 | SET FOREIGN_KEY_CHECKS=0; 17 | 18 | -- ---------------------------- 19 | -- Table structure for cas_action 20 | -- ---------------------------- 21 | DROP TABLE IF EXISTS `cas_action`; 22 | CREATE TABLE `cas_action` ( 23 | `aid` int(11) NOT NULL AUTO_INCREMENT, 24 | `pid` int(11) NOT NULL, 25 | `action_name` varchar(45) NOT NULL, 26 | `action_description` text NOT NULL, 27 | `action_api` varchar(45) NOT NULL, 28 | PRIMARY KEY (`aid`) 29 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; 30 | 31 | -- ---------------------------- 32 | -- Records of cas_action 33 | -- ---------------------------- 34 | INSERT INTO `cas_action` VALUES ('1', '1', '贴吧签到', '每日自动签到关注的贴吧(每日只执行一次,新添加的贴吧第二天开始)', 'SignTieba'); 35 | INSERT INTO `cas_action` VALUES ('2', '2', 'bilibili直播签到', '每天自动签到', 'SignLive'); 36 | INSERT INTO `cas_action` VALUES ('3', '3', '网易云音乐签到', '每日自动签到网易云音乐', 'SignMusic'); 37 | INSERT INTO `cas_action` VALUES ('4', '4', 'V2EX每日任务', 'V2EX每日任务', 'SignV2EX'); 38 | 39 | -- ---------------------------- 40 | -- Table structure for cas_action_task 41 | -- ---------------------------- 42 | DROP TABLE IF EXISTS `cas_action_task`; 43 | CREATE TABLE `cas_action_task` ( 44 | `tid` int(11) unsigned NOT NULL AUTO_INCREMENT, 45 | `uid` int(11) unsigned NOT NULL, 46 | `aid` int(11) unsigned NOT NULL, 47 | `puid` int(11) unsigned NOT NULL, 48 | `task_param` text, 49 | `task_last_time` bigint(20) unsigned NOT NULL, 50 | `task_status` tinyint(4) NOT NULL, 51 | PRIMARY KEY (`tid`) 52 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 53 | 54 | -- ---------------------------- 55 | -- Records of cas_action_task 56 | -- ---------------------------- 57 | 58 | -- ---------------------------- 59 | -- Table structure for cas_config 60 | -- ---------------------------- 61 | DROP TABLE IF EXISTS `cas_config`; 62 | CREATE TABLE `cas_config` ( 63 | `key` varchar(255) NOT NULL, 64 | `value` text NOT NULL, 65 | PRIMARY KEY (`key`) 66 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 67 | 68 | -- ---------------------------- 69 | -- Records of cas_config 70 | -- ---------------------------- 71 | INSERT INTO `cas_config` VALUES ('monitor_status', '0'); 72 | INSERT INTO `cas_config` VALUES ('pwd_encode_salt', '#faxGht&cd'); 73 | 74 | -- ---------------------------- 75 | -- Table structure for cas_log 76 | -- ---------------------------- 77 | DROP TABLE IF EXISTS `cas_log`; 78 | CREATE TABLE `cas_log` ( 79 | `log_id` int(11) unsigned NOT NULL AUTO_INCREMENT, 80 | `uid` int(11) unsigned NOT NULL, 81 | `log_content` text NOT NULL, 82 | `log_type` tinyint(4) NOT NULL, 83 | `log_time` bigint(20) unsigned NOT NULL, 84 | PRIMARY KEY (`log_id`) 85 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 86 | 87 | -- ---------------------------- 88 | -- Records of cas_log 89 | -- ---------------------------- 90 | 91 | -- ---------------------------- 92 | -- Table structure for cas_platform 93 | -- ---------------------------- 94 | DROP TABLE IF EXISTS `cas_platform`; 95 | CREATE TABLE `cas_platform` ( 96 | `pid` int(11) unsigned NOT NULL AUTO_INCREMENT, 97 | `platform_name` varchar(45) NOT NULL, 98 | `platform_description` text NOT NULL, 99 | `platform_api` varchar(45) NOT NULL, 100 | PRIMARY KEY (`pid`) 101 | ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; 102 | 103 | -- ---------------------------- 104 | -- Records of cas_platform 105 | -- ---------------------------- 106 | INSERT INTO `cas_platform` VALUES ('1', '百度', '百度账号', 'BaiduPlatform'); 107 | INSERT INTO `cas_platform` VALUES ('2', 'bilibili', 'bilibili账号', 'BilibiliPlatform'); 108 | INSERT INTO `cas_platform` VALUES ('3', '网易云', '网易云账号操作', 'WangyiPlatform'); 109 | INSERT INTO `cas_platform` VALUES ('4', 'V2EX', '一个汇集各类奇妙好玩的话题和流行动向的网站', 'V2EXPlatform'); 110 | 111 | -- ---------------------------- 112 | -- Table structure for cas_platform_account 113 | -- ---------------------------- 114 | DROP TABLE IF EXISTS `cas_platform_account`; 115 | CREATE TABLE `cas_platform_account` ( 116 | `puid` int(10) unsigned NOT NULL AUTO_INCREMENT, 117 | `pid` int(10) unsigned NOT NULL, 118 | `uid` int(10) unsigned NOT NULL, 119 | `pu_u` varchar(16) DEFAULT NULL, 120 | `pu_p` varchar(16) DEFAULT NULL, 121 | `pu_cookie` text, 122 | `pu_time` bigint(20) unsigned NOT NULL, 123 | `pu_status` tinyint(4) NOT NULL, 124 | PRIMARY KEY (`puid`) 125 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 126 | 127 | -- ---------------------------- 128 | -- Records of cas_platform_account 129 | -- ---------------------------- 130 | 131 | -- ---------------------------- 132 | -- Table structure for cas_token 133 | -- ---------------------------- 134 | DROP TABLE IF EXISTS `cas_token`; 135 | CREATE TABLE `cas_token` ( 136 | `token` varchar(128) NOT NULL, 137 | `value` varchar(64) NOT NULL, 138 | `time` bigint(20) unsigned NOT NULL, 139 | `type` int(4) NOT NULL COMMENT '0 user login 1 email', 140 | PRIMARY KEY (`token`) 141 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 142 | 143 | -- ---------------------------- 144 | -- Records of cas_token 145 | -- ---------------------------- 146 | 147 | -- ---------------------------- 148 | -- Table structure for cas_users 149 | -- ---------------------------- 150 | DROP TABLE IF EXISTS `cas_users`; 151 | CREATE TABLE `cas_users` ( 152 | `uid` int(11) unsigned NOT NULL AUTO_INCREMENT, 153 | `username` varchar(32) NOT NULL, 154 | `password` varchar(128) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, 155 | `email` varchar(64) NOT NULL, 156 | `avatar` varchar(128) NOT NULL, 157 | `reg_time` bigint(20) NOT NULL, 158 | PRIMARY KEY (`uid`) 159 | ) ENGINE=InnoDB DEFAULT CHARSET=utf8; 160 | 161 | -- ---------------------------- 162 | -- Records of cas_users 163 | -- ---------------------------- 164 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | db: 4 | image: "mysql:5.5" 5 | environment: 6 | MYSQL_DATABASE: cas 7 | MYSQL_ROOT_PASSWORD: cas_docker_pwd 8 | networks: 9 | - cas_network 10 | 11 | web: 12 | image: "codfrm/cas" 13 | environment: 14 | DB_HOST: "db" 15 | DB_USER: "root" 16 | DB_PASSWORD: "cas_docker_pwd" 17 | DB_NAME: "cas" 18 | ports: 19 | - 8088:80 20 | depends_on: 21 | - db 22 | networks: 23 | - cas_network 24 | 25 | networks: 26 | cas_network: 27 | driver: bridge 28 | -------------------------------------------------------------------------------- /icf/common/common.php: -------------------------------------------------------------------------------- 1 | $value) { 141 | $url .= "{$p_left}{$key}{$p_mid}{$value}"; 142 | } 143 | return $url; 144 | } 145 | 146 | 147 | function _404() { 148 | \icf\lib\other\HttpHelp::setStatusCode(404); 149 | echo '404'; 150 | } 151 | 152 | 153 | /** 154 | * 更深层次的合并两个数组 155 | * @param array $array1 156 | * @param array $array2 157 | * @return array 158 | */ 159 | function array_merge_in($array1, $array2 = null) { 160 | $towArr = []; 161 | foreach ($array1 as $key => $value) { 162 | if (is_array($value) && isset($array2[$key])) { 163 | $towArr[$key] = array_merge_in($array1[$key], $array2[$key]); 164 | } 165 | } 166 | $tmpArr = array_merge($array1, $array2); 167 | if ($towArr != []) { 168 | $towArr = array_merge($tmpArr, $towArr); 169 | } else { 170 | $towArr = $tmpArr; 171 | } 172 | return $towArr; 173 | } 174 | -------------------------------------------------------------------------------- /icf/config.php: -------------------------------------------------------------------------------- 1 | true, 13 | 'db' => [ 14 | 'type' => 'mysql', 15 | 'server' => env('DB_HOST'), 16 | 'port' => env('DB_PORT'), 17 | 'db' => env('DB_NAME'), 18 | 'user' => env('DB_USER'), 19 | 'pwd' => env('DB_PASSWORD'), 20 | 'prefix' => env('DB_PREFIX') 21 | ], 22 | 'rest' => true, 23 | 'module_key' => 'm', 24 | 'ctrl_key' => 'c', 25 | 'action_key' => 'a', 26 | 'route' => ['get' => ['start' => 'index->sign->start']], 27 | 'tpl_suffix' => 'html', 28 | 'log' => false, 29 | 'url_style' => 2 30 | ]; -------------------------------------------------------------------------------- /icf/functions.php: -------------------------------------------------------------------------------- 1 | notice('ip:' . getip() . ' url:' . getReqUrl() . ' post:' . json_encode($_POST, JSON_UNESCAPED_UNICODE) 59 | . ' cookie:' . json_encode($_COOKIE, JSON_UNESCAPED_UNICODE)); 60 | } 61 | //路由加载 62 | if (isset($config['route'])) { 63 | foreach ($config['route'] as $key => $item) { 64 | route::add($key, $item); 65 | } 66 | } 67 | route::analyze(); 68 | } 69 | } -------------------------------------------------------------------------------- /icf/lib/db.php: -------------------------------------------------------------------------------- 1 | lastinsertid(); 32 | } 33 | 34 | public static function reconnect(){ 35 | (new query())->reconnect(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /icf/lib/db/mysql.php: -------------------------------------------------------------------------------- 1 | setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 26 | self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 27 | } 28 | //处理表前缀 29 | $this->table = input('config.db.prefix') . str_replace('|', ',' . input('config.db.prefix'), $table); 30 | } 31 | 32 | public function reconnect() { 33 | try { 34 | static::$db = null; 35 | self::$db_type = input('config.db.type'); 36 | $dns = call_user_func('icf\\lib\\db\\' . self::$db_type . '::dns'); 37 | self::$db = new PDO($dns, input('config.db.user'), input('config.db.pwd')); 38 | self::$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 39 | self::$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 40 | }catch (\Exception $e){ 41 | return false; 42 | } 43 | return true; 44 | } 45 | 46 | private $table = ''; 47 | private $where = ''; 48 | private $field = ''; 49 | private $order = ''; 50 | private $limit = ''; 51 | private $join = ''; 52 | 53 | private $lastOper = 'and'; 54 | private $bindParam = []; 55 | 56 | /** 57 | * 条件 58 | * @author Farmer 59 | * @param $field 60 | * @param null $value 61 | * @param string $operator 62 | * @return $this 63 | */ 64 | public function where($field, $value = null, $operator = '=') { 65 | $this->where .= ' ' . (empty($this->where) ? '' : $this->lastOper . ' '); 66 | //恢复默认运算符 67 | $this->lastOper = 'and'; 68 | if (is_array($field)) { 69 | //获取最后一个 70 | $keys = array_keys($field); 71 | foreach ($field as $key => $item) { 72 | if (is_string($key)) { 73 | $this->where .= "`$key`$operator? "; 74 | $this->bindParam[] = $item; 75 | if ($key !== end($keys)) { 76 | $this->where .= 'and '; 77 | } 78 | } else if (is_numeric($key)) { 79 | $this->where .= "$item"; 80 | if ($key !== end($keys)) { 81 | $this->where .= 'and '; 82 | } 83 | } 84 | } 85 | } else if (is_string($field)) { 86 | if (is_null($value)) { 87 | $this->where .= $field; 88 | } else { 89 | $this->where .= " `$field`$operator?"; 90 | $this->bindParam[] = $value; 91 | } 92 | } 93 | return $this; 94 | } 95 | 96 | public function join($table, $on = '', $link = 'left') { 97 | if (is_array($table)) { 98 | foreach ($table as $key => $value) { 99 | if (is_string($key)) { 100 | $this->join .= " $link join `" . input('config.db.prefix') . $key . "` as $value " . (empty($on) ? '' : "on $on"); 101 | } else if (is_numeric($key)) { 102 | $this->join .= ' ' . $value; 103 | } 104 | } 105 | } else if (is_string($table)) { 106 | $table = str_replace(':', input('config.db.prefix'), $table); 107 | $this->join .= " $link join $table " . (empty($on) ? '' : "on $on"); 108 | } 109 | return $this; 110 | } 111 | 112 | /** 113 | * 插入数据 114 | * @author Farmer 115 | * @param array $items 116 | * @return bool|int 117 | */ 118 | public function insert(array $items) { 119 | if (!empty ($items)) { 120 | $param = []; 121 | $sql = 'insert into ' . $this->table . '(`' . implode('`,`', array_keys($items)) . '`) values('; 122 | foreach ($items as $value) { 123 | $sql .= '?,'; 124 | $param[] = $value; 125 | } 126 | $sql = substr($sql, 0, strlen($sql) - 1); 127 | $sql .= ')'; 128 | $result = self::$db->prepare($sql); 129 | if ($result->execute($param)) { 130 | return $result->rowCount(); 131 | } 132 | return false; 133 | } 134 | return false; 135 | } 136 | 137 | /** 138 | * and 139 | * @author Farmer 140 | * @return $this 141 | */ 142 | public function _and() { 143 | $this->lastOper = 'and'; 144 | return $this; 145 | } 146 | 147 | /** 148 | * or 149 | * @author Farmer 150 | * @return $this 151 | */ 152 | public function _or() { 153 | $this->lastOper = 'or'; 154 | return $this; 155 | } 156 | 157 | /** 158 | * 查询记录 159 | * @author Farmer 160 | * @return bool|record 161 | */ 162 | public function select() { 163 | $sql = 'select ' . ($this->field ?: '*') . " from {$this->table} {$this->join} " . ($this->where ? 'where' : ''); 164 | $sql .= $this->dealParam(); 165 | $result = self::$db->prepare($sql); 166 | if ($result->execute($this->bindParam)) { 167 | return new record($result); 168 | } 169 | return false; 170 | } 171 | 172 | public function count() { 173 | $tmpField = $this->field; 174 | $tmpLimit = $this->limit; 175 | $this->field = ''; 176 | $count = $this->field('count(*)')->find()['count(*)']; 177 | $this->field = $tmpField; 178 | $this->limit = $tmpLimit; 179 | return $count; 180 | } 181 | 182 | /** 183 | * 数据更新 184 | * @author Farmer 185 | * @param $set 186 | * @return bool|int 187 | */ 188 | public function update($set) { 189 | $data = null; 190 | if (is_string($set)) { 191 | $data = $set; 192 | } else if (is_array($set)) { 193 | foreach ($set as $key => $value) { 194 | if (is_numeric($key)) { 195 | $data .= ',' . $set[$key]; 196 | } else { 197 | $data .= ",`{$key}`=?"; 198 | $tmpParam[] = $value; 199 | } 200 | } 201 | $this->bindParam = array_merge($tmpParam, $this->bindParam); 202 | $data = substr($data, 1); 203 | } 204 | $sql = "update {$this->table} set $data where" . $this->dealParam(); 205 | $result = self::$db->prepare($sql); 206 | if ($result->execute($this->bindParam)) { 207 | return $result->rowCount(); 208 | } 209 | return false; 210 | } 211 | 212 | /** 213 | * 删除数据 214 | * @author Farmer 215 | * @return bool|int 216 | */ 217 | public function delete() { 218 | $sql = "delete from {$this->table} where" . $this->dealParam(); 219 | $result = self::$db->prepare($sql); 220 | if ($result->execute($this->bindParam)) { 221 | return $result->rowCount(); 222 | } 223 | return false; 224 | } 225 | 226 | /** 227 | * 对where等进行处理 228 | * @author Farmer 229 | * @return string 230 | */ 231 | private function dealParam() { 232 | $sql = $this->where ?: ''; 233 | $sql .= $this->order ?: ''; 234 | $sql .= $this->limit ?: ''; 235 | return $sql; 236 | } 237 | 238 | /** 239 | * 绑定参数 240 | * @author Farmer 241 | * @param $key 242 | * @param string $value 243 | * @return $this 244 | */ 245 | public function bind($key, $value = '') { 246 | if (is_array($key)) { 247 | $this->bindParam = array_merge($this->bindParam, $key); 248 | } else { 249 | $this->bindParam[$key] = $value; 250 | } 251 | return $this; 252 | } 253 | 254 | /** 255 | * 排序 256 | * @author Farmer 257 | * @param $field 258 | * @param string $rule 259 | * @return $this 260 | */ 261 | public function order($field, $rule = 'desc') { 262 | if ($this->order) { 263 | $this->order .= ",`$field` $rule"; 264 | } else { 265 | $this->order = " order by `$field` $rule"; 266 | } 267 | return $this; 268 | } 269 | 270 | /** 271 | * 分页 272 | * @author Farmer 273 | * @param $start 274 | * @param int $count 275 | * @return $this 276 | */ 277 | public function limit($start, $count = 0) { 278 | if ($count) { 279 | $this->limit = " limit $start,$count"; 280 | } else { 281 | $this->limit = " limit $start"; 282 | } 283 | return $this; 284 | } 285 | 286 | /** 287 | * 查询出单条数据 288 | * @author Farmer 289 | * @return mixed 290 | */ 291 | public function find() { 292 | return $this->limit('1')->select()->fetch(); 293 | } 294 | 295 | /** 296 | * 开始事务 297 | * @author Farmer 298 | */ 299 | public function begin() { 300 | $this->exec('begin'); 301 | } 302 | 303 | /** 304 | * 提交事务 305 | * @author Farmer 306 | */ 307 | public function commit() { 308 | $this->exec('commit'); 309 | } 310 | 311 | /** 312 | * 回滚事务 313 | * @author Farmer 314 | */ 315 | public function rollback() { 316 | $this->exec('rollback'); 317 | } 318 | 319 | public function field($field, $alias = '') { 320 | if (is_string($field)) { 321 | if (empty($alias)) { 322 | $this->field .= (empty($this->field) ? '' : ',') . $field . ' '; 323 | } else { 324 | $this->field .= (empty($this->field) ? '' : ',') . $field . ' as ' . $alias . ' '; 325 | } 326 | } else if (is_array($field)) { 327 | foreach ($field as $key => $value) { 328 | if (is_array($value)) { 329 | $this->field .= (empty($this->field) ? '' : ',') . $key . ' as ' . $value . ' '; 330 | } else if (is_string($value)) { 331 | $this->field .= (empty($this->field) ? '' : ',') . $value . ' '; 332 | } 333 | 334 | } 335 | } 336 | return $this; 337 | } 338 | 339 | /** 340 | * 上一个插入id 341 | * @author Farmer 342 | * @return int 343 | */ 344 | public function lastinsertid() { 345 | return self::$db->lastInsertId(); 346 | } 347 | 348 | public function __call($func, $arguments) { 349 | if (is_null(self::$db)) { 350 | return 0; 351 | } 352 | return call_user_func_array(array( 353 | self::$db, 354 | $func 355 | ), $arguments); 356 | } 357 | } 358 | 359 | /** 360 | * 记录集类 361 | * @author Farmer 362 | * @package icf\lib 363 | */ 364 | class record { 365 | private $result; 366 | 367 | public function __call($func, $arguments) { 368 | if (is_null($this->result)) { 369 | return 0; 370 | } 371 | return call_user_func_array(array( 372 | $this->result, 373 | $func 374 | ), $arguments); 375 | } 376 | 377 | function __construct(\PDOStatement $result) { 378 | $this->result = $result; 379 | $this->result->setFetchMode(PDO::FETCH_ASSOC); 380 | } 381 | 382 | function fetchAll() { 383 | return $this->result->fetchAll(); 384 | } 385 | 386 | function fetch() { 387 | return $this->result->fetch(); 388 | } 389 | 390 | } -------------------------------------------------------------------------------- /icf/lib/info/AliSms.php: -------------------------------------------------------------------------------- 1 | akID = $AccessKeyID; 23 | $this->akSecrt = $AccessKeySecret; 24 | 25 | } 26 | 27 | public function sendSms($SignName, $TemplateCode, $TemplateParam, $PhoneNumbers) { 28 | return $this->request([ 29 | 'Action' => 'SendSms', 30 | 'Version' => '2017-05-25', 31 | 'RegionId' => 'cn', 32 | 'SignName' => $SignName, 33 | 'TemplateCode' => $TemplateCode, 34 | 'TemplateParam' => json_encode($TemplateParam, JSON_UNESCAPED_UNICODE), 35 | 'PhoneNumbers' => $PhoneNumbers 36 | ]); 37 | } 38 | 39 | public function request($param) { 40 | $req = array_merge([ 41 | 'AccessKeyId' => $this->akID, 42 | 'Timestamp' => gmdate("Y-m-d\TH:i:s\Z"), 43 | 'SignatureMethod' => 'HMAC-SHA1', 44 | 'SignatureVersion' => '1.0', 45 | 'SignatureNonce' => uniqid(mt_rand(0, 0xffff), true), 46 | 'Format' => 'JSON' 47 | ], $param); 48 | $getParam = $this->getReqString($req); 49 | $Signature = $this->sign($getParam); 50 | $http = new http("https://dysmsapi.aliyuncs.com/?Signature={$Signature}{$getParam}"); 51 | $http->https(); 52 | $data = $http->get(); 53 | return $data; 54 | } 55 | 56 | private function getReqString($req) { 57 | ksort($req); 58 | $ret = ''; 59 | foreach ($req as $key => $value) { 60 | $ret .= '&' . $this->encode($key) . '=' . $this->encode($value); 61 | } 62 | return $ret; 63 | } 64 | 65 | private function sign($param) { 66 | $stringToSign = "GET&%2F&" . $this->encode(substr($param, 1)); 67 | $sign = base64_encode(hash_hmac("sha1", $stringToSign, $this->akSecrt . "&", true)); 68 | return $this->encode($sign); 69 | } 70 | 71 | private function encode($str) { 72 | $res = urlencode($str); 73 | $res = preg_replace("/\+/", "%20", $res); 74 | $res = preg_replace("/\*/", "%2A", $res); 75 | $res = preg_replace("/%7E/", "~", $res); 76 | return $res; 77 | } 78 | 79 | } -------------------------------------------------------------------------------- /icf/lib/info/smtp.php: -------------------------------------------------------------------------------- 1 | _name=$name; 89 | } 90 | /** 91 | * 设置邮件传输代理,如果是可以匿名发送有邮件的服务器,只需传递代理服务器地址就行 92 | * @access public 93 | * @param string $server 代理服务器的ip或者域名 94 | * @param string $username 认证账号 95 | * @param string $password 认证密码 96 | * @param int $port 代理服务器的端口,smtp默认25号端口 97 | * @param boolean $isSecurity 到服务器的连接是否为安全连接,默认false 98 | * @return boolean 99 | */ 100 | public function setServer($server, $username = "", $password = "", $port = 25, $isSecurity = false) { 101 | $this->_sendServer = $server; 102 | $this->_port = $port; 103 | $this->_isSecurity = $isSecurity; 104 | $this->_userName = empty($username) ? "" : base64_encode($username); 105 | $this->_password = empty($password) ? "" : base64_encode($password); 106 | return true; 107 | } 108 | 109 | /** 110 | * 设置发件人 111 | * @access public 112 | * @param string $from 发件人地址 113 | * @return boolean 114 | */ 115 | public function setFrom($from) { 116 | $this->_from = $from; 117 | return true; 118 | } 119 | 120 | /** 121 | * 设置收件人,多个收件人,调用多次. 122 | * @access public 123 | * @param string $to 收件人地址 124 | * @return boolean 125 | */ 126 | public function setReceiver($to) { 127 | $this->_to[] = $to; 128 | return true; 129 | } 130 | 131 | /** 132 | * 设置抄送,多个抄送,调用多次. 133 | * @access public 134 | * @param string $cc 抄送地址 135 | * @return boolean 136 | */ 137 | public function setCc($cc) { 138 | $this->_cc[] = $cc; 139 | return true; 140 | } 141 | 142 | /** 143 | * 设置秘密抄送,多个秘密抄送,调用多次 144 | * @access public 145 | * @param string $bcc 秘密抄送地址 146 | * @return boolean 147 | */ 148 | public function setBcc($bcc) { 149 | $this->_bcc[] = $bcc; 150 | return true; 151 | } 152 | 153 | /** 154 | * 设置邮件附件,多个附件,调用多次 155 | * @access public 156 | * @param string $file 文件地址 157 | * @return boolean 158 | */ 159 | public function addAttachment($file) { 160 | if (!file_exists($file)) { 161 | $this->_errorMessage = "file " . $file . " does not exist."; 162 | return false; 163 | } 164 | $this->_attachment[] = $file; 165 | return true; 166 | } 167 | 168 | /** 169 | * 设置邮件信息 170 | * @access public 171 | * @param string $body 邮件主题 172 | * @param string $subject 邮件主体内容,可以是纯文本,也可是是HTML文本 173 | * @return boolean 174 | */ 175 | public function setMail($subject, $body) { 176 | $this->_subject = base64_encode($subject); 177 | $this->_body = base64_encode($body); 178 | return true; 179 | } 180 | 181 | /** 182 | * 发送邮件 183 | * @access public 184 | * @return boolean 185 | */ 186 | public function sendMail() { 187 | $command = $this->getCommand(); 188 | $this->_isSecurity ? $this->socketSecurity() : $this->socket(); 189 | foreach ($command as $value) { 190 | $result = $this->_isSecurity ? $this->sendCommandSecurity($value[0], $value[1]) : $this->sendCommand($value[0], $value[1]); 191 | if ($result) { 192 | continue; 193 | } else { 194 | return false; 195 | } 196 | } 197 | //其实这里也没必要关闭,smtp命令:QUIT发出之后,服务器就关闭了连接,本地的socket资源会自动释放 198 | $this->_isSecurity ? $this->closeSecutity() : $this->close(); 199 | return true; 200 | } 201 | 202 | /** 203 | * 返回错误信息 204 | * @return string 205 | */ 206 | public function error() { 207 | if (!isset($this->_errorMessage)) { 208 | $this->_errorMessage = ""; 209 | } 210 | return $this->_errorMessage; 211 | } 212 | 213 | /** 214 | * 返回mail命令 215 | * @access protected 216 | * @return array 217 | */ 218 | protected function getCommand() { 219 | $separator = "----=_Part_" . md5($this->_from . time()) . uniqid(); //分隔符 220 | $command = array( 221 | array("HELO sendmail\r\n", 250) 222 | ); 223 | if (!empty($this->_userName)) { 224 | $command[] = array("AUTH LOGIN\r\n", 334); 225 | $command[] = array($this->_userName . "\r\n", 334); 226 | $command[] = array($this->_password . "\r\n", 235); 227 | } 228 | //设置发件人 229 | $command[] = array("MAIL FROM: <" . $this->_from . ">\r\n", 250); 230 | $header = "FROM: =?utf-8?b?".base64_encode($this->_name)."?= <" . $this->_from . ">\r\n"; 231 | //设置收件人 232 | if (!empty($this->_to)) { 233 | $count = count($this->_to); 234 | if ($count == 1) { 235 | $command[] = array("RCPT TO: <" . $this->_to[0] . ">\r\n", 250); 236 | $header .= "TO: <" . $this->_to[0] . ">\r\n"; 237 | } else { 238 | for ($i = 0; $i < $count; $i++) { 239 | $command[] = array("RCPT TO: <" . $this->_to[$i] . ">\r\n", 250); 240 | if ($i == 0) { 241 | $header .= "TO: <" . $this->_to[$i] . ">"; 242 | } elseif ($i + 1 == $count) { 243 | $header .= ",<" . $this->_to[$i] . ">\r\n"; 244 | } else { 245 | $header .= ",<" . $this->_to[$i] . ">"; 246 | } 247 | } 248 | } 249 | } 250 | //设置抄送 251 | if (!empty($this->_cc)) { 252 | $count = count($this->_cc); 253 | if ($count == 1) { 254 | $command[] = array("RCPT TO: <" . $this->_cc[0] . ">\r\n", 250); 255 | $header .= "CC: <" . $this->_cc[0] . ">\r\n"; 256 | } else { 257 | for ($i = 0; $i < $count; $i++) { 258 | $command[] = array("RCPT TO: <" . $this->_cc[$i] . ">\r\n", 250); 259 | if ($i == 0) { 260 | $header .= "CC: <" . $this->_cc[$i] . ">"; 261 | } elseif ($i + 1 == $count) { 262 | $header .= ",<" . $this->_cc[$i] . ">\r\n"; 263 | } else { 264 | $header .= ",<" . $this->_cc[$i] . ">"; 265 | } 266 | } 267 | } 268 | } 269 | //设置秘密抄送 270 | if (!empty($this->_bcc)) { 271 | $count = count($this->_bcc); 272 | if ($count == 1) { 273 | $command[] = array("RCPT TO: <" . $this->_bcc[0] . ">\r\n", 250); 274 | $header .= "BCC: <" . $this->_bcc[0] . ">\r\n"; 275 | } else { 276 | for ($i = 0; $i < $count; $i++) { 277 | $command[] = array("RCPT TO: <" . $this->_bcc[$i] . ">\r\n", 250); 278 | if ($i == 0) { 279 | $header .= "BCC: <" . $this->_bcc[$i] . ">"; 280 | } elseif ($i + 1 == $count) { 281 | $header .= ",<" . $this->_bcc[$i] . ">\r\n"; 282 | } else { 283 | $header .= ",<" . $this->_bcc[$i] . ">"; 284 | } 285 | } 286 | } 287 | } 288 | //主题 289 | $header .= "Subject: =?UTF-8?B?" . $this->_subject . "?=\r\n"; 290 | if (isset($this->_attachment)) { 291 | //含有附件的邮件头需要声明成这个 292 | $header .= "Content-Type: multipart/mixed;\r\n"; 293 | } elseif (false) { 294 | //邮件体含有图片资源的,且包含的图片在邮件内部时声明成这个,如果是引用的远程图片,就不需要了 295 | $header .= "Content-Type: multipart/related;\r\n"; 296 | } else { 297 | //html或者纯文本的邮件声明成这个 298 | $header .= "Content-Type: multipart/alternative;\r\n"; 299 | } 300 | //邮件头分隔符 301 | $header .= "\t" . 'boundary="' . $separator . '"'; 302 | $header .= "\r\nMIME-Version: 1.0\r\n"; 303 | //这里开始是邮件的body部分,body部分分成几段发送 304 | $header .= "\r\n--" . $separator . "\r\n"; 305 | $header .= "Content-Type:text/html; charset=utf-8\r\n"; 306 | $header .= "Content-Transfer-Encoding: base64\r\n\r\n"; 307 | $header .= $this->_body . "\r\n"; 308 | $header .= "--" . $separator . "\r\n"; 309 | //加入附件 310 | if (!empty($this->_attachment)) { 311 | $count = count($this->_attachment); 312 | for ($i = 0; $i < $count; $i++) { 313 | $header .= "\r\n--" . $separator . "\r\n"; 314 | $header .= "Content-Type: " . $this->getMIMEType($this->_attachment[$i]) . '; name="=?UTF-8?B?' . base64_encode(basename($this->_attachment[$i])) . '?="' . "\r\n"; 315 | $header .= "Content-Transfer-Encoding: base64\r\n"; 316 | $header .= 'Content-Disposition: attachment; filename="=?UTF-8?B?' . base64_encode(basename($this->_attachment[$i])) . '?="' . "\r\n"; 317 | $header .= "\r\n"; 318 | $header .= $this->readFile($this->_attachment[$i]); 319 | $header .= "\r\n--" . $separator . "\r\n"; 320 | } 321 | } 322 | //结束邮件数据发送 323 | $header .= "\r\n.\r\n"; 324 | 325 | $command[] = array("DATA\r\n", 354); 326 | $command[] = array($header, 250); 327 | $command[] = array("QUIT\r\n", 221); 328 | return $command; 329 | } 330 | 331 | /** 332 | * 发送命令 333 | * @access protected 334 | * @param string $command 发送到服务器的smtp命令 335 | * @param int $code 期望服务器返回的响应吗 336 | * @return boolean 337 | */ 338 | protected function sendCommand($command, $code) { 339 | // echo 'Send command:' . $command . ',expected code:' . $code . '
'; 340 | //发送命令给服务器 341 | try { 342 | if (socket_write($this->_socket, $command, strlen($command))) { 343 | //当邮件内容分多次发送时,没有$code,服务器没有返回 344 | if (empty($code)) { 345 | return true; 346 | } 347 | //读取服务器返回 348 | $data = trim(socket_read($this->_socket, 1024)); 349 | // echo 'response:' . $data . '

'; 350 | if ($data) { 351 | $pattern = "/^" . $code . "+?/"; 352 | if (preg_match($pattern, $data)) { 353 | return true; 354 | } else { 355 | $this->_errorMessage = "Error:" . $data . "|**| command:"; 356 | return false; 357 | } 358 | } else { 359 | $this->_errorMessage = "Error:" . socket_strerror(socket_last_error()); 360 | return false; 361 | } 362 | } else { 363 | $this->_errorMessage = "Error:" . socket_strerror(socket_last_error()); 364 | return false; 365 | } 366 | } catch (Exception $e) { 367 | $this->_errorMessage = "Error:" . $e->getMessage(); 368 | } 369 | } 370 | 371 | /** 372 | * 安全连接发送命令 373 | * @access protected 374 | * @param string $command 发送到服务器的smtp命令 375 | * @param int $code 期望服务器返回的响应吗 376 | * @return boolean 377 | */ 378 | protected function sendCommandSecurity($command, $code) { 379 | // echo 'Send command:' . $command . ',expected code:' . $code . '
'; 380 | try { 381 | if (fwrite($this->_socket, $command)) { 382 | //当邮件内容分多次发送时,没有$code,服务器没有返回 383 | if (empty($code)) { 384 | return true; 385 | } 386 | //读取服务器返回 387 | $data = trim(fread($this->_socket, 1024)); 388 | // echo 'response:' . $data . '

'; 389 | if ($data) { 390 | $pattern = "/^" . $code . "+?/"; 391 | if (preg_match($pattern, $data)) { 392 | return true; 393 | } else { 394 | $this->_errorMessage = "Error:" . $data . "|**| command:"; 395 | return false; 396 | } 397 | } else { 398 | return false; 399 | } 400 | } else { 401 | $this->_errorMessage = "Error: " . $command . " send failed"; 402 | return false; 403 | } 404 | } catch (Exception $e) { 405 | $this->_errorMessage = "Error:" . $e->getMessage(); 406 | } 407 | } 408 | 409 | /** 410 | * 读取附件文件内容,返回base64编码后的文件内容 411 | * @access protected 412 | * @param string $file 文件 413 | * @return mixed 414 | */ 415 | protected function readFile($file) { 416 | if (file_exists($file)) { 417 | $file_obj = file_get_contents($file); 418 | return base64_encode($file_obj); 419 | } else { 420 | $this->_errorMessage = "file " . $file . " dose not exist"; 421 | return false; 422 | } 423 | } 424 | 425 | /** 426 | * 获取附件MIME类型 427 | * @access protected 428 | * @param string $file 文件 429 | * @return mixed 430 | */ 431 | protected function getMIMEType($file) { 432 | if (file_exists($file)) { 433 | $mime = mime_content_type($file); 434 | /*if(! preg_match("/gif|jpg|png|jpeg/", $mime)){ 435 | $mime = "application/octet-stream"; 436 | }*/ 437 | return $mime; 438 | } else { 439 | return false; 440 | } 441 | } 442 | 443 | /** 444 | * 建立到服务器的网络连接 445 | * @access protected 446 | * @return boolean 447 | */ 448 | protected function socket() { 449 | //创建socket资源 450 | $this->_socket = socket_create(AF_INET, SOCK_STREAM, getprotobyname('tcp')); 451 | if (!$this->_socket) { 452 | $this->_errorMessage = socket_strerror(socket_last_error()); 453 | return false; 454 | } 455 | socket_set_block($this->_socket);//设置阻塞模式 456 | //连接服务器 457 | if (!socket_connect($this->_socket, $this->_sendServer, $this->_port)) { 458 | $this->_errorMessage = socket_strerror(socket_last_error()); 459 | return false; 460 | } 461 | $str = socket_read($this->_socket, 1024); 462 | if (!preg_match("/220+?/", $str)) { 463 | $this->_errorMessage = $str; 464 | return false; 465 | } 466 | return true; 467 | } 468 | 469 | /** 470 | * 建立到服务器的SSL网络连接 471 | * @access protected 472 | * @return boolean 473 | */ 474 | protected function socketSecurity() { 475 | $remoteAddr = "tcp://" . $this->_sendServer . ":" . $this->_port; 476 | $this->_socket = stream_socket_client($remoteAddr, $errno, $errstr, 30); 477 | if (!$this->_socket) { 478 | $this->_errorMessage = $errstr; 479 | return false; 480 | } 481 | //设置加密连接,默认是ssl,如果需要tls连接,可以查看php手册stream_socket_enable_crypto函数的解释 482 | stream_socket_enable_crypto($this->_socket, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); 483 | stream_set_blocking($this->_socket, 1); //设置阻塞模式 484 | $str = fread($this->_socket, 1024); 485 | if (!preg_match("/220+?/", $str)) { 486 | $this->_errorMessage = $str; 487 | return false; 488 | } 489 | return true; 490 | } 491 | 492 | /** 493 | * 关闭socket 494 | * @access protected 495 | * @return boolean 496 | */ 497 | protected function close() { 498 | if (isset($this->_socket) && is_object($this->_socket)) { 499 | $this->_socket->close(); 500 | return true; 501 | } 502 | $this->_errorMessage = "No resource can to be close"; 503 | return false; 504 | } 505 | 506 | /** 507 | * 关闭安全socket 508 | * @access protected 509 | * @return boolean 510 | */ 511 | protected function closeSecutity() { 512 | if (isset($this->_socket) && is_object($this->_socket)) { 513 | stream_socket_shutdown($this->_socket, STREAM_SHUT_WR); 514 | return true; 515 | } 516 | $this->_errorMessage = "No resource can to be close"; 517 | return false; 518 | } 519 | } -------------------------------------------------------------------------------- /icf/lib/log.php: -------------------------------------------------------------------------------- 1 | >> [notice] $msg"); 73 | } 74 | 75 | /** 76 | * 错误日志 77 | * @author Farmer 78 | * @param $msg 79 | * @return bool|int 80 | */ 81 | public function error($msg) { 82 | return self::wline(date('Y-m-d H:i:s') . ">>> [error] $msg"); 83 | } 84 | 85 | } -------------------------------------------------------------------------------- /icf/lib/model.php: -------------------------------------------------------------------------------- 1 | table = $table; 20 | $this->where = $where; 21 | if ($where !== '') { 22 | $this->data = db::table($table)->where($where)->find(); 23 | } 24 | } 25 | 26 | public function __get($name) { 27 | // TODO: Implement __get() method. 28 | if (substr($name, 0, 1) == '_') { 29 | $tmpKey = $this->table . $name; 30 | } else { 31 | $tmpKey = $name; 32 | } 33 | if (isset($this->data[$tmpKey])) { 34 | return $this->data[$tmpKey]; 35 | } else { 36 | throw new \Exception('not find ' . $name); 37 | } 38 | } 39 | 40 | public function __set($name, $value) { 41 | // TODO: Implement __set() method. 42 | if (substr($name, 0, 1) == '_') { 43 | $tmpKey = $this->table . $name; 44 | } else { 45 | $tmpKey = $name; 46 | } 47 | $this->data[$tmpKey] = $value; 48 | } 49 | 50 | /** 51 | * 添加数据到数据库 52 | * @author Farmer 53 | * @return int 54 | */ 55 | public function add() { 56 | db::table($this->table)->insert($this->data); 57 | return db::table()->lastinsertid(); 58 | } 59 | 60 | /** 61 | * 修改数据 62 | * @author Farmer 63 | * @param $where 64 | */ 65 | public function put($where) { 66 | db::table($this->table)->where($where)->update($this->data); 67 | } 68 | 69 | /** 70 | * 获取数据 71 | * @author Farmer 72 | * @return mixed 73 | */ 74 | public function getData() { 75 | return $this->data; 76 | } 77 | 78 | /** 79 | * 设置数据 80 | * @author Farmer 81 | * @param $data 82 | */ 83 | public function setData($data) { 84 | $this->data = $data; 85 | } 86 | } -------------------------------------------------------------------------------- /icf/lib/other/HttpHelp.php: -------------------------------------------------------------------------------- 1 | 'Continue', 30 | 101 => 'Switching Protocols', 31 | 200 => 'OK', 32 | 201 => 'Created', 33 | 202 => 'Accepted', 34 | 203 => 'Non-Authoritative Information', 35 | 204 => 'No Content', 36 | 205 => 'Reset Content', 37 | 206 => 'Partial Content', 38 | 300 => 'Multiple Choices', 39 | 301 => 'Moved Permanently', 40 | 302 => 'Found', 41 | 303 => 'See Other', 42 | 304 => 'Not Modified', 43 | 305 => 'Use Proxy', 44 | 306 => '(Unused)', 45 | 307 => 'Temporary Redirect', 46 | 400 => 'Bad Request', 47 | 401 => 'Unauthorized', 48 | 402 => 'Payment Required', 49 | 403 => 'Forbidden', 50 | 404 => 'Not Found', 51 | 405 => 'Method Not Allowed', 52 | 406 => 'Not Acceptable', 53 | 407 => 'Proxy Authentication Required', 54 | 408 => 'Request Timeout', 55 | 409 => 'Conflict', 56 | 410 => 'Gone', 57 | 411 => 'Length Required', 58 | 412 => 'Precondition Failed', 59 | 413 => 'Request Entity Too Large', 60 | 414 => 'Request-URI Too Long', 61 | 415 => 'Unsupported Media Type', 62 | 416 => 'Requested Range Not Satisfiable', 63 | 417 => 'Expectation Failed', 64 | 500 => 'Internal Server Error', 65 | 501 => 'Not Implemented', 66 | 502 => 'Bad Gateway', 67 | 503 => 'Service Unavailable', 68 | 504 => 'Gateway Timeout', 69 | 505 => 'HTTP Version Not Supported'); 70 | return ($httpStatus[$statusCode]) ? $httpStatus[$statusCode] : $httpStatus[500]; 71 | } 72 | } -------------------------------------------------------------------------------- /icf/lib/other/ImageVerifyCode.php: -------------------------------------------------------------------------------- 1 | left = mt_rand(10, 15); 27 | $this->backcolor();//生成背景颜色 28 | $this->code = ''; 29 | for ($i = 0; $i < 4; $i++) {//绘制字符 30 | $tmp = self::getRandString(1); 31 | $this->createWord($tmp); 32 | $this->code .= $tmp; 33 | } 34 | $this->_writeCurve();//绘制干扰线 35 | return $this->code; 36 | } 37 | 38 | /** 39 | * 取随机字符串 40 | * @author Farmer 41 | * @param $length 42 | * @param $type 43 | * @return string 44 | */ 45 | public static function getRandString($length, $type = 2) { 46 | $randString = '123456789qwwertyuopasdfghjkzxcvbnmQWERTYUIPASDFGHHJKLZXCVBNM'; 47 | $retStr = ''; 48 | for ($n = 0; $n < $length; $n++) { 49 | $retStr .= substr($randString, mt_rand(0, 9 + $type * 24), 1); 50 | } 51 | return $retStr; 52 | } 53 | 54 | public function getImage() { 55 | return $this->im; 56 | } 57 | 58 | public function display() { 59 | $this->create(); 60 | header('Pragma: no-cache'); 61 | header('Content-type: image/png'); 62 | imagepng($this->im); 63 | imagedestroy($this->im); 64 | return $this->code; 65 | } 66 | 67 | private function backcolor() { 68 | $this->im = imagecreatetruecolor($this->imageL, $this->imageH); 69 | $this->bgc = imagecolorallocate($this->im, 255, 255, 255); 70 | imagefill($this->im, 0, 0, imagecolorallocate($this->im, 255, 255, 255)); 71 | } 72 | 73 | private function createWord($word) { 74 | $font = __ROOT_ . '/icf/res/arial.ttf'; 75 | $size = mt_rand(24, 28); 76 | imagefttext($this->im, $size, mt_rand(-60, 60), $this->left, $size * 1.5, $this->createRandColor(), $font, $word); 77 | $this->left += mt_rand($size * 1.2, $size * 1.6); 78 | } 79 | 80 | private function createRandColor() { 81 | return imagecolorallocate($this->im, mt_rand(10, 200), mt_rand(10, 200), mt_rand(10, 200)); 82 | } 83 | 84 | /** 85 | * 算法来自:http://www.piaoyi.org/php/php-yanzhengma-rand-shape.html 86 | * 画一条由两条连在一起构成的随机正弦函数曲线作干扰线(你可以改成更帅的曲线函数) 87 | * 正弦型函数解析式:y=Asin(ωx+φ)+b 88 | * 各常数值对函数图像的影响: 89 | * A:决定峰值(即纵向拉伸压缩的倍数) 90 | * b:表示波形在Y轴的位置关系或纵向移动距离(上加下减) 91 | * φ:决定波形与X轴位置关系或横向移动距离(左加右减) 92 | * ω:决定周期(最小正周期T=2π/∣ω∣) 93 | */ 94 | protected function _writeCurve() { 95 | $A = mt_rand(1, $this->imageH / 2); // 振幅 96 | $b = mt_rand(-$this->imageH / 4, $this->imageH / 4); // Y轴方向偏移量 97 | $f = mt_rand(-$this->imageH / 4, $this->imageH / 4); // X轴方向偏移量 98 | $T = mt_rand($this->imageH * 1.5, $this->imageL * 2); // 周期 99 | $w = (2 * M_PI) / $T; 100 | 101 | $px1 = 0; // 曲线横坐标起始位置 102 | $px2 = mt_rand($this->imageL / 2, $this->imageL * 0.667); // 曲线横坐标结束位置 103 | $t_bg = $this->createRandColor(); 104 | for ($px = $px1; $px <= $px2; $px = $px + 0.9) { 105 | if ($w != 0) { 106 | $py = $A * sin($w * $px + $f) + $b + $this->imageH / 2; // y = Asin(ωx+φ) + b 107 | $i = (int)(($this->fontSize - 6) / 4); 108 | while ($i > 0) { 109 | imagesetpixel($this->im, $px + $i, $py + $i, $t_bg); 110 | //这里画像素点比imagettftext和imagestring性能要好很多 111 | $i--; 112 | } 113 | } 114 | } 115 | 116 | $A = mt_rand(1, $this->imageH / 2); // 振幅 117 | $f = mt_rand(-$this->imageH / 4, $this->imageH / 4); // X轴方向偏移量 118 | $T = mt_rand($this->imageH * 1.5, $this->imageL * 2); // 周期 119 | $w = (2 * M_PI) / $T; 120 | $b = $py - $A * sin($w * $px + $f) - $this->imageH / 2; 121 | $px1 = $px2; 122 | $px2 = $this->imageL; 123 | for ($px = $px1; $px <= $px2; $px = $px + 0.9) { 124 | if ($w != 0) { 125 | $py = $A * sin($w * $px + $f) + $b + $this->imageH / 2; // y = Asin(ωx+φ) + b 126 | $i = (int)(($this->fontSize - 8) / 4); 127 | while ($i > 0) { 128 | imagesetpixel($this->im, $px + $i, $py + $i, $t_bg); 129 | //这里(while)循环画像素点比imagettftext和imagestring用字体大小一次画出 130 | //的(不用while循环)性能要好很多 131 | $i--; 132 | } 133 | } 134 | } 135 | } 136 | 137 | } -------------------------------------------------------------------------------- /icf/lib/other/http.php: -------------------------------------------------------------------------------- 1 | curl = curl_init($url); 25 | curl_setopt($this->curl, CURLOPT_HEADER, 0); //不返回header部分 26 | curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, true); //返回字符串,而非直接输出 27 | curl_setopt($this->curl, CURLOPT_TIMEOUT, 10); 28 | } 29 | 30 | public function setopt($key, $value) { 31 | curl_setopt($this->curl, $key, $value); 32 | } 33 | 34 | public function responseHeader() { 35 | $this->setopt(CURLOPT_HEADER, $this->responseHeader = (!$this->responseHeader)); 36 | } 37 | 38 | public function getResponseHeader() { 39 | if ($this->responseHeader) { 40 | return substr($this->data, 0, strpos($this->data, "\r\n\r\n")); 41 | } 42 | return false; 43 | } 44 | 45 | public function data() { 46 | if ($this->responseHeader) { 47 | return substr($this->data, strpos($this->data, "\r\n\r\n") + 4); 48 | } 49 | return $this->data; 50 | } 51 | 52 | public function getCookie() { 53 | $cookie = ''; 54 | preg_match_all('/Set-Cookie:(.*);/iU', $this->getResponseHeader(), $matchCookie); 55 | foreach ($matchCookie[1] as $value) { 56 | $cookie .= $value . ';'; 57 | } 58 | return $cookie; 59 | } 60 | 61 | public function getHeader($opt = 0) { 62 | return curl_getinfo($this->curl, $opt); 63 | } 64 | 65 | public function setRedirection($value = 1) { 66 | curl_setopt($this->curl, CURLOPT_FOLLOWLOCATION, $value); 67 | } 68 | 69 | public function __destruct() { 70 | // TODO: Implement __destruct() method. 71 | curl_close($this->curl); 72 | } 73 | 74 | public function setCookie($cookie) { 75 | curl_setopt($this->curl, CURLOPT_COOKIE, $cookie); 76 | } 77 | 78 | public function setHeader($header) { 79 | curl_setopt($this->curl, CURLOPT_HTTPHEADER, $header); 80 | } 81 | 82 | public function setUrl($url) { 83 | curl_setopt($this->curl, CURLOPT_URL, $url); 84 | } 85 | 86 | public function https() { 87 | curl_setopt($this->curl, CURLOPT_SSL_VERIFYPEER, false); 88 | } 89 | 90 | public function get($url = '') { 91 | if (!empty($url)) { 92 | $this->setUrl($url); 93 | } 94 | curl_setopt($this->curl, CURLOPT_POST, 0); 95 | return $this->access(); 96 | } 97 | 98 | public function post($url = '', $data = '') { 99 | curl_setopt($this->curl, CURLOPT_POST, 1); 100 | if (!empty($data)) { 101 | $this->setUrl($url); 102 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, $data); 103 | } else { 104 | curl_setopt($this->curl, CURLOPT_POSTFIELDS, $url); 105 | } 106 | return $this->access(); 107 | } 108 | 109 | public function access() { 110 | $response = curl_exec($this->curl); 111 | if ($response == false) return curl_error($this->curl); 112 | return $this->data = $response; 113 | } 114 | } -------------------------------------------------------------------------------- /icf/lib/route.php: -------------------------------------------------------------------------------- 1 | [ 24 | '{s}.php' => '${1}->index->index', 25 | '{s}/{s}/{s}#p' => '${1}->${2}->${3}', 26 | '{s}/{s}#p' => '${1}->${2}', 27 | '{s}#p' => '${1}->index' 28 | ], 'get' => [ 29 | 30 | ]]; 31 | 32 | static $get_param = []; 33 | 34 | static $replace_param = ''; 35 | 36 | static $classNamePace = ''; 37 | 38 | static $get = []; 39 | 40 | static $matchUrl = ''; 41 | 42 | static $req_method = 'get'; 43 | 44 | static function matchRule($match, $pathInfo) { 45 | //初始化 46 | self::$module = ''; 47 | self::$ctrl = ''; 48 | self::$action = ''; 49 | //处理各个参数 50 | $param = ''; 51 | if ($cut = strpos($match[0], '#')) { 52 | $param = substr($match[0], $cut + 1); 53 | $match[0] = substr($match[0], 0, $cut); 54 | if (strpos($param, 'p') !== false) { 55 | $match[0] .= '/'; 56 | $pathInfo .= '/'; 57 | } 58 | } 59 | $var = preg_replace_callback('#{(.*?)}#', function ($v) { 60 | static $count = 0; 61 | $count++; 62 | self::$get_param[$count] = $v[1]; 63 | return '([\S][^\{^\}^/]*)'; 64 | }, $match[0]); 65 | self::$replace_param = $match[1]; 66 | self::$get = []; 67 | $count = 0; 68 | preg_replace_callback('#^\/' . $var . '#', function ($v) { 69 | foreach ($v as $key => $value) { 70 | self::$replace_param = str_replace('${' . $key . '}', $value, self::$replace_param); 71 | if (isset(self::$get_param[$key])) { 72 | self::$get[self::$get_param[$key]] = $value; 73 | } 74 | } 75 | self::$matchUrl = $v[0]; 76 | return ''; 77 | }, $pathInfo, 1, $count); 78 | if ($count <= 0) { 79 | return false; 80 | } 81 | $mca = explode('->', self::$replace_param, 3); 82 | if (sizeof($mca) <= 2) { 83 | $mca[2] = $mca[isset($mca[1])]; 84 | $mca[1] = isset($mca[1]) ? $mca[0] : 'index'; 85 | $mca[0] = __DEFAULT_MODULE_; 86 | } 87 | self::$module = _get(_config('module_key'), $mca[0]); 88 | self::$ctrl = _get(_config('ctrl_key'), $mca[1]); 89 | self::$action = _get(_config('action_key'), $mca[2]); 90 | self::$classNamePace = 'app\\' . self::$module . '\\ctrl\\' . self::$ctrl; 91 | $className = str_replace('\\', '/', self::$classNamePace); 92 | if (!is_file($className . '.php')) { 93 | return false; 94 | } 95 | $tmpParam = ''; 96 | if (self::$matchUrl) { 97 | $tmpParam = substr($pathInfo, strpos($pathInfo, self::$matchUrl) + strlen(self::$matchUrl)); 98 | } 99 | if (strpos($param, 'p') !== false) { 100 | //处理后方参数 101 | preg_match_all('#/([\S][^\{^\}^/]*)/([\S][^\{^\}^/]*)#', '/' . $tmpParam, $matchArr, PREG_SET_ORDER); 102 | foreach ($matchArr as $item) { 103 | self::$get[$item[1]] = $item[2]; 104 | } 105 | } else { 106 | if ($tmpParam != '') { 107 | return false; 108 | } 109 | } 110 | return true; 111 | } 112 | 113 | private static $pathInfo = ""; 114 | 115 | public static function path_info() { 116 | if (!empty(static::$pathInfo)) { 117 | return static::$pathInfo; 118 | } 119 | if (isset($_SERVER['PATH_INFO']) && !empty($_SERVER['PATH_INFO'])) { 120 | return static::$pathInfo = $_SERVER['PATH_INFO']; 121 | } 122 | //如果没有pathinfo,自己处理通过请求的url处理 123 | $pathInfo = $_SERVER['REQUEST_URI']; 124 | //删除的url中的脚本路径和脚本名字 125 | $scriptPath = substr($_SERVER['SCRIPT_NAME'], 0, strrpos($_SERVER['SCRIPT_NAME'], '/')); 126 | $scriptName = substr($_SERVER['SCRIPT_NAME'], strrpos($_SERVER['SCRIPT_NAME'], '/') + 1); 127 | $pathInfo = substr($pathInfo, strlen($scriptPath)); 128 | if (($pos = strpos($pathInfo, $scriptName)) === 1) { 129 | $pathInfo = '/' . substr($pathInfo, $pos + strlen($scriptName)); 130 | } 131 | //删除get参数? 132 | if ($pos = strrpos($pathInfo, '?')) { 133 | $pathInfo = substr($pathInfo, 0, $pos); 134 | } 135 | return static::$pathInfo = $pathInfo; 136 | } 137 | 138 | /** 139 | * 解析URL,加载控制类 140 | * @access public 141 | * @author Farmer 142 | */ 143 | static function analyze() { 144 | self::$req_method = strtolower($_SERVER['REQUEST_METHOD']); 145 | $pathInfo = self::path_info(); 146 | if (!empty($pathInfo) && $pathInfo != '/') { 147 | if (isset(self::$rule[self::$req_method])) { 148 | $tmpRule = self::$rule[self::$req_method]; 149 | foreach ($tmpRule as $key => $value) { 150 | //匹配规则 151 | if (self::matchRule([$key, $value], $pathInfo)) { 152 | if (self::runAction()) { 153 | return; 154 | } 155 | } 156 | } 157 | } 158 | $tmpRule = self::$rule['*']; 159 | foreach ($tmpRule as $key => $value) { 160 | //匹配规则 161 | if (self::matchRule([$key, $value], $pathInfo)) { 162 | if (self::runAction()) { 163 | return; 164 | } 165 | } 166 | } 167 | _404(); 168 | return; 169 | } else { 170 | self::$module = _get(_config('module_key'), __DEFAULT_MODULE_); 171 | self::$ctrl = _get(_config('ctrl_key'), 'index'); 172 | self::$action = _get(_config('action_key'), 'index'); 173 | self::$classNamePace = 'app\\' . self::$module . '\\ctrl\\' . self::$ctrl; 174 | $className = str_replace('\\', '/', self::$classNamePace); 175 | if (!is_file($className . '.php')) { 176 | _404(); 177 | return false; 178 | } 179 | self::runAction(); 180 | return; 181 | } 182 | } 183 | 184 | 185 | static function runAction() { 186 | input('module', route::$module); 187 | input('ctrl', route::$ctrl); 188 | input('action', route::$action); 189 | //加载全局函数 190 | $comPath = __ROOT_ . '/app/common.php'; 191 | if (file_exists($comPath)) { 192 | require_once $comPath; 193 | } 194 | //加载模块函数 195 | $comPath = __ROOT_ . '/app/' . self::$module . '/'; 196 | if (file_exists($comPath . 'common.php')) { 197 | require_once $comPath . 'common.php'; 198 | } 199 | try { 200 | input('get', $_GET); 201 | if ($_SERVER['REQUEST_METHOD'] != 'GET') { 202 | $input = file_get_contents('php://input'); 203 | if (sizeof($_POST) <= 0 && $input != '') { 204 | if (strpos(isset($_SERVER['CONTENT_TYPE']) ? $_SERVER['CONTENT_TYPE'] : '', 'application/json') !== false) { 205 | $_POST = json_decode($input, true); 206 | if (!$_POST || sizeof($_POST) <= 0) { 207 | parse_str($input, $_POST); 208 | } 209 | } else { 210 | parse_str($input, $_POST); 211 | } 212 | } 213 | } 214 | input('post', $_POST); 215 | $tmp = self::$classNamePace; 216 | $object = new $tmp(); 217 | if (input('config.rest')) { 218 | $tmpMethod = self::$req_method . self::$action; 219 | if (method_exists($object, $tmpMethod)) { 220 | self::$action = $tmpMethod; 221 | } 222 | } 223 | // 获取方法参数 224 | $method = new \ReflectionMethod ($object, self::$action); 225 | // 参数绑定 226 | $param = []; 227 | $_GET = array_merge($_GET, self::$get); 228 | foreach ($method->getParameters() as $value) { 229 | if ($val = _get($value->getName())) { 230 | $param [] = $val; 231 | } else { 232 | $param [] = $value->isDefaultValueAvailable() ? $value->getDefaultValue() : ''; 233 | } 234 | } 235 | $data = call_user_func_array([ 236 | $object, 237 | self::$action 238 | ], $param); 239 | if (is_array($data)) { 240 | header('Content-Type: application/json; charset=utf-8'); 241 | echo json($data); 242 | } else { 243 | echo $data; 244 | } 245 | } catch (\Throwable $e) { 246 | if (input('config.debug')) { 247 | if (input('config.log')) { 248 | index::$log->error('[file] ' . $e->getFile() . ' [line] ' . $e->getLine() . ' [error] ' . $e->getMessage()); 249 | } 250 | echo "file:" . $e->getFile() . "
\n"; 251 | echo "line:" . $e->getLine() . "
\n"; 252 | echo "error:" . $e->getMessage() . "
\n"; 253 | var_dump($e->getTrace()); 254 | } else { 255 | _404(); 256 | } 257 | } 258 | return true; 259 | } 260 | 261 | /** 262 | * 添加规则 263 | * @access public 264 | * @author Farmer 265 | * @param $req_type 266 | * @param $rule 267 | * @param string $to 268 | */ 269 | static function add($req_type, $rule, $to = '') { 270 | if (is_array($rule)) { 271 | foreach ($rule as $pattern => $value) { 272 | self::$rule [$req_type][$pattern] = $value; 273 | } 274 | } else { 275 | self::$rule [$req_type][$rule] = $to; 276 | } 277 | } 278 | } -------------------------------------------------------------------------------- /icf/lib/view.php: -------------------------------------------------------------------------------- 1 | module = $module; 36 | } 37 | 38 | /** 39 | * 设置值 40 | * 41 | * @author Farmer 42 | * @param string $param 43 | * @param mixed $value 44 | * @return 45 | * 46 | */ 47 | public function assign($param, $value) { 48 | self::$tplVar [$param] = $value; 49 | } 50 | 51 | /** 52 | * 输出模板内容 53 | * @author Farmer 54 | * @param string $filename 55 | * @return null 56 | */ 57 | public function display($filename = '') { 58 | $cache = self::compile($filename); 59 | if ($cache) { 60 | header('Content-type: text/html; charset=utf-8'); 61 | echo $cache; 62 | return true; 63 | } 64 | return false; 65 | } 66 | 67 | /** 68 | * 返回编译内容 69 | * @param $filename 70 | * @return string 71 | */ 72 | public function compile($filename = '') { 73 | if ($filename === '') { 74 | $filename = input('action'); 75 | } 76 | if (strpos($filename, '/') === false) { 77 | $path = __ROOT_ . '/app/' . input('module') . '/tpl/' . input('ctrl') . '/' . $filename; 78 | } else { 79 | $path = __ROOT_ . '/app/' . input('module') . '/tpl/' . $filename; 80 | } 81 | $suffix = '.' . input('config.tpl_suffix'); 82 | if (substr($path, strlen($path) - strlen($suffix), strlen($suffix)) != $suffix) { 83 | $path .= $suffix; 84 | } 85 | if (!is_file($path)) { 86 | echo '
template load error'; 87 | return false; 88 | } 89 | $cache = __ROOT_ . '/app/cache/tpl/' . md5($path) . '.php'; 90 | return self::fetch($path, $cache); 91 | } 92 | 93 | /** 94 | * 生成编译文件并返回 95 | * 96 | * @author Farmer 97 | * @param string $path 98 | * @param string $cache 99 | * @return 100 | * 101 | */ 102 | private function fetch($path, $cache) { 103 | $fileData = file_get_contents($path); 104 | if (!file_exists($cache) || filemtime($path) > filemtime($cache)) { 105 | $pattern = array( 106 | '/\{(\$[\w\[\]\']+)\}/', 107 | '/{break}/', 108 | '/{continue}/', 109 | '/{if (.*?)}/', 110 | '/{\/if}/', 111 | '/{elseif (.*?)}/', 112 | '/{else}/', 113 | '/{foreach (.*?)}/', 114 | '/{\/foreach}/', 115 | "/{include '(.*?)'}/", 116 | '/{\:(.*?)}/' 117 | ); 118 | $replace = array( 119 | '', 120 | '', 121 | '', 122 | '', 123 | '', 124 | '', 125 | '', 126 | '', 127 | '', 128 | 'display("${1}");?>', 129 | '' 130 | ); 131 | $cacheData = preg_replace($pattern, $replace, $fileData); 132 | @file_put_contents($cache, $cacheData); 133 | } else { 134 | $cacheData = file_get_contents($cache); 135 | } 136 | $pattern = array( 137 | '/__HOME__/' 138 | ); 139 | $replace = array( 140 | __HOME_ 141 | ); 142 | $cacheData = preg_replace($pattern, $replace, $cacheData); 143 | preg_match_all('/\{\$([a-zA-Z0-9]+)\}/', $fileData, $tmp); 144 | for ($i = 0; $i < sizeof($tmp [1]); $i++) { 145 | if (!isset (self::$tplVar [$tmp [1] [$i]])) { 146 | self::$tplVar [$tmp [1] [$i]] = ''; 147 | } 148 | } 149 | ob_start(); 150 | extract(self::$tplVar); 151 | eval ('?>' . $cacheData); 152 | $content = ob_get_contents(); 153 | ob_end_clean(); 154 | return $content; 155 | } 156 | } -------------------------------------------------------------------------------- /icf/loader.php: -------------------------------------------------------------------------------- 1 | 'icf/lib']; 17 | //已加载 18 | static $loaded = []; 19 | 20 | /** 21 | * 加载类 22 | * @param $className 23 | * @return bool 24 | */ 25 | static function loadClass($className) { 26 | if (in_array($className, self::$loaded)) { 27 | return true; 28 | } 29 | self::$loaded[] = $className; 30 | //处理斜杠,linux系统中得用/ 31 | $className = str_replace('\\', '/', $className); 32 | //取出左边的路径 33 | $rootPath = substr($className, 0, strpos($className, '/')); 34 | $loadFile = __ROOT_ . '/' . (isset(loader::$path[$rootPath]) ? loader::$path[$rootPath] : $rootPath); 35 | $loadFile .= substr($className, strpos($className, '/')) . '.php'; 36 | if (!is_file($loadFile)) { 37 | $loadFile = __ROOT_ . '/icf/lib/' . (isset(loader::$path[$rootPath]) ? loader::$path[$rootPath] : $rootPath); 38 | $loadFile .= substr($className, strpos($className, '/')) . '.php'; 39 | } 40 | if (is_file($loadFile)) { 41 | require_once $loadFile; 42 | } 43 | return true; 44 | } 45 | } -------------------------------------------------------------------------------- /index.php: -------------------------------------------------------------------------------- 1 | start(); 23 | --------------------------------------------------------------------------------