composer require chen-see/chen-pay
include __DIR__ . '/../vendor/autoload.php';
$aliCookie = '';
$wxCookie = '';
$GLOBALS['aliSum'] = 1;
$GLOBALS['aliType'] = true; // 支付宝接口切换
$GLOBALS['aliStatus'] = time(); // 暂停 有订单情况下才是10秒一次的频率 杜绝支付宝风控
ChenPay\Pay::Listen(10, function () use ($aliCookie) {
// time 现在时间此为订单生成时间 默认3分钟有效时间
$data = [['fee' => 0.01, 'time' => time() + 3 * 60]];
if ($GLOBALS['aliStatus'] > time() && count($data) == 0) return;
try {
$run = (new ChenPay\AliPay($aliCookie))->getData($GLOBALS['aliType'])->DataHandle();
foreach ($data as $item) {
$remarks = '123456'; //如果需要判断备注
$order = $run->DataContrast($item['fee'], $item['time'], 5, $remarks);
if ($order) echo "{$order}订单有效!备注:{$remarks}\n";
unset($order, $item);// 摧毁变量防止内存溢出
}
echo $GLOBALS['aliSum'] . "次运行\n";
$GLOBALS['aliType'] = !$GLOBALS['aliType'];
$GLOBALS['aliSum']++;
$GLOBALS['aliStatus'] = time() + 2 * 60; //
} catch (\ChenPay\PayException\PayException $e) {
echo $e->getMessage() . "\n";
unset($e);// 摧毁变量防止内存溢出
}
unset($run, $data);// 摧毁变量防止内存溢出
});
$GLOBALS['wxSum'] = 1;
$GLOBALS['syncKey'] = false;
ChenPay\Pay::Listen(10, function () use ($wxCookie) {
// time 现在时间此为订单生成时间 默认3分钟有效时间
$data = [['fee' => 0.01, 'time' => time() + 3 * 60]];
try {
$run = (new ChenPay\WxPay($wxCookie))->getData('wx.qq.com', $GLOBALS['syncKey'])->DataHandle();
$GLOBALS['syncKey'] = $run->syncKey;
foreach ($data as $item) {
$remarks = '123456'; //如果需要判断备注
$order = $run->DataContrast($item['fee'], $item['time'], 3, $remarks);
if ($order) echo "{$order}订单有效!备注:{$remarks}\n";
unset($order, $item);// 摧毁变量防止内存溢出
}
echo $GLOBALS['wxSum'] . "次运行\n";
$GLOBALS['wxSum']++;
} catch (\ChenPay\PayException\PayException $e) {
echo $e->getMessage() . "\n";
unset($e);// 摧毁变量防止内存溢出
}
unset($run, $data);// 摧毁变量防止内存溢出
});
# 前台运行
php test/test.php
# 后台运行
nohup php test/test.php &