Skip to content

Commit

Permalink
feat: 🎸 添加bepusdt插件
Browse files Browse the repository at this point in the history
  • Loading branch information
monlor committed May 6, 2024
1 parent 7aa89fb commit 5da64c4
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bepusdt/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 介绍

支持arm,修改自:https://github.com/v03413/bepusdt?tab=readme-ov-file
支持arm,修改自:https://github.com/v03413/bepusdt?tab=readme-ov-file

独角数卡接口地址配置格式:https://usdt.xxx.com/api/v1/order/create-transaction
2 changes: 2 additions & 0 deletions epay/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ RUN git clone https://github.com/LightCountry/TokenPay && \
# Expose端口
EXPOSE 80

ADD plugins /tmp/epay/plugins

COPY start.sh /opt/start.sh

RUN chmod +x /opt/start.sh
Expand Down
106 changes: 106 additions & 0 deletions epay/plugins/bepusdt/bepusdt_plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
<?php

class bepusdt_plugin
{
static public $info = [
'name' => 'bepusdt',
'showname' => 'Bepusdt(一款更好用的个人USDT收款网关)',
'author' => '莫名',
'link' => 'https://github.com/v03413/bepusdt', //支付插件作者链接
'types' => ['usdt'], //支付插件支持的支付方式,可选的有alipay,qqpay,wxpay,bank
'inputs' => [ //支付插件要求传入的参数以及参数显示名称,可选的有appid,appkey,appsecret,appurl,appmchid
'appid' => [
'name' => '接口地址',
'type' => 'input',
'note' => '必须以http://或https://开头,以/结尾',
],
'appsecret' => [
'name' => 'Token',
'type' => 'input',
'note' => '',
]
],
'select' => null,
'note' => ''
];

public static function submit(): array
{
global $siteurl, $channel, $order, $conf;

$data = [
"order_id" => TRADE_NO,
"amount" => (float)$order['realmoney'],
"notify_url" => $conf['localurl'] . 'pay/notify/' . TRADE_NO . '/',
"redirect_url" => $siteurl . 'pay/return/' . TRADE_NO . '/',
];
$resp = self::createTransaction($data, $channel['appid'], $channel['appsecret']);
$json = json_decode($resp, true);
if (!is_array($json) || $json['status_code'] != 200) {

return ['type' => 'error', 'msg' => 'Bepusdt 订单创建失败,请检测相关配置是否错误!'];
}

return ['type' => 'jump', 'url' => $json['data']['payment_url']];
}

public static function notify()
{
global $channel, $order;

$data = json_decode(file_get_contents('php://input'), true);
if (!is_array($data)) {

exit('fail');
}

$sign = $data['signature'];
unset($data['signature']);

if ($sign != self::toSign($data, $channel['appsecret'])) {

exit('sign error');
}

processNotify($order, $data['trade_id']);

exit('ok');
}

public static function return()
{
global $order;

processReturn($order, $order['api_trade_no']);
}

private static function toSign(array $data, $token): string
{
ksort($data);
$sign = '';
foreach ($data as $k => $v) {
if ($v == '') continue;
$sign .= $k . '=' . $v . '&';
}
$sign = trim($sign, '&');
return md5($sign . $token);
}

private static function createTransaction(array $data, $api, $token)
{
$data['signature'] = self::toSign($data, $token);

$url = $api . 'api/v1/order/create-transaction';
$header = ['Content-Type: application/json; charset=UTF-8'];
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //SSL证书认证false
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false); //严格认证false
curl_setopt($curl, CURLOPT_HTTPHEADER, $header); //设置HTTPHEADER
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 显示输出结果
curl_setopt($curl, CURLOPT_POST, true); // post传输数据
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); // post传输数据
$res = curl_exec($curl);
curl_close($curl);
return $res;
}
}

0 comments on commit 5da64c4

Please sign in to comment.