Giter VIP home page Giter VIP logo

pingpp-php's Introduction

Pingpp PHP SDK

简介

lib 文件夹下是 PHP SDK 文件,
example 文件夹里面是简单的接入示例,该示例仅供参考。

版本要求

PHP 版本 5.3 及以上

安装

使用 Composer

composer.json 中添加以下代码

{
  "require": {
    "pingplusplus/pingpp-php": "dev-master"
  }
}

然后执行

composer install

使用 Composer 的 autoload 引入

require_once('vendor/autoload.php');

手动引入

require_once('/path/to/pingpp-php/init.php');

接入方法

初始化

\Pingpp\Pingpp::setApiKey('YOUR-KEY');

支付

$ch = \Pingpp\Charge::create(
    array(
        'order_no'  => '123456789',
        'app'       => array('id' => 'YOUR-APP-ID'),
        'channel'   => 'alipay',
        'amount'    => 100,
        'client_ip' => '127.0.0.1',
        'currency'  => 'cny',
        'subject'   => 'Your Subject',
        'body'      => 'Your Body',
        'extra'     => $extra
    )
);

查询

\Pingpp\Charge::retrieve('CHARGE_ID');
\Pingpp\Charge::all(array('limit' => 5));

退款

$ch = \Pingpp\Charge::retrieve('CHARGE_ID');
$re = $ch->refunds->create(array('description' => 'Refund Description');

退款查询

$ch = \Pingpp\Charge::retrieve('CHARGE_ID');
$ch->refunds->retrieve('REFUND_ID');
$ch = \Pingpp\Charge::retrieve('CHARGE_ID');
$ch->refunds->all(array('limit' => 5));

微信红包

\Pingpp\RedEnvelope::create(
    array(
        'order_no'  => '123456789',
        'app'       => array('id' => 'YOUR-APP-ID'),
        'channel'   => 'wx_pub',
        'amount'    => 100,
        'currency'  => 'cny',
        'subject'   => 'Your Subject',
        'body'      => 'Your Body',
        'extra'     => array(
            'nick_name' => 'Nick Name',
            'send_name' => 'Send Name'
        ),
        'recipient'   => 'Openid',
        'description' => 'Your Description'
    )
);

查询

\Pingpp\RedEnvelope::retrieve('RED_ID');
\Pingpp\RedEnvelope::all(array('limit' => 5));

微信公众号获取签名

如果使用微信 JS-SDK 来调起支付,需要在创建 charge 后,获取签名(signature),传给 HTML5 SDK。

$jsapi_ticket_arr = \Pingpp\WxpubOAuth::getJsapiTicket($wx_app_id, $wx_app_secret);
$ticket = $jsapi_ticket_arr['ticket'];

正常情况下,jsapi_ticket 的有效期为 7200 秒。由于获取 jsapi_ticket 的 api 调用次数非常有限,频繁刷新 jsapi_ticket 会导致 api 调用受限,影响自身业务,开发者必须在自己的服务器全局缓存 jsapi_ticket

下面方法中 $url 是当前网页的 URL,不包含 # 及其后面部分

$signature = \Pingpp\WxpubOauth::getSignature($charge, $ticket, $url);

然后在 HTML5 SDK 里调用

pingpp.createPayment(charge, callback, signature, false);

详细信息请参考 API 文档

pingpp-php's People

Contributors

samurai00 avatar bix29 avatar sparanoid avatar

Watchers

James Cloos avatar  avatar  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.