编程语言
首页 > 编程语言> > laravel5.5 easywechat 小程序支付

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']);
        }
    }

 

标签:code,return,jssdk,程序,easywechat,id,laravel5.5,payment,result
来源: https://blog.51cto.com/u_14097531/2972968