PHPackages                             join/php-payment - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Payment Processing](/categories/payments)
4. /
5. join/php-payment

ActiveLibrary[Payment Processing](/categories/payments)

join/php-payment
================

php

v0.2.7(4y ago)2116MITPHPPHP &gt;=7.2.0

Since Dec 15Pushed 4y ago1 watchersCompare

[ Source](https://github.com/SantiagoFan/php-payment)[ Packagist](https://packagist.org/packages/join/php-payment)[ RSS](/packages/join-php-payment/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (4)Versions (9)Used By (0)

PHP-JOIN-PAYMENT php 支付工程
=========================

[](#php-join-payment-php-支付工程)

github (最新代码)
gitee (定期同步) [https://gitee.com/san\_fan/php-paymentgit](https://gitee.com/san_fan/php-paymentgit)

### 整体框架

[](#整体框架)

[![avatar](doc/%E6%94%AF%E4%BB%98%E4%B8%AD%E9%97%B4%E4%BB%B6%EF%BC%88draw%E5%8F%AF%E7%BC%96%E8%BE%91%EF%BC%89.svg)](doc/%E6%94%AF%E4%BB%98%E4%B8%AD%E9%97%B4%E4%BB%B6%EF%BC%88draw%E5%8F%AF%E7%BC%96%E8%BE%91%EF%BC%89.svg)

### composer 安装

[](#composer-安装)

需要 composer 版本2+

```
composer require join/php-payment

```

包地址

### require 依赖

[](#require-依赖)

php：&gt;=7.2.0

代码结构
----

[](#代码结构)

### 如何参与开发成为代码贡献人员

[](#如何参与开发成为代码贡献人员)

1. 将项目fork到自己帐号
2. 修改代码完成测试
3. 提交commit push 到自己的仓库
4. New pull request(简称pr) 合并请求到主库等待合并

使用教程
====

[](#使用教程)

### 1.安装包 composer 包

[](#1安装包-composer-包)

```
composer require join/php-payment

```

### 2.创建数据表

[](#2创建数据表)

复制源码文件夹的sql 脚本创建 交易流水表（此表作为所有支付进出的流水信息记录），具体业务订单信息请自己单独创建，参照下面的myorder

```
vendor/join/php-payment/doc/model.sql

```

字段数据类型可空含义idvarchar(64)not null支付记录表titlevarchar(128)null支付项目名称 如：商品-橘子5斤is\_refundtinyint(1)null是否为退款state intdefault 0null支付完成状态 -1撤销 0 默认 1 交易中 2支付完成business\_namevarchar(50)null业务类别：1.商品支付business\_novarchar(128)null内部业务 关联订单号码pay\_channelvarchar(50)null支付渠道：alipay,wxpaypay\_channel\_novarchar(128)null支付渠道 返回的外部订单号amountdecimal(10,2)null操作金额 支付为正 退款为负real\_amountdecimal(10,2)nullapply\_timedatetimenull下单时间complete\_timedatetimenull交易完成时间original\_amountdecimal(10,2)null原订单交易金额original\_idvarchar(64)null原始交易订单### 3.编写配置类（实现 IPaymentConfig 接口）

[](#3编写配置类实现-ipaymentconfig-接口)

- getPayConfig 是获取微信支付宝支付通道所需参数的方法
- getBusinessMap 是通过业务名称获取 业务类（具体指业务系统里需要有支付需求的订单如，商户购买订单、充值订单等）
- getPayChannel 是前端业务场景对应支付通道的配置

```
class PaymentConfig implements IPaymentConfig{
    // 注入配置
    public static function init(){
        $config  = new self();
        PayFactory::init($config);
    }
    /**
    * 注入配置信息
    * @param string $type
    * @return mixed
    */
    public function getPayConfig(string $type){
        // 方式一：代码里直接编写参数
//        $config = [
//           "wxpay"=>[],
//           "alipay"=>[]
//        ];
        // 方式二：单独配置文件  config/payment.php
        $config = Config::get('payment.');
        return $config[$type];
    }
    /**
     * 获取业务类映射关系
     * @return array|mixed
     */
    public function getBusinessMap(){
        // 具体请映射业务类
        return [
            "recharge_order"=>Model_MemberBalance::class,
        ];
    }
    /**
    * 配置客户端 对应支付通道
    * @param string $client
    * @return string
    */
    public function getPayChannel(string $client): string
    {
        // 客戶端支付方式映射支付渠道
        $channel=[
            PayClient::WEIXIN_MP => PayChannel::WEIXIN_PAY_JS,
            PayClient::WEIXIN_QRCODE => PayChannel::WEIXIN_PAY_NATIVE,
            PayClient::ALI_MP => PayChannel::ALI_PAY_JS,
            PayClient::ALI_PAY_QRCODE => PayChannel::ALI_PAY_NATIVE,
        ];
        return $channel[$client];
    }
}
```

配置示例 config/payment.php

```
