PHP code example of hempflower / payment-sdk-php

1. Go to this page and download the library: Download hempflower/payment-sdk-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/ */

    

hempflower / payment-sdk-php example snippets


$config = [
            'wechat' => [
                'app_id'    =>'',
                'mch_id'    =>'',
                'mch_key'   =>'',
                'ssl_cer'   =>'',
                'ssl_key'   =>'',
                'notify_url'=>''
            ],
            'alipay' => [
                //应用ID,您的APPID。
                'app_id' => "",
                //商户私钥, 请把生成的私钥文件中字符串拷贝在此
                'private_key'    =>'',
                //支付宝公钥,查看地址:https://openhome.alipay.com/platform/keyManage.htm 对应APPID下的支付宝公钥。
                'public_key' => '',
                //异步通知地址
                'notify_url' => "",
                //同步跳转
                'return_url' => "",
                //沙箱
                'debug'           => false,
            ],
            'qpay' => [
                // QQ钱包分配的商户号
                'mch_id'          => '',
                // Qpay商户号
                'sub_mch_id'      => '',
                // Qpay支付签名秘钥
                'mch_key'         => '',
                //异步通知地址
                'notify_url'      => '',
                'ssl_cer'         => '',
                'ssl_key'         => '',
                //沙箱
                'debug'           => false,
            ],
        ];

// 实例支付对象
$pay = new \Sheep\payment\Pay($config);

try {
    $options = $pay->driver('alipay')->gateway('wap')->apply($payOrder);
    var_dump($options);
} catch (Exception $e) {
    echo "创建订单失败," . $e->getMessage();
}

 if ($this->request->isPost()){
            $driver = $this->request->post('driver');
            $gateway = $this->request->post('gateway');
            switch ($driver){
                case 'alipay':
                    $order = [
                        'out_trade_no' => time(),
                        'total_amount' => '0.01', //微信 total_fee
                        'subject'      => 'test subject-测试订单',//微信 body
                    ];
                    break;
                default:
                    $order = [
                        'out_trade_no' => time(),
                        'total_fee' => '1', //微信 total_fee  //单位:分
                        'body'      => 'test subject-测试订单',//微信 body
                    ];
                    break;
            }
            $pay = new Pay($config);
            $result = $pay->driver($driver)->gateway($gateway)->pay($order);
            halt($result);
        }
    }

// 实例支付对象
$pay = new \Sheep\payment\Pay($config);

$verify = $pay->driver('alipay')->gateway()->verify($_POST);
if ($verify) {
  //TODO 支付成功操作
} else {
  //验签失败
}

$pay = new \Pay\Pay($config);
$verify = $pay->driver('wechat')->gateway('mp')->verify(file_get_contents('php://input'));

if ($verify) {
  //TODO 支付成功操作
} else {
  //验签失败
}

echo "success";
shell
// 方法一、 使用git安装
git clone https://github.com/singlesheep/payment-sdk-php