2017 © Pedro Peláez
 

think-interface-encryption think-interface-encryption

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

image

mrmiao/think-interface-encryption

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  • Monday, June 5, 2017
  • by 896845927
  • Repository
  • 1 Watchers
  • 0 Stars
  • 59 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 11 % Grown

The README.md

think-interface-encryption

Encrypt the JSON-type interface request and return data by using the RSA, (*1)

这个扩展包深度依赖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;, (*2)

//引用RSACrypt加密类 use mrmiao\encryption\RSACrypt;, (*3)

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); } } ```, (*4)

The Versions

05/06 2017

dev-master

9999999-dev

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

05/06 2017

1.08

1.08.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

19/05 2017

1.07

1.07.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

16/05 2017

1.06

1.06.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

02/05 2017

1.05

1.05.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

26/04 2017

1.04

1.04.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

26/04 2017

1.03

1.03.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

23/04 2017

1.02

1.02.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

21/04 2017

1.01

1.01.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

  • ext-openssl *

 

by Avatar 896845927

21/04 2017

1.0

1.0.0.0

Base on TP framework encrypt the JSON-type interface request and return data by using the RSA algorithm

  Sources   Download

The Requires

 

by Avatar 896845927