Compare commits

...

4 Commits

Author SHA1 Message Date
zbuse
48f7539918
Merge fc6bb8cf34 into 7acae3dcc4 2025-01-22 10:48:15 +08:00
Xboard
7acae3dcc4
Update docker-publish.yml 2025-01-21 22:14:01 +08:00
Xboard
dff2e721cb
Update docker-publish.yml 2025-01-21 22:05:56 +08:00
zbuse
fc6bb8cf34
Create EpusdtPay.php 2024-01-24 17:53:03 +08:00
2 changed files with 102 additions and 2 deletions

View File

@ -2,7 +2,7 @@ name: Docker Build and Publish
on: on:
push: push:
branches: ["legacy"] branches: ["legacy", "dev"]
workflow_dispatch: workflow_dispatch:
env: env:
@ -73,6 +73,9 @@ jobs:
cache-to: type=gha,mode=max cache-to: type=gha,mode=max
tags: | tags: |
${{ env.REGISTRY }}/${{ github.repository_owner }}/xboard:legacy ${{ env.REGISTRY }}/${{ github.repository_owner }}/xboard:legacy
${{ env.REGISTRY }}/${{ github.repository_owner }}/xboard:dev
${{ env.REGISTRY }}/${{ github.repository_owner }}/xboard
${{ env.REGISTRY }}/${{ github.repository_owner }}/xboard:latest
${{ env.REGISTRY }}/${{ github.repository_owner }}/xboard:${{ steps.get_version.outputs.version }} ${{ env.REGISTRY }}/${{ github.repository_owner }}/xboard:${{ steps.get_version.outputs.version }}
build-args: | build-args: |
BUILDKIT_INLINE_CACHE=1 BUILDKIT_INLINE_CACHE=1
@ -88,4 +91,4 @@ jobs:
env: env:
COSIGN_EXPERIMENTAL: 1 COSIGN_EXPERIMENTAL: 1
run: | run: |
echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes "{}@${{ steps.build-and-push.outputs.digest }}" echo "${{ steps.meta.outputs.tags }}" | xargs -I {} cosign sign --yes "{}@${{ steps.build-and-push.outputs.digest }}"

View File

@ -0,0 +1,97 @@
<?php
//author by GoodGoodStudy
namespace App\Payments;
use \Curl\Curl;
class EpusdtPay {
public function __construct($config)
{
$this->config = $config;
}
public function form()
{
return [
'epusdt_pay_url' => [
'label' => 'API 地址',
'description' => '您的 EpusdtPay API 接口地址(例如: https://epusdt-pay.xxx.com)',
'type' => 'input',
],
'epusdt_pay_apitoken' => [
'label' => 'API Token',
'description' => '您的 EpusdtPay API Token',
'type' => 'input',
]
];
}
public function pay($order)
{
$params = [
"amount" => round($order['total_amount']/100,2),
"order_id" => $order['trade_no'],
'redirect_url' => $order['return_url'],
'notify_url' => $order['notify_url'],
];
$params['signature'] = $this->sign($params);
$curl = new Curl();
$curl->setUserAgent('EpusdtPay');
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
$curl->setOpt(CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
$curl->post($this->config['epusdt_pay_url'] . '/api/v1/order/create-transaction', json_encode($params));
$result = $curl->response;
$curl->close();
if (!isset($result->status_code) || $result->status_code != 200) {
abort(500, "Failed to create order. Error: {$result->message}");
}
return [
'type' => 1, // 0:qrcode 1:url
'data' => $result->data->payment_url
];
}
public function notify($params)
{
$status = $params['status'];
// 1等待支付2支付成功3已过期
if ($status != 2) {
die('failed');
}
//不合法的数据
if (!$this->verify($params)) {
die('cannot pass verification');
}
return [
'trade_no' => $params['order_id'],
'callback_no' => $params['trade_id'],
'custom_result' => 'ok'
];
}
public function verify($params) {
return $params['signature'] === $this->sign($params);
}
protected function sign(array $params)
{
ksort($params);
reset($params); //内部指针指向数组中的第一个元素
$sign = '';
$urls = '';
foreach ($params as $key => $val) {
if ($val == '') continue;
if ($key != 'signature') {
if ($sign != '') {
$sign .= "&";
$urls .= "&";
}
$sign .= "$key=$val"; //拼接为url参数形式
$urls .= "$key=" . urlencode($val); //拼接为url参数形式
}
}
$sign = md5($sign . $this->config['epusdt_pay_apitoken']);//密码追加进入开始MD5签名
return $sign;
}
}