mrmiao / think-interface-encryption
Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm
Installs: 195
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Type:think-interface-encryption
Requires
- ext-openssl: *
README
Encrypt the JSON-type interface request and return data by using the RSA
这个扩展包深度依赖TP5框架
- 使用到大量的tp框架下的帮助函数
- 加密类依赖了框架的配置文件的自动加载模式
- 加密类配置文件生成依赖了框架的命令行方式
预定义了异常 code
- 100 缺少配置文件
- 101 请求参数解析失败
- 102 请求方式错误
- 103 请求参数数量与规则不符
- 104 错误的请求参数
请求参数支持严格规则
- $rule 严格设定的参数规则,['参数名'=>'参数类型']
- 参数类型包括,会强制转换类型
- array 数组
- int 整数
- float 浮点数
- boolean 布尔值
- string 字串
注意
- 配置文件rsa_config.php位于 application/extra目录下
- debug设置,本地开发环境中设为 true,调试模式; 线上环境中设为 false,接口模式;
- 在接口模式下,请求强制要求为json类型
- 在接口模式下,请求数据统一强制使用$_REQUEST['param']来获取(既app端统一请求param来放置请求密文数据)
命令行生成配置文件
- 在项目目录下使用命令行命令 php think MakeRSAConfig
对接app
- 需要提供给APP端rsa_config配置文件里的 request_pubKey 和 response_privKey
如何设置明文请求调试
- 在rsa_config_path文件中将debug设置为true
调用示例
<?php
namespace app\index\controller;
//引用RSACrypt加密类
use mrmiao\encryption\RSACrypt;
class Index
{
//在方法中实例化加密类
function encrypt(RSACrypt $crypt){
//调用request()方法获取请求参数,request方法可选参数数组['参数名'=>'强制转换类型']
$param = $crypt->request(['user_id'=>'int','mobile'=>'array','quest_time'=>'int','app_id'=>'string']);
//解析后参数变为明文数据
$param['php_add'] = '正常使用参数数据';
//调用response()方法返回数据,参数为数组
return $crypt->response(['code'=>200,'message'=>'success','data'=>$param],true);
}
}
```