2017 © Pedro Peláez
 

yii2-extension pingpp-yii2-plus

Simple Pingpp wrapper for Yii2

image

lyt8384/pingpp-yii2-plus

Simple Pingpp wrapper for Yii2

  • Wednesday, October 25, 2017
  • by lyt8384
  • Repository
  • 0 Watchers
  • 0 Stars
  • 12 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

pingpp-Yii2-plus

pingxx伪基于Yii2的封装, (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

最近主要又换Yii2开发了,其实不封装这个也是可以直接用官方那个的,只不过每次都要额外设置key什么的,搜了下,有别的大神写了一个很完善的版本,但是用起来感觉没在Laravel里那么爽,所以就把代码复制过来改了个名。这个版本的优点就是,官方SDK更新了。这边不用更新。 本人比较菜,没写单元测试,有比较在行的朋友帮补一个?, (*3)

配置方法

  1. composer.json里添加如下内容,并运行composer update:
{
    "require": {
        "lyt8384/pingpp-yii2-plus": "dev-master"
    }
}
  1. config/web.php文件里的components变量下添加配置
'pingpp' => [
    'class' => '\lyt8384\pingpp\Pingpp',
    'test_secret_key' => 'YOUR-TEST-KEY',
    'live_secret_key' => 'YOUR-LIVE-KEY',
    'live' => true, //测试时请设置为false
    'pub_key_path' => '/path/to/pingpp_rsa_public_key.pem', //该处不填不进行回调验证
    'private_key_path' => '/path/to/your_rsa_private_key.pem'   //该处不填不进行商家验证
],

使用方法

use Yii;

class SomeClass extends Controller {

    public function someFunction()
    {
        $pingpp = Yii::$app->pingpp;
        $pingpp->Charge->create([
            'order_no'  => '123456789',
            'amount'    => '100',
            'app'       => array('id' => 'app_xxxxxxxxxxxxxx'),
            'channel'   => 'upacp',
            'currency'  => 'cny',
            'client_ip' => '127.0.0.1',
            'subject'   => 'Your Subject',
            'body'      => 'Your Body'
        ]);
    }
}
use Yii;

class SomeClass extends Controller {

    public function someFunction()
    {
        $pingpp = Yii::$app->pingpp;
        $pingpp->RedEnvelope->create([
            'order_no'  => '123456789',
            'app'       => array('id' => '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调用发生错误的时候会return false,此时调用Yii::$app->pingpp->getError();返回具体错误内容。, (*4)

接收 Webhooks 通知

直接调用Yii::$app->pingpp->notice(),若验证成功,会返回通知的array结构数据,若失败直接弹出错Http误回Pingpp。并产生一条Warning级别的错误日志。, (*5)

IDE自动提示

可以按照 IDE autocompletion for custom components 设置,在Yii.php扩展的映射下面增加@property \lyt8384\pingpp\Pingpp $pingpp Simple Pingpp wrapper for Yii2, (*6)

其他使用方法见官方文档PingPlusPlus, (*7)

The Versions

25/10 2017

dev-master

9999999-dev

Simple Pingpp wrapper for Yii2

  Sources   Download

MIT

The Requires

 

by Avatar lyt8384

yii2 pingpp pingxx