PHP code example of kaer / wxpay-for-laravel

1. Go to this page and download the library: Download kaer/wxpay-for-laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kaer / wxpay-for-laravel example snippets


$wxpay = app('wxpay.app');
$wxpay->setBody("app在线支付")
      ->setTradeNo($trade_no)
      ->setTotalFee(($order->money * 100));
$result = $wxpay->unifiedOrder();//统一下单结果
if ($result['return_code'] === 'SUCCESS' &&$result['result_code'] == 'SUCCESS') {
   $prepay_id = $result['prepay_id'];
   $rst = $wxpay->getAppPayParams($prepay_id);
   return $rst;
} else {
 //统一下单失败
}


        $WXPay = app('wxpay.app');
        $data = $WXPay->getNotifyData();
        // 验证请求。
        if (!$WXPay->verify()) {
            //验证失败
            return $WXPay->replyFailNotify();
        }
        if ($data['result_code'] == "SUCCESS") {
            $money = ($data['total_fee'] / 100);
            $out_trade_no = $data['out_trade_no'];
            $wx_trade_no = $data['transaction_id'];
            //你的业务
        }
        return $WXPay->replySuccessNotify();