Giter Site home page Giter Site logo

swonzhang / thirdpay Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 7.0 48 KB

该PHP包封装了支付宝app支付,扫码支付,wap支付,即时到账支付以及微信app支付,微信扫码支付。该PHP包的目的是让接入支付宝和微信支付的开发工作变得更加简单优雅。

License: MIT License

PHP 100.00%

thirdpay's Introduction

ThirdPay

Latest Stable Version Total Downloads Latest Unstable Version License

该PHP包封装了支付宝app支付,扫码支付,wap支付,即时到账支付以及微信app支付,微信扫码支付。 它提供了统一而简洁的调用接口,主要目的是让接入支付宝和微信支付的开发工作变得更加简单优雅。 目前只提供支付退款功能。

该PHP包的作者是 郭觉能.

安装

  • 第一种方式 直接下载程序包,然后在项目中包含autoload.php
    include_once '包的根目录/src/autoload.php';
  • 第二种方式 用composer安装,在composer.json中指定安装jaydenguo/thirdpay
    "require": {
        "jaydenguo/thirdpay": "1.0.*"
    }

配置

每一种支付方式的配置项都是一个数组。example/config文件夹中列出了各个支付方式的配置项,配置项的键名不能随意修改, 你可以根据你的情况以最合适的方式引入这些配置项。 例如假设你使用thinkphp框架开发,这些支付配置项就可以放在thinkphp 的配置文件中,再通过C方法引入。

支付接入最大的难点之一是准确理解并填写这些配置项,否则很容易遇到签名等问题。

示例

这个程序包提供了各个方式的支付和退款示例,你可以填写好配置项后,搭建好本地环境运行看看。

用法

###实例化支付对象

$pay = \Jueneng\Pay::getInstance('alipay.direct');
$pay->setConfig($config);

getInstance方法传入参数alipay.direct表示实例化的是支付宝即使到账支付对象。所有的标识如下:

支付宝即时到帐支付: alipay.direct(对应支付宝旧版接口)
支付宝app支付: alipay.app(对应支付宝新版接口)
支付宝扫码支付: alipay.qr(对应支付宝新版接口)
支付宝wap支付: alipay.wap(对应支付宝新版接口)
微信扫码支付: weixinpay.qr
微信app支付: weixinpay.app
###发起支付

$result = $pay->createOrder($params);

$params是从外部传入的参数数组,具体请求参数请参考对应的官方文档。

请勿传入在请求之前就已经确定的参数,比如charset,app_id,sign_type等, 因为这个包里面已经预先设置好了这些参数,你也可以参照示例来传,以及查看 对应的参数请求类,比如支付的参数请求类是CreateOrderRequestParam。

返回的$result可能是字符串也可能是一个数组,以实际返回数据为准。
如果是一个数组,则包含3个字段message,success,data, message是返回消息,success是发起支付是否成功,true是成功,false是失败, data是原始返回数据。

###发起退款

$result = $pay->refund($params);

$params是从外部传入的参数数组,具体请求参数请看对应的官方文档。
返回的$result是一个数组,包含3个字段message,success,data, message是返回消息,success是发起支付是否成功,true是成功,false是失败, data是原始返回数据

###验证回跳或异步通知参数

$params = \Jueneng\AliPay\Helper::getNotifyRequestParams();
$result = $pay->verifyReturn($params);

$result是bool类型,true是验证成功,false是验证失败。异步通知回调验证等于true时, 需要给第三方支付返回指定字符串,调用如下方法返回:

return $pay->responseNotifySuccess();

##其他 以下是官方文档链接:

支付宝有两个版本接口,一个新版的,一个旧版的,一定要认清文档的版本

##最后 如你发现该程序包的任何bug,请用邮件联系我[email protected],我将会以最快速度修复。

thirdpay's People

Stargazers

 avatar

Watchers

James Cloos avatar swonzhang avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.