PHP code example of pingplusplus / pingpp-php

1. Go to this page and download the library: Download pingplusplus/pingpp-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pingplusplus / pingpp-php example snippets






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

\Pingpp\Pingpp::setPrivateKeyPath('/path/to/your_rsa_private_key.pem');

\Pingpp\Pingpp::$caBundle = '/path/to/cacert.pem';

$ch = \Pingpp\Charge::create([
    'order_no'  => '123456789',
    'app'       => ['id' => '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(['limit' => 5, 'app' => ['id' => 'APP_ID']]);

$re = \Pingpp\Refund::create('ch_a9CmfHTGGaz1urHiL8m5OiX1', [
    'amount' => 1,
    'description' => 'Your Descripton',
]);

\Pingpp\Refund::retrieve('CHARGE_ID', 'REFUND_ID');

\Pingpp\Refund::all('CHARGE_ID',[
    'limit' => 5,
]);

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

\Pingpp\RedEnvelope::retrieve('RED_ID');

\Pingpp\RedEnvelope::all(['limit' => 5]);

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

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

\Pingpp\Event::retrieve('EVT_ID');

\Pingpp\Event::all(['type' => 'charge.succeeded']);

\Pingpp\Transfer::create([
    'amount' => 100,
    'order_no' => '123456d7890',
    'currency' => 'cny',
    'channel' => 'wx_pub',
    'app' => ['id' => 'APP_ID'],
    'type' => 'b2c',
    'recipient' => 'o9zpMs9jIaLynQY9N6yxcZ',
    'description' => 'testing',
    'extra' => ['user_name' => 'User Name', 'force_check' => true]
]);

\Pingpp\Transfer::retrieve('TR_ID');

\Pingpp\Transfer::all(['limit' => 5]);

\Pingpp\Identification::identify([
    'type' => 'id_card',
    'app' => $app_id,
    'data' => [
        'id_name' => '张三', // 姓名
        'id_number' => '310181198910107641' // 身份证号
    ]
]);

\Pingpp\Identification::identify([
    'type' => 'bank_card',
    'app' => $app_id,
    'data' => [
        'id_name' => '张三', // 姓名
        'id_number' => '310181198910107641', // 身份证号,
        'card_number' => '6201111122223333', // 银行卡号
        'phone_number' => '18623234545' // 银行预留手机号,不支持 178 号段
    ]
]);

\Pingpp\BatchTransfer::create(
    [
        'amount'      => 8000,
        'app'         => APP_ID,
        'batch_no'    => uniqid('batch'),    // 批量退款批次号,3-24位,允许字母和英文
        'channel'     => 'alipay',
        'description' => 'Your Description', // 批量退款详情,最多 255 个 Unicode 字符
        'recipients'  => [ // 需要退款的  charge id 列表,一次最多 100 个
            [
                'account' => '[email protected]',
                'amount'  => 5000,
                'name'    => '张三'
            ],
            [
                'account' => '[email protected]',
                'amount'  => 3000,
                'name'    => '李四'
            ]
        ],
        'type'      => 'b2c'
    ]
);

\Pingpp\BatchTransfer::retrieve('181611151506412852'); // 批量转账对象id ,由 Ping++ 生成

\Pingpp\BatchTransfer::all(['page' => 1]);

\Pingpp\BatchRefund::create(
    [
        'app'         => APP_ID,
        'batch_no'    => uniqid('batch'),    // 批量退款批次号,3-24位,允许字母和英文
        'description' => 'Your Description', // 批量退款详情,最多 255 个 Unicode 字符
        'charges'     => [ // 需要退款的  charge id 列表,一次最多 100 个
            'ch_qn5G8GH1SOCCvnv10S8mXTqP',
            'ch_SijjXL8Ki1u1arL1S49q5ifL'
        ]
    ]
);

\Pingpp\BatchRefund::retrieve('151611141520583238'); // 批量退款对象id ,由 Ping++ 生成

\Pingpp\BatchRefund::all(['page' => 1]);

\Pingpp\Customs::create(
    [
        'app'               => APP_ID,
        'charge'            => 'ch_L8qn10mLmr1GS8e5OODmHaL4',
        'channel'           => 'alipay',
        'trade_no'          => '12332132131',         // 商户报关订单号,8~20位
        'customs_code'      => 'GUANGZHOU',
        'amount'            => 8000,
        'transport_amount'  => 10,
        'is_split'          => true,
        'sub_order_no'      => '123456',
        'extra'  => [
            'pay_account'   => '1234567890',
            'certif_type'   => '02',
            'customer_name' => 'A Name',
            'certif_id'     => 'ID Card No',
            'tax_amount'    => '10',
        ]
    ]
);

\Pingpp\Customs::retrieve('14201609281040220109'); // 报关对象 ID,由 Ping++ 生成

\Pingpp\Order::create([
    "amount" => 100,
    "app" => APP_ID,
    "merchant_order_no" => "88888888888", //商户订单号
    "subject" => "subj{$order_no}",
    "currency" => "cny",
    "body" => "body{$order_no}",
    "uid" => "test_user_001",
    "client_ip" => "192.168.0.101",
]);

\Pingpp\Order::pay('2011611170000003651', [
    'balance_amount'    => 0,
    'charge_amount'     => 10,
    'channel' => 'alipay',
    'extra' => [
        'key' => 'value',
    ],
]);

\Pingpp\Order::cancel('2011611170000003651'); // 订单对象 ID,由 Ping++ 生成

\Pingpp\Order::retrieve('2011611170000003651'); // 订单对象 ID,由 Ping++ 生成

$params = ['app' => APP_ID];
\Pingpp\Order::all($params);

\Pingpp\OrderRefund::create('2011708070000007521', [
    'description' => 'Your description', //退款附加说明。
    'metadata' => [],
    'refund_mode' => 'to_source',        //退款模式。原路退回:to_source,退至余额:to_balance。默认为原路返回。
]);

\Pingpp\OrderRefund::retrieve('2011611160000343961', 're_OW1CSS8KCS0KvfzDu5jTerrH');

\Pingpp\OrderRefund::all('2011611160000343961');

\Pingpp\Recharge::create([
    'user' => 'user_test_01',
    'charge' => [
        'amount' => 100,
        'channel' => 'alipay_qr',
        'order_no' => substr(md5(time()), 0, 10),
        'subject' => 'Your subject',
        'body' => 'Your recharge body',
        'time_expire' => time()+ 3600,
        'client_ip' => '127.0.0.1',
        'extra' => [],
    ],
    'balance_bonus' => [
        'amount' => 10,
    ],
    'from_user' => 'user_test_01',
    'description' => 'Your description',
    'metadata' => [],
]);

\Pingpp\Recharge::retrieve('221170807730968330240000')

$params = [
    'page' => 1,
    'per_page' => 100,
];
\Pingpp\Recharge::all($params);

\Pingpp\Recharge::refund('221170807730968330240000', [
    'description' => 'Rechage refund description',
]);

\Pingpp\Recharge::refund_retrieve('221170807730968330240000', 're_iTqLaTe1WTmHvXjrv9i5C8G4')

\Pingpp\Recharge::refundList('221170807730968330240000')

 \Pingpp\User::create([
    'id' => uniqid('uid'), // 用户 ID ,由商户提供
 ]);

\Pingpp\User::retrieve('uid582d35283f628');

\Pingpp\User::update($uid, [
    'address' => 'Shanghai',
    'name' => 'User Name',
    'metadata' => [
        'key' => 'value'
    ],
]);

$users = \Pingpp\User::all([
    'page' => 1,
    'per_page' => 10,
]);

\Pingpp\CouponTemplate::create([
    'name'             => '25OFF', // 优惠券模板名称
    'type'             => 2,       // 优惠券模板的类型 1:现金券;2:折扣券
    'percent_off'      => 25,      // 折扣百分比, 如 20 表示 8 折, 100 表示免费
    'amount_available' => 10000,   // 订单金额大于等于该值时,优惠券有效(适用于满减);0 表示无限制
    'max_circulation'  => 1000,    // 优惠券最大生成数量,当已生成数量达到最大值时,不能再生成优惠券;默认 null,表示可以无限生成
    'metadata'         => [],      // metadata
    'expiration'       => null,    // 优惠券模板过期策略
]);

\Pingpp\CouponTemplate::all([
    'page' => 1,
    'per_page' => 10,
]);

\Pingpp\CouponTemplate::retrieve('300116082415452100000700');

$ct = \Pingpp\CouponTemplate::update('300116082415452100000700', [
    'metadata' => [
        'keys' => 'value',
    ]
]);

\Pingpp\CouponTemplate::delete('300116082415452100000700');

$coupon_tmpl_id = '300216111711085500022401'; // Ping++ 返回的优惠券模板 ID
$params = [
    'users' => [
        'uid582d1756b1650',
        'uid582d1756b1651',
    ],
];
\Pingpp\CouponTemplate::batchCreateCoupons($coupon_tmpl_id, $params);

\Pingpp\CouponTemplate::couponsList('300216111711085500022401'); //  Ping++ 返回的优惠券模板 ID

$user_id = 'uid582d1756b1650'; // 用户 ID
$params = [
    'coupon_template' => '300216111619300600019101', // 优惠券模版 ID
];
\Pingpp\Coupon::create($user_id, $params);

$user_id = 'uid582d1756b1650'; // 用户 ID
$coupon_id = '300416111711463500023901'; // 优惠券 ID
\Pingpp\Coupon::retrieve($user_id, $coupon_id);

// 更新 Coupon 对象
$user_id = 'uid582d1756b1650'; // 用户 ID
$coupon_id = '300416111711571500024101'; // 优惠券 ID
$params = [
    'metadata' => [
        'key' => 'value',
    ],
];
\Pingpp\Coupon::update($user_id, $coupon_id, $params);

$user_id = 'uid582d1756b1650'; // 用户 ID
$coupon_id = '300416111711463500023901'; // 优惠券 ID
\Pingpp\Coupon::delete($user_id, $coupon_id);

$user_id = 'uid582d1756b1650'; // 用户 ID
$search_params = [ //搜索条件,此数组可以为空
    'page' => 1, //页码,取值范围:1~1000000000;默认值为"1"
    'per_page' => 2, //每页数量,取值范围:1~100;默认值为"20"
];
\Pingpp\Coupon::all($user_id, $search_params);

$params = [
    'withdrawals' => [
        '1701611150302360654',
        '1701611151015078981',
    ]
];
\Pingpp\BatchWithdrawal::confirm($params);

$params = [
    'withdrawals' => [
        '1701611150302360654',
        '1701611151015078981',
    ]
];
\Pingpp\BatchWithdrawal::cancel($params);


\Pingpp\BatchWithdrawal::retrieve('1901611151015122025'); //批量提现对象 ID。

$params = [
    'per_page' => 20,
    'page' => 1
];
\Pingpp\BatchWithdrawal::all($params);

\Pingpp\BalanceTransaction::all([]);

\Pingpp\BalanceTransaction::retrieve('310216111501260200000601');

$params = [
    "user" => 'u-s.e_r1479281694040', // 用户 ID
    "amount" => 200, // 转账金额
    "channel" => 'unionpay', // 提现使用渠道。银联:unionpay,支付宝:alipay,微信:wx
    "user_fee" => 10, // 用户需要承担的手续费
    "description" => "test232description",
    "order_no" => time() . mt_rand(11111, 99999), // 提现订单号,为长度不大于 16 的数字
    "extra" => [
        "card_number" => "6214888888888888",
        "user_name" => "张三",
        "open_bank_code" => "0102",
        "prov" => "上海",
        "city" => "上海",
    ],
];
\Pingpp\Withdrawal::create($params);

\Pingpp\Withdrawal::retrieve('1711611161932569404');

\Pingpp\Withdrawal::all([
    'per_page' => 3
]);

\Pingpp\BalanceBonus::create([
    'amount' => 10,
    'description' => '余额赠送描述',
    'user' => 'user_test_01',
    'order_no' => substr(md5(time()), 0, 10),
]);

\Pingpp\BalanceBonus::retrieve('651170807590953932800000');

\Pingpp\BalanceBonus::all()

\Pingpp\BalanceTransfer::create(
    [
        'amount' => 10,
        'user_fee' => 0,
        'user' => 'user_001',
        'recipient' => '0',
        'order_no' => substr(md5(random_bytes(64)), 0, 10),
        'description' => 'Your description',
        'metadata' => [],
    ]
);

\Pingpp\BalanceTransfer::retrieve('661170807435256330240000');

\Pingpp\BalanceTransfer::all()

\Pingpp\SubApp::create([
    'display_name' => 'sub_app_display_name',
    'user' => 'user_102',
    'metadata' => [
        'key' => 'value',
    ],
]);

\Pingpp\SubApp::retrieve('app_1Gqj58ynP0mHeX1q');

\Pingpp\SubApp::all();

$sub_app = \Pingpp\SubApp::update('app_1Gqj58ynP0mHeX1q', [
    'display_name' => 'display_name_2',
    'metadata' => [
        'key' => 'value2',
    ],
    'description' => 'Your description',
]);

\Pingpp\SubApp::delete('app_1Gqj58ynP0mHeX1q');

\Pingpp\Channel::create('app_1Gqj58ynP0mHeX1q', [
    'channel' => 'alipay',
    'params' => [
        'fee_rate' => 60,
        'alipay_pid' => '2088501666666666',
        'alipay_account' => '[email protected]',
        'alipay_security_key' => 'Your security_key',
        'alipay_mer_app_private_key' => '-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQDSBOW3jdthyqSBMNJ8P+BQnfoKpL29BtvACW1gr8YhXh8EqpBU
nUDdQgi8uYnprXBbR5O1DVnIqLKG9loEn3Rc2iqpnj3M3nSShuVByjyJjQ+DAIG2
/cgJjGQknCLo0CKtuEIyD5xBKYVz3GLofLKqCNGDYdUIxwgaBBpssNIDGQIDAQAB
AoGBAKmzw1taiRawA9VQegRkKQF7ZXwMOjTvwcme1H74CYUU5MOEfzOgDbW7kgvN
cJ8dwlg/sh7uNsppZjif/4UUw5R7bSu33m1sIyglmKUYTU7Kw+ETVAPgwkQjJhek
V/pDr143vmchAblD4RqQZTneojTkvYgci4RkHHHIIZ8lClIBAkEA/nEyCKzl0gxU
LWMd0HKLctcwDu6NPWycffFzSg/+k1+h0GlSTp2E8J6DKOYnrlQYvK2/BnbFPfrb
EySi+7c86QJBANNOExrr7xl54JnlZxbXNDnNrql2brPk1DsV/3Lo3Tmt8NuVqiyo
hVE8Vs/CPRqTTSPoTV4TwSscB4Torlox9rECQB9tne+CY7TJPxCIIKOhsmXR/Kar
gpimtMG9tC7ewOQ1OMiEad06CbSq76p6m0YmLxQHJgRHYV+hf7Pin5sV7BkCQQC6
9KxAuJk/YC9R2r/AXL4vmoU8GLZP4lnIwWjXwaLiwryFfEEp7BywyINCpOgtWED7
UTEK2M2jl9QrSzfgQ66xAkBm2RI+8onm/4PVKtOt8tqLjfsFGMR3g0aUwgSbznc0
Xg9dfU+YUgqfQnyAQHt9jG3/SBdmIrYoWwb7TqJZLkZI
-----END RSA PRIVATE KEY-----',
        'alipay_app_public_key' => '-----BEGIN PUBLIC KEY-----
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDSBOW3jdthyqSBMNJ8P+BQnfoK
pL29BtvACW1gr8YhXh8EqpBUnUDdQgi8uYnprXBbR5O1DVnIqLKG9loEn3Rc2iqp
nj3M3nSShuVByjyJjQ+DAIG2/cgJjGQknCLo0CKtuEIyD5xBKYVz3GLofLKqCNGD
YdUIxwgaBBpssNIDGQIDAQAB
-----END PUBLIC KEY-----',
    ],
    'banned' => false,
    'banned_msg' => null,
    'description' => 'alipay description',
]);

\Pingpp\Channel::retrieve('app_1Gqj58ynP0mHeX1q', 'alipay');

\Pingpp\Channel::update('app_1Gqj58ynP0mHeX1q', 'alipay', [
    'description' => 'new description',
    'params' => [
        'fee_rate' => 50,
        'alipay_pid' => 'Your Alipay pid',
        'alipay_account' => '[email protected]',
    ],
]);

\Pingpp\Channel::delete('app_1Gqj58ynP0mHeX1q', 'alipay');

\Pingpp\SettleAccount::create('user_004', [
    'channel' => 'alipay',
    'recipient' => [
        'type' => 'b2c', //转账类型。b2c:企业向个人付款,b2b:企业向企业付款。
        'account' => '[email protected]',
        'name' => '李狗',
    ],
]);

\Pingpp\SettleAccount::retrieve('user_008', '320217031816231000001001');

\Pingpp\SettleAccount::update(
    'user_001', // 用户 ID
    '320118012216303200004401', // 结算账户 ID
    [
        'recipient' => [
            'account' => '6214888888888866', // 银行卡号。
            'name' => '张三', // 接收者姓名。
            'type' => 'b2c', // 转账类型。b2c:企业向个人付款,b2b:企业向企业付款。
            'open_bank_code' => '0308', // 开户银行编号
            "open_bank" => "工商银行",
            "sub_bank" => "招商银行股份有限公司上海陆家嘴支行",
            "sub_bank_code" => "308290003773",
            'card_type' => 0, // 银行卡号类型,0:银行卡;1:存折。
            'mobile' => '13822334557', // 手机号
            "city" => "上海市",
            "prov" => "上海市",
        ],
    ]
);

\Pingpp\SettleAccount::delete('user_008', '320217031816231000001001');

\Pingpp\SettleAccount::all('user_008');

\Pingpp\SettleAccount::updateMobile(
    'user_001', // 用户 ID
    '320118012216303200004401', // 结算账户 ID
    [
        'mobile' => '13822334557',
    ]
);

\Pingpp\SettleAccount::verify(
    'user_001', // 用户 ID
    '320118012216303200004401', // 结算账户 ID
    [
        'receive_amount' => 2,
    ]
);

$royalties = \Pingpp\Royalty::update([
    'ids' => [
        '170301124238000111',
        '170301124238000211',
    ],
    'method' => 'manual', //手动标记结算: manual 或 取消手动标记结算:null
    'description' => 'Your description',
]);

\Pingpp\Royalty::retrieve('411170318160900002');

\Pingpp\Royalty::all();

\Pingpp\RoyaltySettlement::create([
    'payer_app' => APP_ID,
    'method' => 'alipay',   //分润的方式,余额 balance 或渠道名称,例如 alipay
    'recipient_app' => APP_ID,
    'created' => [
        'gt' => 1489826451,
        'lt' => 1492418451,
    ],
    'source_user' => 'user_002',
    //'source_no' => '',
    'min_amount' => 1,
    'metadata' => [
        'key' => 'value',
    ],
]);

\Pingpp\RoyaltySettlement::retrieve('431170318144700001');

\Pingpp\RoyaltySettlement::update('431170318144700001', [
    'status' => 'pending' // pending, canceled
]);

\Pingpp\RoyaltySettlement::all([
    'payer_app' => APP_ID,
]);

\Pingpp\RoyaltyTransaction::retrieve('441170318144700002');
bash
php PingppEnvInspect.php

composer 
php
\Pingpp\RoyaltyTransaction::all();
php
\Pingpp\RoyaltyTemplate::retrieve('451170807182300001')
php
\Pingpp\RoyaltyTemplate::retrieve('451170807182300001')
php
\Pingpp\RoyaltyTemplate::delete('451170807182300001')
php
\Pingpp\SplitReceiver::retrieve('recv_1fRbIo0jME7yuL');
php
\Pingpp\SplitReceiver::delete('recv_1fRbIo0jME7yuL');
php
\Pingpp\SplitReceiver::all([
    'app' => APP_ID,
    'page' => 1,
    'per_page' => 10,
]);
php
\Pingpp\SplitProfit::create([
    'app' => APP_ID,
    'charge' => 'ch_aDC44OKyL8yHPG0yX9yzLy5K', // Ping++ 交易成功的 charge ID
    'order_no' => md5(random_bytes(64)), // 分账单号,由商家自行生成,规则参照微信分账参数规则
    'recipients' => [
        [
            'split_receiver' => 'recv_1fRbIo5YgIM4hl',
            'amount' => 6,
            'name' => '示例商户全称', // 可选参数,
            'description' => 'Your Description',
        ]
    ],
    'type' => 'split_normal', // 分账类型: split_normal 为普通分账,split_return 为完结分账,
    'metadata' => [], // 分账元数据
]);
php
\Pingpp\SplitProfit::create([
    'app' => APP_ID,
    'charge' => 'ch_aDC44OKyL8yHPG0yX9yzLy5K', //Ping++ 交易成功的 charge ID
    'order_no' => md5(random_bytes(64)), //分账单号,由商家自行生成,规则参照微信分账参数规则
    'recipients' => [
        [
            'split_receiver' => 'recv_1fRbIo5YgIM4hl',
            'amount' => 6,
            'name' => '示例商户全称', //可选参数,
            'description' => 'Your Description',
        ]
    ],
    'type' => 'split_return', //分账类型: split_normal 为普通分账,split_return 为完结分账,
    'metadata' => [], //分账元数据
]);
php
\Pingpp\SplitProfit::retrieve('sp_1iXmpPJLe71sf9');
php
\Pingpp\SplitProfit::all([
    'app' => APP_ID,
    'page' => 1,
    'per_page' => 10,
]);
php
\Pingpp\ProfitTransaction::all([
    'app' => APP_ID,
    'page' => 1,
    'per_page' => 10,
]);
php
\Pingpp\ProfitTransaction::retrieve('ptxn_1m3c7aGbDK2cpl');
php
\Pingpp\SubBank::query([
    'app' => APP_ID, // Ping++ app id,必填
    'channel' => 'chanpay', // transfer 渠道,必填
    'open_bank_code' => '0308', // 银行编号,必填
    'prov' => '浙江省', // 省份,必填
    'city' => '宁波市', // 城市,必填
]);