JoinpayPaymentGlobal.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace common\globals;
  3. use common\globals\BaseGlobal;
  4. use common\globals\GlobalInvoke;
  5. use common\models\common\AddonsInvoker;
  6. class JoinpayPaymentGlobal extends BaseGlobal
  7. {
  8. /**
  9. * 汇聚支付-聚合支付
  10. * @param [type] $invokes
  11. * @param array $params
  12. * @return array
  13. */
  14. public function joinPay($invokes, $params = [])
  15. {
  16. $pay_type = \addons\JoinPay\common\enums\JoinPayTypeEnum::action(\addons\JoinPay\common\enums\JoinPayTypeEnum::JOINPAY);
  17. $order = [
  18. 'title' => $params['trade']->title,
  19. 'order_no' => $params['trade']->out_trade_no,
  20. 'amount' => $params['trade']->pay_fee,
  21. 'mall_id' => $params['trade']->mall_id,
  22. // 'notify_url' => Url::toApi(['notify/' . $pay_type], TRUE),
  23. 'notify_url' => \Yii::$app->request->hostInfo . '/join-pay/notify/' . $pay_type,
  24. 'type' => $params['trade_type'],
  25. 'open_id' => $params['openid'] ?? '',
  26. ];
  27. $config = \Yii::$app->services->setting->mall->get($params['trade']->mall_id, 'pay.' . $pay_type, true);
  28. $config = json_decode($config, true);
  29. // dd($invokes, $order, $config);
  30. foreach ($invokes as $invoke) {
  31. $result = $this->invoke($invoke['class'], $invoke['method'], $order, $config);
  32. $is_success = $this->validateInvokeReturn($params['invoke_id'], $result);
  33. if (!$is_success) {
  34. throw new \Exception('结果数据格式校验未通过');
  35. }
  36. }
  37. return $result;
  38. }
  39. /**
  40. * 汇聚支付-快捷支付
  41. * @param [type] $invokes
  42. * @param array $params
  43. * @return array
  44. */
  45. public function fastPay($invokes, $params = [])
  46. {
  47. $order = [
  48. 'order_no' => $params['trade']->out_trade_no,
  49. 'sms_code' => $params['sms_code'],
  50. 'created_at' => $params['trade']->created_at
  51. ];
  52. $pay_type = \addons\JoinPay\common\enums\JoinPayTypeEnum::action(\addons\JoinPay\common\enums\JoinPayTypeEnum::JOINPAY_FAST_PAY);
  53. $config = \Yii::$app->services->setting->mall->get($params['trade']->mall_id, 'pay.' . $pay_type, true);
  54. $config = json_decode($config, true);
  55. foreach ($invokes as $invoke) {
  56. $result = $this->invoke($invoke['class'], $invoke['method'], $order, $config);
  57. $is_success = $this->validateInvokeReturn($params['invoke_id'], $result);
  58. // 全局调用获取提现条件
  59. if (!$is_success) {
  60. throw new \Exception('结果数据格式校验未通过');
  61. }
  62. }
  63. return $result;
  64. }
  65. /**
  66. * 验证调用结果
  67. * @param [type] $return
  68. * @return boolean
  69. */
  70. protected function validateJoinPay($return = null): bool
  71. {
  72. return true;
  73. }
  74. /**
  75. * 验证调用结果
  76. * @param [type] $return
  77. * @return boolean
  78. */
  79. protected function validateFastPay($return = null): bool
  80. {
  81. return true;
  82. }
  83. }