request->request('sign','','trim'); if(empty($sign)){ $this->error('缺少签名'); } $sign = base64_decode($sign); $public_key_str = config('app_rsa.public_key'); $public_key = "-----BEGIN PUBLIC KEY-----" .PHP_EOL. wordwrap($public_key_str, 64, PHP_EOL, true) . PHP_EOL."-----END PUBLIC KEY-----"; $signgetdata = ''; //被解密出来的数据 openssl_public_decrypt($sign, $signgetdata, $public_key); // 使用私钥解密数据 if (!$signgetdata) { $this->error('签名错误'); } dump($signgetdata); //接收到的参数 $request_all = $this->request->request(); unset($request_all['s']); unset($request_all['sign']); ksort($request_all); $request_all = json_encode($request_all); dump($request_all); //作对比 if($request_all != $signgetdata){ $this->error('验签错误'); } echo '验签正确'; } //加密 public function jiami(){ $request_all = $this->request->request(); unset($request_all['s']); dump($request_all); ksort($request_all); dump($request_all); $json_data = json_encode($request_all); $private_key_str = config('app_rsa.private_key'); $private_key = "-----BEGIN RSA PRIVATE KEY-----\n". wordwrap($private_key_str, 64, "\n", true). "\n-----END RSA PRIVATE KEY-----"; $sign = ''; openssl_private_encrypt($json_data,$sign,$private_key); $sign = base64_encode($sign); $this->success('获得签名',$sign); } }