PHP code example of fk / pay

1. Go to this page and download the library: Download fk/pay 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/ */

    

fk / pay example snippets


# main-local.php

return [
    // other config
    'components' => [
        'pay' => [
            'class' => 'fk\pay\Component',
            'channel' => 'WeChat', // Here is default channel
            // As for different platforms, the actual notify_url will need a prefix of platform name
            // end with .php
            // e.g.
            // For WeChat, it will be `https://api.alijian.net/notify/we-chat.php`
            // The `we-chat.php` come from `WeChat`.
            // You should rewrite the server route, to fit the filename rule.
            'notifyPath' => 'https://api-test.alijian.net/notify/',
            'platforms' => [
                'WeChat' => [
                    'web' => [ // Web, a.k.a JS, a.k.a H5 payment
                        'app_id' => 'wx71xxx',
                        'app_secret' => 'xxx',
                        'mch_id' => 1234567890,
                        'key' => 'QqDAWHMgDpskKmsdjYH', // to sign
                        'ssl_cert_path' => '@common/data/cache/apiclient_cert.pem', // to refund
                        'ssl_key_path' => '@common/data/cache/apiclient_key.pem',
                    ],
                    'app' => [ // App(iOS, Android) payment
                        'app_id' => 'wxxxxx',
                        'mch_id' => 1234567890,
                        'app_secret' => '6exxx',
                        'key' => 'QqDAWHMgDpskKmsdjYH', // to sign
                        'ssl_cert_path' => '@common/data/cache/apiclient_cert.pem', // to refund
                        'ssl_key_path' => '@common/data/cache/apiclient_key.pem',
                    ]
                ],
                'AliPay' => [ // under construction
                    'name' => 'haha',
                ],
            ]
        ]
    ]
];



$orderSn = '2014124582620133'; // 20 bytes recommended
$amount = 1000; // Money with unit Fen(CNY), 10 Yuan
$name = 'Apple';
$description = 'Sweet Apple';
$extra = [
    'trade_type' => 'JSAPI',
    'openid' => 'o-28js7h4kd01kldfg7ag29zk3'
];
Yii::$app->pay
    ->with('WeChat') // Default defined in config file
    ->pay($orderSn, $amount, $name, $description, $extra);