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); }}
1、php版本最好5.6 我用5.4版本同样的秘钥失败
2、加密的格式
3、加密好的签名进行base64转码获得字符串
4、url拼接http_build_query
5、header头部发送的设置