public function testIgnore() { $this->assertSame(['sign', 'sign_type'], (new Signer())->getIgnores()); $params1 = ['aaa' => '111', 'bbb' => '2222', 'ccc' => '3333', 'apple' => 'jobs']; $params2 = ['bbb' => '2222', 'ccc' => '3333', 'aaa' => '111']; $signer = new Signer($params1); $signer->setIgnores(['apple']); $sign1 = $signer->signWithMD5($this->key); $signer = new Signer($params2); $signer->setIgnores(['apple']); $sign2 = $signer->signWithMD5($this->key); $this->assertEquals($sign1, $sign2); $signer = new Signer($params1); $signer->setIgnores([]); $sign3 = $signer->signWithMD5($this->key); $this->assertNotEquals($sign1, $sign3); }
protected function sign($params, $signType) { $signer = new Signer($params); $signType = strtoupper($signType); if ($signType == 'MD5') { if (!$this->getKey()) { throw new InvalidRequestException('The `key` is required for `MD5` sign_type'); } $sign = $signer->signWithMD5($this->getKey()); } elseif ($signType == 'RSA') { if (!$this->getPrivateKey()) { throw new InvalidRequestException('The `private_key` is required for `RSA` sign_type'); } $sign = $signer->signWithRSA($this->getPrivateKey()); } else { throw new InvalidRequestException('The signType is not allowed'); } return $sign; }