123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151 |
- <?php
- declare (strict_types=1);
- namespace app\services\pay;
- use crmeb\services\AliPayService;
- use crmeb\services\wechat\Payment;
- use think\exception\ValidateException;
- class PayServices
- {
-
- const WEIXIN_PAY = 'weixin';
-
- const YUE_PAY = 'yue';
-
- const OFFLINE_PAY = 'offline';
-
- const ALIAPY_PAY = 'alipay';
-
- const CASH_PAY = 'cash';
-
- const PAY_TYPE = [
- PayServices::WEIXIN_PAY => '微信支付',
- PayServices::YUE_PAY => '余额支付',
- PayServices::OFFLINE_PAY => '线下支付',
- PayServices::ALIAPY_PAY => '支付宝',
- PayServices::CASH_PAY => '现金支付',
- ];
-
- protected $authCode;
-
- public function setAuthCode(string $authCode)
- {
- $this->authCode = $authCode;
- return $this;
- }
-
- public function pay(string $payType, string $openid, string $orderId, string $price, string $successAction, string $body, bool $isCode = false)
- {
- try {
- switch ($payType) {
- case 'routine':
-
- if (request()->isApp()) {
- return Payment::appPay($openid, $orderId, $price, $successAction, $body);
- } else {
-
- if (sys_config('pay_routine_open', 0)) {
- return Payment::miniPay($openid, $orderId, $price, $successAction, $body);
- } else {
-
- if (Payment::instance()->isV3PAy) {
- return Payment::instance()->application()->v3pay->miniprogPay($openid, $orderId, $price, $body, $successAction);
- }
- return Payment::jsPay($openid, $orderId, $price, $successAction, $body);
- }
- }
- case 'weixinh5':
-
- if (Payment::instance()->isV3PAy) {
- return Payment::instance()->application()->v3pay->h5Pay($orderId, $price, $body, $successAction);
- }
-
- return Payment::paymentOrder(null, $orderId, $price, $successAction, $body, '', 'MWEB');
- case self::WEIXIN_PAY:
-
- if ($this->authCode) {
- return Payment::microPay($this->authCode, $orderId, $price, $successAction, $body);
- } else {
-
- if (request()->isApp()) {
- return Payment::appPay($openid, $orderId, $price, $successAction, $body);
- } else {
-
- if (Payment::instance()->isV3PAy) {
- return Payment::instance()->application()->v3pay->jsapiPay($openid, $orderId, $price, $body, $successAction);
- }
-
- return Payment::jsPay($openid, $orderId, $price, $successAction, $body);
- }
- }
- case self::ALIAPY_PAY:
- if ($this->authCode) {
- return AliPayService::instance()->microPay($this->authCode, $body, $orderId, $price, $successAction);
- } else {
- return AliPayService::instance()->create($body, $orderId, $price, $successAction, $openid, $openid, $isCode);
- }
- case 'pc':
- case 'store':
-
- return Payment::nativePay($openid, $orderId, $price, $successAction, $body);
- default:
- throw new ValidateException('支付方式不存在');
- }
- } catch (\Throwable $e) {
- throw new ValidateException($e->getMessage());
- }
- }
- }
|