credentials = new WechatPay2Credentials($merchantId, new PrivateKeySigner($serialNo, $privateKey)); return $this; } /** * Set Merchant Credentials * * @param Credentials $credentials Merchant Certificate Credentials * * @return $this */ public function withCredentials(Credentials $credentials) { $this->credentials = $credentials; return $this; } /** * Set WechatPay Certificates Infomation * * @param array of string|resource $certifcates WechatPay Certificates (string - PEM formatted \ * certificate, or resource - X.509 certificate resource returned by openssl_x509_read) * * @return $this */ public function withWechatPay(array $certificates) { $this->validator = new WechatPay2Validator(new CertificateVerifier($certificates)); return $this; } /** * Set WechatPay Validator * * @param Validator $Validator WechatPay Validator * * @return $this */ public function withValidator(Validator $validator) { $this->validator = $validator; return $this; } /** * Build WechatPayMiddleware * * @return WechatPayMiddleware */ public function build() { if (!isset($this->credentials)) { throw new \InvalidArgumentException('商户认证信息(credentials)未设置'); } if (!isset($this->validator)) { throw new \InvalidArgumentException('微信支付平台签名验证(validator)未设置'); } return new WechatPayMiddleware($this->credentials, $this->validator); } }