<?php
namespace Org\Kudian;

use Org\Kudian\Request\H5PayRequest;
use Org\Kudian\Request\Request;

class Api
{
    private static $client;

    private static function getClient() {
        if (!self::$client) {
            self::$client = new Client();
        }
        return self::$client;
    }

    public static function h5Pay($orderNumber, $amount, $notifyUrl, $backUrl, $payType, $body, $clientIp) {
        $request = new H5payRequest(Config::get('mch_id'), Config::get('secret_key'));
        $request->setContent([
            'fee' => $amount,
            'out_trade_no' => $orderNumber,
            'body' => $body,
            'client_ip' => $clientIp,
            'notify_url' => $notifyUrl,
            'payment' => $payType,
            'sence_info' => [
                'wap_url' => 'http://www.hexidongkeji.top',
                'wap_name' => '聚游',
                'return_url' => $backUrl,
            ],
        ]);
        return self::getClient()->request($request);
    }
}