MiniPay.php 820 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php namespace App\Servers\WechatMini;
  2. use EasyWeChat\Factory;
  3. use Ixudra\Curl\Facades\Curl;
  4. /**
  5. * 微信小程序
  6. *
  7. */
  8. class MiniPay
  9. {
  10. protected $payment;
  11. public function __construct(Factory $factory)
  12. {
  13. $this->payment = $factory->payment(config('wechat.mini_pay',[]));
  14. }
  15. /**
  16. * 微信小程序支付下单
  17. *
  18. */
  19. public function unifiedOrder($request)
  20. {
  21. $result = $this->payment->order->unify($request);
  22. if ($result['return_code'] === 'SUCCESS' && !isset($result['err_code'])) {
  23. $prepayId = $result['prepay_id'];
  24. $json = $this->payment->jssdk->sdkConfig($prepayId);
  25. return response()->json($json);
  26. } else {
  27. return response()->json(['error' => '创建订单失败'], 500);
  28. }
  29. }
  30. }