GithubHelp home page GithubHelp logo

guoyu07 / authcode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wolferhua/authcode

0.0 0.0 0.0 8 KB

项目中用base64传输数据,使用后发现 base64 会有 +、/、= 三种特殊字符,会影响数据验证签名。所以在base64基础上进行了一次封装。保证数据传输过程无异常,并参考discuz的加密方法,为数据设置过期时间。

Home Page: http://www.hashmop.com/

License: Apache License 2.0

PHP 100.00%

authcode's Introduction

authcode

项目中用base64传输数据,使用后发现 base64 会有 +、/、= 三种特殊字符,会影响数据验证签名。所以在base64基础上进行了一次封装。保证数据传输过程无异常,并参考discuz的加密方法,为数据设置过期时间。

案例

include 'AuthCode.php';

//打包数据,获得串
$pack = AuthCode::pack([
    'name' => 'wolferhua',
    'mail' => '[email protected]',
    'sex' => 'man',
    'site'=>'http://www.hashmop.com/'
]);

echo $pack . PHP_EOL;
//e3Z6sGiJJAkhIiIcImlJdHEiOBJObTCwUyN0MEZNTGIwMGUwSWRhbUgwSk5VME16VVkwanh6TVdnMVFsRngwbWp2YnlJczR6NWhiV29pT2lKM2IyY3paWEpvZFdFaUxDSnpaWGdpT2lKdFlXNGlMQ0p6YVhSbElqb2lhSFIwY0RwY0wxd3ZkM2QzTG1oaGMyaHRiM0F1WTI5dFhDOGlmUSIsInNpZ24iOiI3OWMwNjM4NzIwNDJhZmEyNjI3ZDFmYzYwMjhkZmVkNyIsInRpbWVzdGFtcCI6MTUxMDIxMTc2OX0

//解包串
$data = AuthCode::unpack($pack);
var_dump($data);
/**
array(4) {
  ["appId"]=>
  string(0) ""
  ["data"]=>
  array(4) {
    ["mail"]=>
    string(16) "[email protected]"
    ["name"]=>
    string(9) "wolferhua"
    ["sex"]=>
    string(3) "man"
    ["site"]=>
    string(23) "http://www.hashmop.com/"
  }
  ["sign"]=>
  string(32) "79c063872042afa2627d1fc6028dfed7"
  ["timestamp"]=>
  int(1510211769)
}

*/
//解包串,获得原始数据。
$data = AuthCode::getDataByPack($pack);
var_dump($data);
/**
array(4) {
  ["mail"]=>
  string(16) "[email protected]"
  ["name"]=>
  string(9) "wolferhua"
  ["sex"]=>
  string(3) "man"
  ["site"]=>
  string(23) "http://www.hashmop.com/"
}
*/

authcode's People

Contributors

wolferhua avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.