composer require fengkui/pay
$wechatConfig = [
'xcxid' => '',
'appid' => '',
'mchid' => '',
'key' => '',
'appsecret' => '',
'sp_appid' => '',
'sp_mchid' => '',
'notify_url' => '',
'redirect_url' => '',
'serial_no' => '',
'cert_client' => './cert/apiclient_cert.pem',
'cert_key' => './cert/apiclient_key.pem',
'public_key_id' => '',
'public_key' => './cert/public_key.pem',
];
$alipayConfig = [
'app_id' => '',
'public_key' => '',
'private_key' => '',
'notify_url' => '',
'return_url' => '',
'sign_type' => 'RSA2',
'is_sandbox' => false,
];
$unionConfig = [
'mchid' => '',
'sign_pwd' => '',
'sign_path' => './cert/acp_test_sign.pfx',
'verify_path' => './cert/verify_sign_acp.cer',
'acp_root' => './cert/acp_test_root.cer',
'acp_middle' => './cert/acp_test_middle.cer',
'notify_url' => '',
'return_url' => '',
'is_sandbox' => true,
];
$baiduConfig = [
'deal_id' => '',
'app_key' => '',
'private_key' => '',
'public_key' => '',
'notify_url' => '',
];
$bytedanceConfig = [
'app_id' => '',
'salt' => '',
'token' => '',
'notify_url' => '',
'thirdparty_id' => '',
];
$pay = new \fengkui\Pay\Wechat($wechatConfig);
$pay = new \fengkui\Pay\Alipay($alipayConfig);
$pay = new \fengkui\Pay\Unionpay($unionConfig);
$pay = new \fengkui\Pay\Baidu($baiduConfig);
$pay = new \fengkui\Pay\Bytedance($bytedanceConfig);
<?php
* @Author: [FENG] <1161634940@qq.com>
* @Date: 2021-06-01T14:55:21+08:00
* @Last Modified by: [FENG] <1161634940@qq.com>
* @Last Modified time: 2021-06-15 15:39:01
*/
require_once('./vendor/autoload.php');
class Payment
{
protected static $pay = '';
protected static $type = '';
protected static $config = [];
* [_initialize 构造函数(获取支付类型与初始化配置)]
* @return [type] [description]
*/
public function _initialize()
{
self::$type = $_GET['type'] ?? 'alipay';
self::config();
}
* [config 获取配置]
* @param string $type [description]
* @return [type] [description]
*/
protected static function config($type='')
{
$type = $type ?: self::$type;
$alipayConfig = [];
if (in_array($type, ['wechat', 'baidu', 'bytedance', 'alipay', 'union'])) {
$config = $type . "Config";
self::$config = $config;
} else {
die('当前类型配置不存在');
}
$type && self::$pay =(new \fengkui\Pay())::$type(self::$config);
}
public function pay()
{
$order = [
'body' => 'subject-测试',
'order_sn' => time(),
'total_amount' => 0.01,
];
$result = self::$pay->web($order);
echo $result;
}
}