public final function parameter($orderNo, $orderDatetime, $queryDatetime) { if (empty($orderNo) || empty($orderDatetime) || empty($queryDatetime)) { throw new Exception('订单编号、订单时间和订单查询时间为必要参数!'); } $this->value['orderNo'] = $orderNo; $this->value['orderDatetime'] = $orderDatetime; $this->value['queryDatetime'] = $queryDatetime; $this->postData = $this->sort($this->properties, $this->value); $this->postData['signMsg'] = Encrypt::MD5_sign($this->postData, $this->config['md5key']); return $this; }
protected final function verify() { if (empty($this->value)) { return false; } $this->value = $this->sort($this->properties, $this->value); $originalSign = $this->value['signMsg']; unset($this->value['signMsg']); $sign = ''; //TODO:因为目前仅支持MD5加密方式 if ($this->value['signType'] == self::ENCRYPT_MD5) { $sign = Encrypt::MD5_sign($this->value, $this->key); } return $sign === $originalSign; }
public final function parameter($orderNo, $orderAmount, $payType = 0) { //$orderNo, $orderAmount, $payType = 0 if (empty($orderNo) || empty($orderAmount)) { throw new InvalidArgumentException('缺少重要参数!'); } if (strlen($orderNo) > 50) { throw new InvalidArgumentException('订单号长度不能超过50!'); } if (round($orderAmount, 2) != $orderAmount) { throw new InvalidArgumentException('金额不正确,仅支持到分!'); } $this->value['orderDatetime'] = date('YmdHis', time()); $this->value['orderNo'] = $orderNo; $this->value['orderAmount'] = $orderAmount * 100; //转为分 $payTypeList = [self::PAY_TYPE_PERSONAL, self::PAY_TYPE_ENTERPRISE, self::PAY_TYPE_WAP, self::PAY_TYPE_CREDIT, self::PAY_TYPE_QUICK, self::PAY_TYPE_AUTH, self::PAY_TYPE_WILDCARD]; $payType = empty($payType) ? self::PAY_TYPE_PERSONAL : $payType; if (!in_array($payType, $payTypeList)) { throw new InvalidArgumentException('暂不支持此支付方式!'); } $this->value['payType'] = $payType; $this->postData = $this->sort($this->properties, $this->value); $this->postData['signMsg'] = Encrypt::MD5_sign($this->postData, $this->config['md5key']); return $this; }