laravel5.5 easywechat 小程序支付

    public function mpPay()
    {
        $options = [
            'app_id' => '',
            'mch_id' => '',
            'key' => '',
            'notify_url' => '',
            'sandbox' => true,
        ];

        $payment = Factory::payment($options);
        $jssdk = $payment->jssdk;


        $attributes = [
            'trade_type' => 'JSAPI',
            'body' => 'ceshi',
            'out_trade_no' => 'ceshi074392473921',
            'total_fee' => 1.01*100,
            'openid' => ''
        ];

        $result = $payment->order->unify($attributes);
        if ($result['return_code'] == 'FAIL') {
            return apiBack(400, $result['return_msg']);
        }
        if ($result['return_code'] == 'SUCCESS') {

            $prepayId = $result['prepay_id'];
            $config = $jssdk->sdkConfig($prepayId);

            return apiBack(200, 'success', [
                'wx_res' => $config
            ]);
        }

        if ($result['return_code'] == 'FAIL' && array_key_exists('return_msg', $result)) {

            return apiBack(400, $result['return_msg']);
        }
    }

猜你喜欢

转载自blog.csdn.net/qq2942713658/article/details/115212281