PayServices.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. declare (strict_types=1);
  12. namespace app\services\pay;
  13. use crmeb\exceptions\ApiException;
  14. use crmeb\services\pay\Pay;
  15. /**
  16. * 支付统一入口
  17. * Class PayServices
  18. * @package app\services\pay
  19. */
  20. class PayServices
  21. {
  22. /**
  23. * 微信支付类型
  24. */
  25. const WEIXIN_PAY = 'weixin';
  26. /**
  27. * 余额支付
  28. */
  29. const YUE_PAY = 'yue';
  30. /**
  31. * 线下支付
  32. */
  33. const OFFLINE_PAY = 'offline';
  34. /**
  35. * 支付宝
  36. */
  37. const ALIAPY_PAY = 'alipay';
  38. /**
  39. * 好友代付
  40. */
  41. const FRIEND = 'friend';
  42. /**
  43. * 支付方式
  44. * @var string[]
  45. */
  46. const PAY_TYPE = [
  47. PayServices::WEIXIN_PAY => '微信支付',
  48. PayServices::YUE_PAY => '余额支付',
  49. PayServices::OFFLINE_PAY => '线下支付',
  50. PayServices::ALIAPY_PAY => '支付宝',
  51. PayServices::FRIEND => '好友代付',
  52. ];
  53. /**
  54. * 发起支付
  55. * @param string $payType
  56. * @param string $openid
  57. * @param string $orderId
  58. * @param string $price
  59. * @param string $successAction
  60. * @param string $body
  61. * @return array|string
  62. */
  63. public function pay(string $payType, string $openid, string $orderId, string $price, string $successAction, string $body, bool $isCode = false)
  64. {
  65. try {
  66. //这些全都是微信支付
  67. if (in_array($payType, ['routine', 'weixinh5', 'weixin', 'pc', 'store'])) {
  68. $payType = 'wechat_pay';
  69. }
  70. if ($payType == 'alipay') {
  71. $payType = 'ali_pay';
  72. }
  73. /** @var Pay $pay */
  74. $pay = app()->make(Pay::class, [$payType]);
  75. return $pay->create($orderId, $price, $successAction, $body, '', ['openid' => $openid, 'isCode' => $isCode,'pay_new_weixin_open' => (bool)sys_config('pay_new_weixin_open')]);
  76. } catch (\Exception $e) {
  77. throw new ApiException($e->getMessage());
  78. }
  79. }
  80. }