コード例 #1
0
ファイル: signed.php プロジェクト: trustly/trustly-client-php
 /**
  * Insert a signature into the outgoing request.
  *
  * @throws Trustly_SignatureException if private key has not been loaded
  *		yet or if we for some other reason fail to sign the request.
  *
  * @param Trustly_Data_JSONRPCRequest $request Request to sign.
  */
 public function signMerchantRequest($request)
 {
     if (!isset($this->merchant_privatekey)) {
         throw new Trustly_SignatureException('No private key has been loaded for signing');
     }
     $method = $request->getMethod();
     if ($method === NULL) {
         $method = '';
     }
     $uuid = $request->getUUID();
     if ($uuid === NULL) {
         $uuid = '';
     }
     $data = $request->getData();
     $serial_data = $method . $uuid . $this->serializeData($data);
     $raw_signature = '';
     $this->clearOpenSSLError();
     if (openssl_sign($serial_data, $raw_signature, $this->merchant_privatekey, OPENSSL_ALGO_SHA1) === TRUE) {
         return base64_encode($raw_signature);
     }
     throw new Trustly_SignatureException('Failed to sign the outgoing merchant request. ' . openssl_error_string());
 }