2019-10-25 15:20:09 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
2020-03-05 12:41:49 +08:00
|
|
|
namespace wchat\qq;
|
2019-10-25 15:20:09 +08:00
|
|
|
|
2020-08-10 11:19:52 +08:00
|
|
|
use Exception;
|
2020-03-05 12:41:49 +08:00
|
|
|
use wchat\common\Help;
|
2019-10-25 15:20:09 +08:00
|
|
|
|
2020-08-10 11:17:42 +08:00
|
|
|
/**
|
|
|
|
|
* Class Notify
|
|
|
|
|
* @package wchat\qq
|
|
|
|
|
*/
|
2019-11-11 18:14:47 +08:00
|
|
|
class Notify extends SmallProgram
|
2019-10-25 15:20:09 +08:00
|
|
|
{
|
2022-09-09 16:42:55 +08:00
|
|
|
public mixed $appid = null;
|
|
|
|
|
public mixed $mch_id = null;
|
|
|
|
|
public mixed $nonce_str = null;
|
|
|
|
|
public mixed $sign = null;
|
|
|
|
|
public mixed $device_info = null;
|
|
|
|
|
public mixed $trade_type = null;
|
|
|
|
|
public mixed $trade_state = null;
|
|
|
|
|
public mixed $bank_type = null;
|
|
|
|
|
public mixed $fee_type = null;
|
|
|
|
|
public mixed $total_fee = null;
|
|
|
|
|
public mixed $cash_fee = null;
|
|
|
|
|
public mixed $coupon_fee = null;
|
|
|
|
|
public mixed $transaction_id = null;
|
|
|
|
|
public mixed $out_trade_no = null;
|
|
|
|
|
public mixed $attach = null;
|
|
|
|
|
public mixed $time_end = null;
|
|
|
|
|
public mixed $openid = null;
|
2019-10-25 15:20:09 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return bool
|
|
|
|
|
* 判断是否完成支付
|
|
|
|
|
*/
|
2022-09-09 16:42:55 +08:00
|
|
|
public function isSuccess(): bool
|
2019-10-25 15:20:09 +08:00
|
|
|
{
|
2022-09-09 16:42:55 +08:00
|
|
|
return $this->trade_state === 'SUCCESS';
|
2019-10-25 15:20:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return $this
|
2020-08-10 11:19:52 +08:00
|
|
|
* @throws Exception
|
2019-10-25 15:20:09 +08:00
|
|
|
*/
|
2022-09-09 16:42:55 +08:00
|
|
|
public function setPayNotifyData(array $params): static
|
2019-10-25 15:20:09 +08:00
|
|
|
{
|
|
|
|
|
if (!$this->validation($params)) {
|
2020-08-10 11:19:52 +08:00
|
|
|
throw new Exception('签名错误!');
|
2019-10-25 15:20:09 +08:00
|
|
|
}
|
|
|
|
|
foreach ($params as $key => $val) {
|
|
|
|
|
$this->$key = $val;
|
|
|
|
|
}
|
|
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2022-09-09 16:42:55 +08:00
|
|
|
public function __set(string $name, $value): void
|
|
|
|
|
{
|
|
|
|
|
if (property_exists($this, $name)) {
|
|
|
|
|
$this->{$name} = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2019-10-25 15:20:09 +08:00
|
|
|
/**
|
|
|
|
|
* @param array $params
|
|
|
|
|
* @return bool
|
|
|
|
|
*/
|
2022-09-09 16:42:55 +08:00
|
|
|
public function validation(array $params): bool
|
2019-10-25 15:20:09 +08:00
|
|
|
{
|
|
|
|
|
$sign = $params['sign'];
|
|
|
|
|
unset($params['sign']);
|
|
|
|
|
|
|
|
|
|
$signType = $this->config->getSignType();
|
|
|
|
|
$privateKey = $this->config->getKey();
|
|
|
|
|
$nowSign = Help::sign($params, $privateKey, $signType);
|
|
|
|
|
if ($sign === $nowSign) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2020-08-10 11:17:42 +08:00
|
|
|
* @return null
|
2019-10-25 15:20:09 +08:00
|
|
|
*/
|
|
|
|
|
public function getAppid()
|
|
|
|
|
{
|
|
|
|
|
return $this->appid;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-10 11:17:42 +08:00
|
|
|
|
2019-10-25 15:20:09 +08:00
|
|
|
}
|