Convert Figma logo to code with AI

yansongda logopay

可能是我用过的最优雅的 Alipay/WeChat/Douyin/Unipay/江苏银行 的支付 SDK 扩展包了

5,011
1,029
5,011
15

Top Related Projects

📦 一个 PHP 微信 SDK

可能是我用过的最优雅的 Alipay/WeChat/Unipay 的 laravel 支付扩展包了

微信 SDK for Laravel, 基于 overtrue/wechat

Quick Overview

The yansongda/pay project is a PHP package that provides a unified API for various payment gateways, including Alipay, WeChat Pay, and UnionPay. It aims to simplify the integration of payment processing into PHP applications, offering a consistent and easy-to-use interface across different payment providers.

Pros

  • Unified API: The package provides a consistent API for interacting with different payment gateways, reducing the complexity of integrating multiple payment methods.
  • Extensive Documentation: The project has detailed documentation, including examples and usage guides, making it easier for developers to get started and understand the library's features.
  • Active Development: The project is actively maintained, with regular updates and bug fixes, ensuring compatibility with the latest payment gateway requirements.
  • Community Support: The project has a growing community of contributors and users, providing a valuable resource for troubleshooting and feature requests.

Cons

  • Limited Payment Gateways: While the package supports several popular payment gateways, it may not cover all the payment methods required by some applications.
  • Dependency on External Libraries: The package relies on external libraries, such as guzzlehttp/guzzle and symfony/http-foundation, which may introduce additional complexity and potential compatibility issues.
  • Potential Learning Curve: Developers unfamiliar with the package may need to invest time in understanding its structure and usage, especially if they need to integrate with multiple payment gateways.
  • Potential Vendor Lock-in: By using this package, developers may become more dependent on the project's maintainers, which could lead to vendor lock-in concerns.

Code Examples

Here are a few code examples demonstrating the usage of the yansongda/pay package:

Alipay Payment

use Yansongda\Pay\Pay;

$order = [
    'out_trade_no' => time(),
    'total_amount' => '1.00',
    'subject'      => 'test subject - 测试',
];

$result = Pay::alipay()->web($order)->send();

// 将结果返回给前端
return $result->getContent();

This code demonstrates how to create an Alipay payment order and generate the payment page HTML.

WeChat Pay Payment

use Yansongda\Pay\Pay;

$order = [
    'out_trade_no' => time(),
    'body'         => 'test body - 测试',
    'total_fee'    => '1',
    'openid'       => 'openid',
];

$result = Pay::wechat()->mp($order)->send();

// 将结果返回给前端
return $result->getContent();

This code shows how to create a WeChat Pay payment order and generate the payment page HTML for a WeChat Mini Program.

Refund

use Yansongda\Pay\Pay;

$refund = [
    'out_trade_no'   => '1514027114',
    'refund_amount'  => '1',
    'out_refund_no'  => time(),
];

$result = Pay::alipay()->refund($refund)->send();

// 处理结果
var_dump($result->toArray());

This code demonstrates how to initiate a refund for an Alipay payment.

Getting Started

To get started with the yansongda/pay package, follow these steps:

  1. Install the package using Composer:
composer require yansongda/pay
  1. Configure the payment gateway settings in your application:
use Yansongda\Pay\Pay;

