快速上手

安装

composer require fengkui/pay

完善支付配置

微信支付

# 微信支付配置
$wechatConfig = [
    'xcxid'         => '', // 小程序 appid
    'appid'         => '', // 微信支付 appid
    'mchid'         => '', // 微信支付 mch_id 商户收款账号
    'key'           => '', // 微信支付 apiV3key(尽量包含大小写字母,否则验签不通过,服务商模式使用服务商key)
    'appsecret'     => '', // 公众帐号 secert (公众号支付获取 code 和 openid 使用)

    'sp_appid'      => '', // 服务商应用 ID
    'sp_mchid'      => '', // 服务商户号

    'notify_url'    => '', // 接收支付状态的连接  改成自己的回调地址
    'redirect_url'  => '', // 公众号支付,调起支付页面

    // 服务商模式下,使用服务商证书
    'serial_no'     => '', // 证书序列号(可不传,默认根据证书直接获取)
    'cert_client'   => './cert/apiclient_cert.pem', // 证书(退款,红包时使用)
    'cert_key'      => './cert/apiclient_key.pem', // 商户私钥(Api安全中下载)
    'public_key'    => './cert/public_key.pem', // 平台公钥(调动证书列表,自动生成,注意目录权限)
];

支付宝支付

# 支付宝支付配置
$alipayConfig = [
    'app_id'        => '', // 开发者的应用ID
    'public_key'    => '', // 支付宝公钥,一行字符串
    'private_key'   => '', // 开发者私钥去头去尾去回车,一行字符串

    'notify_url'    => '', // 异步接收支付状态
    'return_url'    => '', // 同步接收支付状态
    'sign_type'     => 'RSA2', // 生成签名字符串所使用的签名算法类型,目前支持RSA2和RSA,默认使用RSA2
    'is_sandbox'    => false, // 是否使用沙箱调试,true使用沙箱,false不使用,默认false不使用
];

百度支付

# 百度支付配置
$baiduConfig = [
    'deal_id'       => '', // 百度收银台的财务结算凭证
    'app_key'       => '', // 表示应用身份的唯一ID
    'private_key'   => '', // 私钥原始字符串
    'public_key'    => '', // 平台公钥
    'notify_url'    => '', // 支付回调地址
];

字节跳动支付

# 字节跳动支付配置
$bytedanceConfig = [
    'app_id'        => '', // App ID
    'salt'          => '', // 支付密钥值
    'token'         => '', // 回调验签的Token
    'notify_url'    => '', // 支付回调地址
    'thirdparty_id' => '', // 第三方平台服务商 id,非服务商模式留空
];

使用说明

单独使用

$pay = new \fengkui\Pay\Wechat($wechatConfig); // 微信
$pay = new \fengkui\Pay\Alipay($alipayConfig); // 支付宝
$pay = new \fengkui\Pay\Baidu($baiduConfig); // 百度
$pay = new \fengkui\Pay\Bytedance($bytedanceConfig); // 字节跳动

公共使用

<?php
/**
 * @Author: [FENG] <1161634940@qq.com>
 * @Date:   2021-06-01T14:55:21+08:00
 * @Last Modified by:   [FENG] <1161634940@qq.com>
 * @Last Modified time: 2021-06-15 15:39:01
 */
require_once('./vendor/autoload.php');

// 通用支付
class Payment
{
    // 支付类实例化
    protected static $pay = '';
    // 支付类型
    protected static $type = '';
    // 支付相关配置
    protected static $config = [];

    /**
     * [_initialize 构造函数(获取支付类型与初始化配置)]
     * @return [type] [description]
     */
    public function _initialize()
    {
        self::$type = $_GET['type'] ?? 'alipay';
        self::config();
    }

    /**
     * [config 获取配置]
     * @param  string $type [description]
     * @return [type]       [description]
     */
    protected static function config($type='')
    {
        $type = $type ?: self::$type;

        // 相关配置
        $alipayConfig = [];

        if (in_array($type, ['wechat', 'baidu', 'bytedance', 'alipay'])) {
            $config = $type . "Config";
            self::$config = $config;
        } else {
            die('当前类型配置不存在');
        }

        $type && self::$pay =(new \fengkui\Pay())::$type(self::$config);
    }

    // 支付方法
    public function pay()
    {
        $order = [
            'body'      => 'subject-测试', // 商品描述
            'order_sn'  => time(), // 商户订单号
            'total_amount' => 0.01, // 订单金额
        ];
        $result = self::$pay->web($order); // 直接跳转链接
        echo $result;
    }

}
Last Updated:
Contributors: kuifeng