// +---------------------------------------------------------------------- namespace crmeb\services; use think\exception\ValidateException; class PayStatusService { protected $type; protected $options; public function __construct(string $type, array $options) { $this->type = $type; $this->options = $options; } public function query() { $method = 'query' . ucfirst($this->type); if (!method_exists($this, $method)) { throw new ValidateException('不支持该支付方式'); } return $this->{$method}(); } /** * 微信扫码支付查询订单状态 * * @return void */ protected function queryWeixinBarCode() : array { $res = WechatService::create()->query($this->options['order_sn']); if($res->return_code == 'SUCCESS' && $res->result_code == 'SUCCESS' && $res->trade_state == 'SUCCESS') { return ['transaction_id' => $res->transaction_id]; } return []; } /** * 支付宝扫码支付查询订单状态 * * @return void */ protected function queryAlipayBarCode() { $res = AlipayService::create()->query($this->options['order_sn']); if($res['code'] == '10000' && $res['msg'] == 'Success') { return ['transaction_id' => $res['trade_no']]; } return []; } }