MiniPay.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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([
  22. 'body' => $request->get('body'), // 商品描述
  23. 'out_trade_no' => $request->get('out_trade_no'), // 商户订单号
  24. 'total_fee' => $request->get('total_fee'), // 订单金额
  25. 'notify_url' => $request->get('notify_url'), // 支付结果通知地址
  26. ]);
  27. if ($result['return_code'] === 'SUCCESS' && !isset($result['err_code'])) {
  28. $prepayId = $result['prepay_id'];
  29. $json = $this->payment->jssdk->sdkConfig($prepayId);
  30. return response()->json($json);
  31. } else {
  32. return response()->json(['error' => '创建订单失败'], 500);
  33. }
  34. }
  35. }