123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php namespace App\Servers\WechatMini;
- use EasyWeChat\Factory;
- use Ixudra\Curl\Facades\Curl;
- /**
- * 微信小程序
- *
- */
- class MiniPay
- {
- protected $payment;
- public function __construct(Factory $factory)
- {
- $this->payment = $factory->payment(config('wechat.mini_pay',[]));
- }
- /**
- * 微信小程序支付下单
- *
- */
- public function unifiedOrder($request)
- {
- $result = $this->payment->order->unify([
- 'body' => $request->get('body'), // 商品描述
- 'out_trade_no' => $request->get('out_trade_no'), // 商户订单号
- 'total_fee' => $request->get('total_fee'), // 订单金额
- 'notify_url' => $request->get('notify_url'), // 支付结果通知地址
- ]);
- if ($result['return_code'] === 'SUCCESS' && !isset($result['err_code'])) {
- $prepayId = $result['prepay_id'];
- $json = $this->payment->jssdk->sdkConfig($prepayId);
- return response()->json($json);
- } else {
- return response()->json(['error' => '创建订单失败'], 500);
- }
- }
- }
|