// Alipay configuration
$config = [
    'app_id'         => 'your-alipay-app-id',
    'ali_public_key' => 'path/to/your/alipay/public/key',
    'private_key'    => 'path/to/your/private/key',
    'log'            => [
        'file'     => './logs/alipay.log',
        'level'    => 'debug',
        'type'     => 'single', // optional

Competitor Comparisons

📦 一个 PHP 微信 SDK

Pros of EasyWechat

  • EasyWechat provides a more comprehensive set of features for WeChat integration, including support for official accounts, mini-programs, and payment gateways.
  • The library is actively maintained and has a larger community of contributors, ensuring regular updates and bug fixes.
  • EasyWechat has better documentation and more detailed examples, making it easier for developers to get started with WeChat integration.

Cons of EasyWechat

  • Pay is a more lightweight and focused library, which may be preferred by developers who only need basic payment functionality.
  • EasyWechat has a larger codebase and may have a steeper learning curve for developers who are new to WeChat integration.
  • The licensing and intellectual property considerations may be more complex with EasyWechat, as it is a commercial product.

Code Comparison

Pay:

$pay = Pay::wechat([
    'app_id' => 'your-wechat-app-id',
    'mch_id' => 'your-wechat-mch-id',
    'key' => 'your-wechat-key',
    'cert_path' => 'path/to/your/cert.pem',
    'key_path' => 'path/to/your/key.pem',
]);

$order = $pay->order->unify([
    'out_trade_no' => time(),
    'total_fee' => 1,
    'body' => 'test body',
    'openid' => 'openid',
]);

EasyWechat:

$app = Factory::payment([
    'app_id' => 'your-wechat-app-id',
    'mch_id' => 'your-wechat-mch-id',
    'key' => 'your-wechat-key',
    'cert_path' => 'path/to/your/cert.pem',
    'key_path' => 'path/to/your/key.pem',
]);

$result = $app->order->unify([
    'body' => 'Your cart order',
    'out_trade_no' => time(),
    'total_fee' => 1,
    'trade_type' => 'JSAPI',
    'openid' => 'openid',
]);

可能是我用过的最优雅的 Alipay/WeChat/Unipay 的 laravel 支付扩展包了

Pros of yansongda/laravel-pay

  • Easier Integration: yansongda/laravel-pay provides a Laravel-specific integration, making it more straightforward to use within a Laravel application.
  • Automatic Configuration: The package handles the configuration and setup process, reducing the amount of boilerplate code required.
  • Consistent API: The package follows the Laravel conventions, providing a familiar and consistent API for developers.

Cons of yansongda/laravel-pay

  • Limited to Laravel: yansongda/laravel-pay is specifically designed for Laravel applications, limiting its use in non-Laravel projects.
  • Dependency on Laravel: The package is tightly coupled with the Laravel framework, which may be a drawback for developers who prefer a more framework-agnostic solution.
  • Potentially Slower Updates: The updates and maintenance of yansongda/laravel-pay may be slower compared to the more general yansongda/pay package.

Code Comparison

yansongda/pay:

$config = [
    'alipay' => [
        'app_id' => 'your-alipay-app-id',
        'secret' => 'your-alipay-secret',
        // ...
    ],
    'wechat' => [
        'app_id' => 'your-wechat-app-id',
        'mch_id' => 'your-wechat-mch-id',
        // ...
    ],
];

$pay = Pay::alipay($config['alipay'])->web([
    'out_trade_no' => time(),
    'total_amount' => 1,
    'subject'      => 'test subject',
]);

yansongda/laravel-pay:

$pay = Pay::alipay()->web([
    'out_trade_no' => time(),
    'total_amount' => 1,
    'subject'      => 'test subject',
]);

微信 SDK for Laravel, 基于 overtrue/wechat

Pros of Laravel-WeChat

  • Provides a comprehensive set of APIs for interacting with WeChat's various services, including official accounts, mini-programs, payment, and more.
  • Integrates seamlessly with the Laravel framework, allowing developers to leverage the framework's features and conventions.
  • Offers a modular design, allowing developers to use only the components they need, reducing the overall project footprint.

Cons of Laravel-WeChat

  • Primarily focused on WeChat integration, which may not be suitable for developers who need to work with other payment gateways or service providers.
  • Requires a deeper understanding of the Laravel framework, which may be a barrier for developers who are not familiar with it.
  • May have a steeper learning curve compared to a more generic payment library like yansongda/pay.

Code Comparison

yansongda/pay:

$pay = Pay::alipay([
    'app_id' => 'your-alipay-app-id',
    'notify_url' => 'http://example.com/alipay-notify',
    'return_url' => 'http://example.com/alipay-return',
    'ali_public_key' => 'path/to/alipay/public/key',
    'private_key' => 'path/to/private/key',
    'log' => [
        'file' => './logs/alipay.log',
        'level' => 'debug',
        'type' => 'single',
    ],
]);

$result = $pay->web([
    'out_trade_no' => time(),
    'total_amount' => 1,
    'subject' => 'test subject - 测试',
]);

Laravel-WeChat:

$app = app('wechat.official_account');
$app->server->push(function($message) {
    switch ($message['MsgType']) {
        case 'text':
            return "Hello, I'm WeChat!";
        case 'image':
            return [
                'type' => 'image',
                'media_id' => 'media_id',
            ];
    }
    return '';
});

$app->server->serve()->send();

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Logo

scrutinizer Tester Status Code Coverage Status Coding Style Status Stable Version Total Downloads License

前言

v3 版与 v2 版在底层有很大的不同,基础架构做了重新的设计,更易扩展,使用起来更方便。

开发了多次支付宝与微信支付后,很自然产生一种反感,惰性又来了,想在网上找相关的轮子,可是一直没有找到一款自己觉得逞心如意的,要么使用起来太难理解,要么文件结构太杂乱,只有自己撸起袖子干了。

欢迎 Star,欢迎 PR!

hyperf 扩展包请 传送至这里

laravel 扩展包请 传送至这里

yii 扩展包请 传送至这里

特点

  • 多租户支持
  • Swoole 支持
  • 灵活的插件机制
  • 丰富的事件系统
  • 命名不那么乱七八糟
  • 隐藏开发者不需要关注的细节
  • 根据支付宝、微信最新 API 开发而成
  • 高度抽象的类,免去各种拼json与xml的痛苦
  • 文件结构清晰易理解,可以随心所欲添加本项目中没有的支付网关
  • 方法使用更优雅,不必再去研究那些奇怪的的方法名或者类名是做啥用的
  • 内置自动获取微信公共证书方法,再也不用再费劲去考虑第一次获取证书的的问题了
  • 符合 PSR2、PSR3、PSR4、PSR7、PSR11、PSR14、PSR18 等各项标准,你可以各种方便的与你的框架集成

版本计划

https://pay.yansongda.cn/docs/v3/overview/planning

详细文档

https://pay.yansongda.cn

支持的支付方法

yansongda/pay 100% 兼容 支付宝/微信/银联 所有功能(包括服务商功能),只需通过「插件机制」引入即可。

同时,SDK 直接支持内置了以下插件,详情请查阅文档。

支付宝

  • 电脑支付
  • 手机网站支付
  • APP 支付
  • 刷卡支付
  • 扫码支付
  • 账户转账
  • 小程序支付
  • ...

微信

  • 公众号支付
  • 小程序支付
  • H5 支付
  • 扫码支付
  • APP 支付
  • 刷卡支付
  • ...

抖音

  • 小程序支付
  • ...

银联

  • 手机网站支付
  • 电脑网站支付
  • 刷卡支付
  • 扫码支付
  • ...

江苏银行(e融支付)

  • 聚合扫码支付(微信,支付宝,银联,e融)
  • ...

安装

composer require yansongda/pay:~3.7.0 -vvv

深情一撇

支付宝

<?php

namespace App\Http\Controllers;

use Yansongda\Pay\Pay;

class AlipayController
{
    protected $config = [
        'alipay' => [
            'default' => [
                // 必填-支付宝分配的 app_id
                'app_id' => '2016082000295641',
                // 必填-应用私钥 字符串或路径
                'app_secret_cert' => '89iZ2iC16H6/6a3YcP+hDZUjiNGQx9cuwi9eJyykvcwhD...',
                // 必填-应用公钥证书 路径
                'app_public_cert_path' => '/Users/yansongda/pay/cert/appCertPublicKey_2016082000295641.crt',
                // 必填-支付宝公钥证书 路径
                'alipay_public_cert_path' => '/Users/yansongda/pay/cert/alipayCertPublicKey_RSA2.crt',
                // 必填-支付宝根证书 路径
                'alipay_root_cert_path' => '/Users/yansongda/pay/cert/alipayRootCert.crt',
                'return_url' => 'https://yansongda.cn/alipay/return',
                'notify_url' => 'https://yansongda.cn/alipay/notify',
                // 选填-第三方应用授权token
                'app_auth_token' => '',
                // 选填-服务商模式下的服务商 id,当 mode 为 Pay::MODE_SERVICE 时使用该参数
                'service_provider_id' => '',
                // 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE
                'mode' => Pay::MODE_NORMAL,
            ],       
        ],   
        'logger' => [ // optional
            'enable' => false,
            'file' => './logs/alipay.log',
            'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
            'type' => 'single', // optional, 可选 daily.
            'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
        ],
        'http' => [ // optional
            'timeout' => 5.0,
            'connect_timeout' => 5.0,
            // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ],
    ];

    public function web()
    {
        Pay::config($this->config);
        
        $result = Pay::alipay()->web([
            'out_trade_no' => ''.time(),
            'total_amount' => '0.01',
            'subject' => 'yansongda 测试 - 1',
        ]);
        
        return $result;
    }

    public function returnCallback()
    {
        Pay::config($this->config);
    
        $data = Pay::alipay()->callback(); // 是的,验签就这么简单!

        // 订单号:$data->out_trade_no
        // 支付宝交易号:$data->trade_no
        // 订单总金额:$data->total_amount
    }

    public function notifyCallback()
    {
        Pay::config($this->config);
        
        try{
            $data = Pay::alipay()->callback(); // 是的,验签就这么简单!

            // 请自行对 trade_status 进行判断及其它逻辑进行判断,在支付宝的业务通知中,只有交易通知状态为 TRADE_SUCCESS 或 TRADE_FINISHED 时,支付宝才会认定为买家付款成功。
            // 1、商户需要验证该通知数据中的out_trade_no是否为商户系统中创建的订单号;
            // 2、判断total_amount是否确实为该订单的实际金额(即商户订单创建时的金额);
            // 3、校验通知中的seller_id(或者seller_email) 是否为out_trade_no这笔单据的对应的操作方(有的时候,一个商户可能有多个seller_id/seller_email);
            // 4、验证app_id是否为该商户本身。
            // 5、其它业务逻辑情况
        } catch (\Throwable $e) {
            dd($e);
        }

        return Pay::alipay()->success();
    }
}

微信

<?php

namespace App\Http\Controllers;

use Yansongda\Pay\Pay;

class WechatController
{
    protected $config = [
        'wechat' => [
            'default' => [
                // 必填-商户号
                'mch_id' => '',
                // 选填-v2商户私钥
                'mch_secret_key_v2' => '',
                // 必填-v3商户秘钥
                'mch_secret_key' => '',
                // 必填-商户私钥 字符串或路径
                'mch_secret_cert' => '',
                // 必填-商户公钥证书路径
                'mch_public_cert_path' => '',
                // 必填
                'notify_url' => 'https://yansongda.cn/wechat/notify',
                // 选填-公众号 的 app_id
                'mp_app_id' => '',
                // 选填-小程序 的 app_id
                'mini_app_id' => '',
                // 选填-app 的 app_id
                'app_id' => '',
                // 选填-服务商模式下,子公众号 的 app_id
                'sub_mp_app_id' => '',
                // 选填-服务商模式下,子 app 的 app_id
                'sub_app_id' => '',
                // 选填-服务商模式下,子小程序 的 app_id
                'sub_mini_app_id' => '',
                // 选填-服务商模式下,子商户id
                'sub_mch_id' => '',
                // 选填-微信平台公钥证书路径, optional,强烈建议 php-fpm 模式下配置此参数
                'wechat_public_cert_path' => [
                    '45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__.'/Cert/wechatpay_45F***D57.pem',
                ],
                // 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SERVICE
                'mode' => Pay::MODE_NORMAL,
            ]
        ],
        'logger' => [ // optional
            'enable' => false,
            'file' => './logs/wechat.log',
            'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
            'type' => 'single', // optional, 可选 daily.
            'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
        ],
        'http' => [ // optional
            'timeout' => 5.0,
            'connect_timeout' => 5.0,
            // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ],
    ];

    public function index()
    {
        Pay::config($this->config);
        
        $order = [
            'out_trade_no' => time().'',
            'description' => 'subject-测试',
            'amount' => [
                 'total' => 1,
            ],
            'payer' => [
                 'openid' => 'onkVf1FjWS5SBxxxxxxxx',
            ],
        ];

        $pay = Pay::wechat()->mp($order);

        // $pay->appId
        // $pay->timeStamp
        // $pay->nonceStr
        // $pay->package
        // $pay->signType
    }

    public function callback()
    {
        Pay::config($this->config);
        
        try{
            $data = Pay::wechat()->callback(); // 是的,验签就这么简单!
        } catch (\Throwable $e) {
            dd($e);
        }
        
        return Pay::wechat()->success();
    }
}

抖音

<?php

namespace App\Http\Controllers;

use Yansongda\Pay\Pay;

class DouyinController
{
    protected $config = [
        'douyin' => [
            'default' => [
                // 选填-商户号
                // 抖音开放平台 --> 应用详情 --> 支付信息 --> 产品管理 --> 商户号
                'mch_id' => '73744242495132490630',
                // 必填-支付 Token,用于支付回调签名
                // 抖音开放平台 --> 应用详情 --> 支付信息 --> 支付设置 --> Token(令牌)
                'mch_secret_token' => 'douyin_mini_token',
                // 必填-支付 SALT,用于支付签名
                // 抖音开放平台 --> 应用详情 --> 支付信息 --> 支付设置 --> SALT
                'mch_secret_salt' => 'oDxWDBr4U7FAAQ8hnGDm29i4A6pbTMDKme4WLLvA',
                // 必填-小程序 app_id
                // 抖音开放平台 --> 应用详情 --> 支付信息 --> 支付设置 --> 小程序appid
                'mini_app_id' => 'tt226e54d3bd581bf801',
                // 选填-抖音开放平台服务商id
                'thirdparty_id' => '',
                // 选填-抖音支付回调地址
                'notify_url' => 'https://yansongda.cn/douyin/notify',
            ],
        ],
        'logger' => [ // optional
            'enable' => false,
            'file' => './logs/alipay.log',
            'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
            'type' => 'single', // optional, 可选 daily.
            'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
        ],
        'http' => [ // optional
            'timeout' => 5.0,
            'connect_timeout' => 5.0,
            // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ],
    ];

    public function pay()
    {
        Pay::config($this->config);
        
        $result = Pay::douyin()->mini([
            'out_order_no' => date('YmdHis').mt_rand(1000, 9999),
            'total_amount' => 1,
            'subject' => '闫嵩达 - test - subject - 01',
            'body' => '闫嵩达 - test - body - 01',
            'valid_time' => 600,
            'expand_order_info' => json_encode([
                'original_delivery_fee' => 15,
                'actual_delivery_fee' => 10
            ])
        ]);
        
        return $result;
    }

    public function callback()
    {
        Pay::config($this->config);
    
        try{
            $data = Pay::douyin()->callback(); // 是的,验签就这么简单!
        } catch (\Throwable $e) {
            dd($e)
        }

        return Pay::douyin()->success();
    }
}

江苏银行(e融支付)

<?php

namespace App\Http\Controllers;

use Yansongda\Pay\Pay;

class JsbController
{
    protected $config = [
        'jsb' => [
            'default' => [
                // 服务代码
                'svr_code' => '',
                // 必填-合作商ID
                'partner_id' => '',
                // 必填-公私钥对编号
                'public_key_code' => '00',
                // 必填-商户私钥(加密签名)
                'mch_secret_cert_path' => '',
                // 必填-商户公钥证书路径(提供江苏银行进行验证签名用)
                'mch_public_cert_path' => '',
                // 必填-江苏银行的公钥(用于解密江苏银行返回的数据)
                'jsb_public_cert_path' => '',
                //支付通知地址
                'notify_url'            => '', 
                // 选填-默认为正常模式。可选为: MODE_NORMAL:正式环境, MODE_SANDBOX:测试环境
                'mode' => Pay::MODE_NORMAL,
            ]
        ],
        'logger' => [ // optional
            'enable' => false,
            'file' => './logs/epay.log',
            'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
            'type' => 'single', // optional, 可选 daily.
            'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
        ],
        'http' => [ // optional
            'timeout' => 5.0,
            'connect_timeout' => 5.0,
            // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ],
    ];

    public function index()
    {
        Pay::config($this->config);
        
        $order = [
            'outTradeNo' => time().'',
            'proInfo' => 'subject-测试',
            'totalFee'=> 1,
        ];

        $pay = Pay::jsb()->scan($order);
    }

    public function notifyCallback()
    {
        Pay::config($this->config);

        try{
            $data = Pay::jsb()->callback(); // 是的,验签就这么简单!
        } catch (\Throwable $e) {
            dd($e);
        }
        
        return Pay::jsb()->success();
    }
}

代码贡献

由于测试及使用环境的限制,本项目中只开发了「支付宝」、「微信支付」、「抖音支付」、「银联」、「江苏银行」的相关支付网关。

如果您有其它支付网关的需求,或者发现本项目中需要改进的代码,欢迎 Fork 并提交 PR!

赏一杯咖啡吧

pay

LICENSE

MIT

NPM DownloadsLast 30 Days