public function testGetContentToSign() { $params1 = ['bbb' => '2222', 'ccc' => '3333', 'aaa' => '111', 's' => '"."', 'e' => '', 'apple' => 'jobs']; $signer = new Signer($params1); $signer->setIgnores(['apple']); $content = $signer->getContentToSign(); $this->assertEquals('aaa=111&bbb=2222&ccc=3333&s="."', $content); }
/** * Get the raw data array for this message. The format of this varies from gateway to * gateway, but will usually be either an associative array, or a SimpleXMLElement. * * @return mixed */ public function getData() { $this->validateParams(); $params = $this->getParamsToSign(); $signer = new Signer($params); $sign = $signer->signWithRSA($this->privateKey); $resp['order_string'] = sprintf('%s&sign="%s"&sign_type="RSA"', $signer->getContentToSign(), urlencode($sign)); return $resp; }
protected function verifySignature() { $signer = new Signer($this->params->all()); $signer->setSort($this->sort); $content = $signer->getContentToSign(); $sign = $this->params->get('sign'); $signType = strtoupper($this->params->get('sign_type')); if ($signType == 'MD5') { if (!$this->getKey()) { throw new InvalidRequestException('The `key` is required for `MD5` sign_type'); } $match = (new Signer())->verifyWithMD5($content, $sign, $this->getKey()); } elseif ($signType == 'RSA') { if (!$this->getAlipayPublicKey()) { throw new InvalidRequestException('The `alipay_public_key` is required for `RSA` sign_type'); } $match = (new Signer())->verifyWithRSA($content, $sign, $this->getAlipayPublicKey()); } else { throw new InvalidRequestException('The `sign_type` is invalid'); } if (!$match) { throw new InvalidRequestException('The signature is not match'); } }
protected function verifySignature() { $signer = new Signer($this->params->all()); $signer->setSort($this->sort); $signer->setEncodePolicy($this->encodePolicy); $content = $signer->getContentToSign(); $sign = $this->params->get('sign'); $match = (new Signer())->verifyWithRSA($content, $sign, $this->getAlipayPublicKey()); if (!$match) { throw new InvalidRequestException('The signature is not match'); } }