class SimpleERP { private $_config; private $_domain; private $_private_pem="./private.pem"; public function __construct() { if(version_compare(PHP_VERSION,'5.5.9','<')) die('require PHP > 5.5.9 !'); $this->_config = require 'config.php'; } public function login() { $user["tokenEnc"] = $this->_config['AUTH_TOKEN_ENC']; $user['sign'] =$this->getSign($this->_config['AUTH_TOKEN_ENC']); $urlData= http_build_query($user); $url = $this->_config['WEB_URL'] . "system/user/loginByToken.do"; $header=array( 'user-agent:SIMPLE-HTTPCLIENT-RELEASED-RSA2', 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' ); $res = HttpService::postRequest($url, $urlData,$header); var_dump($res); } private function getSign($data=""){ $private_key= file_get_contents($this->_private_pem); $res= openssl_get_privatekey($private_key); openssl_sign($data, $sign,$res,OPENSSL_ALGO_SHA256); return base64_encode($sign); } }
一、php版本最好5.6 我用5.4版本一樣的祕鑰失敗php
二、加密的格式app
三、加密好的簽名進行base64轉碼得到字符串dom
四、url拼接http_build_querypost
五、header頭部發送的設置 ui