PayStatusService.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace crmeb\services;
  12. use think\exception\ValidateException;
  13. class PayStatusService
  14. {
  15. protected $type;
  16. protected $options;
  17. public function __construct(string $type, array $options)
  18. {
  19. $this->type = $type;
  20. $this->options = $options;
  21. }
  22. public function query()
  23. {
  24. $method = 'query' . ucfirst($this->type);
  25. if (!method_exists($this, $method)) {
  26. throw new ValidateException('不支持该支付方式');
  27. }
  28. return $this->{$method}();
  29. }
  30. /**
  31. * 微信扫码支付查询订单状态
  32. *
  33. * @return void
  34. */
  35. protected function queryWeixinBarCode() : array
  36. {
  37. $res = WechatService::create()->query($this->options['order_sn']);
  38. if($res->return_code == 'SUCCESS' && $res->result_code == 'SUCCESS' && $res->trade_state == 'SUCCESS') {
  39. return ['transaction_id' => $res->transaction_id];
  40. }
  41. return [];
  42. }
  43. /**
  44. * 支付宝扫码支付查询订单状态
  45. *
  46. * @return void
  47. */
  48. protected function queryAlipayBarCode()
  49. {
  50. $res = AlipayService::create()->query($this->options['order_sn']);
  51. if($res['code'] == '10000' && $res['msg'] == 'Success') {
  52. return ['transaction_id' => $res['trade_no']];
  53. }
  54. return [];
  55. }
  56. }