validate(); } /** * 校验微信支付 appid、商户号、APIv3 密钥、商户证书序列号和商户私钥。 */ public function validate(): void { foreach ([ 'appid' => $this->appid, 'mchId' => $this->mchId, 'apiV3Key' => $this->apiV3Key, 'merchantSerial' => $this->merchantSerial, 'merchantPrivateKey' => $this->merchantPrivateKey, ] as $name => $value) { if (trim($value) === '') { throw new WechatException($name . ' 不能为空'); } } } /** * 从数组创建微信支付 APIv3 商户配置。 * * @param array $data */ public static function fromArray(array $data): static { return new static( (string)($data['appid'] ?? ''), (string)($data['mch_id'] ?? $data['mchid'] ?? ''), (string)($data['api_v3_key'] ?? $data['mch_v3_key'] ?? ''), (string)($data['merchant_serial'] ?? $data['cert_serial'] ?? ''), (string)($data['merchant_private_key'] ?? $data['cert_private'] ?? ''), (string)($data['platform_certificate'] ?? $data['cert_public'] ?? ''), (string)($data['platform_public_key'] ?? ''), (string)($data['platform_serial'] ?? ''), ); } }