| Server IP : 43.141.50.122 / Your IP : 113.219.202.44 Web Server : Apache System : Linux VM-8-5-opencloudos 6.6.34-9.oc9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 19 19:35:45 CST 2024 x86_64 User : www ( 1000) PHP Version : 8.1.27 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /www/wwwroot/www.ucppt.com/wp-content/plugins/wpcom-member-pro/payment/ |
Upload File : |
<?php
namespace WPCOM\Member\Payments;
use WPCOM\Member\Order;
use WPCOM\Themer\Session;
defined('ABSPATH') || exit;
class Payment {
public $id;
public $title;
public $icon;
public $color;
public $modal;
public function __construct() {
add_filter('wpcom_payment_gateways', [$this, 'add_gateway']);
add_action("wpcom_payment_{$this->id}_check_response", [$this, 'check_response']);
add_action("wpcom_payment_{$this->id}_submit_page", [$this, 'submit_page_render'], 10, 2);
add_action("wpcom_payment_{$this->id}_receipt_page", [$this, 'receipt_page_render']);
add_action("wpcom_payment_{$this->id}_return_page", [$this, 'return_page_render']);
}
function add_gateway($methods) {
if ($this->id) $methods[$this->id] = $this;
return $methods;
}
public function process_payment($order_id) {
$url = Order::get_checkout_payment_url($order_id);
return [
'result' => 'success',
'redirect' => $url
];
}
function submit_page_render($res, $data) {
if ($res['result'] === 0 && $res['order_id']) {
$order_id = $res['order_id'];
$output = '<div class="loading-img"></div><p class="loading-text">正在创建订单...</p>';
$output .= '<script>if(window.opener) {window.opener.postMessage(JSON.parse(\'' . wp_json_encode($res) . '\'), \'*\');} window.location.href = "' . $res['redirect'] . '";</script>';
} else {
$order_id = $data;
$output = '<p class="text-center" style="color:#f66;padding: 20px 0;">' . (isset($res['msg']) && $res['msg'] ? $res['msg'] : '订单创建失败,请稍后再试!') . '</p>';
}
$this->html_template($output, $order_id);
}
function receipt_page_render($order_id) {
if (function_exists('WWA_is_rest') && WWA_is_rest()) {
return $this->receipt_page($order_id);
}
ob_start();
$this->receipt_page($order_id);
$output = ob_get_contents();
ob_end_clean();
$this->html_template($output, $order_id);
}
function return_page_render($order_id) {
ob_start();
$this->return_page($order_id);
$output = ob_get_contents();
ob_end_clean();
$this->html_template($output, $order_id);
}
function html_template($html, $order_id) {
global $wpmx_options, $options;
$color = isset($wpmx_options['member_color']) && $wpmx_options['member_color'] ? $wpmx_options['member_color'] : '#206be7';
$is_theme = function_exists('wpcom_setup') && $options;
$color = $is_theme && isset($options['theme_color']) && $options['theme_color'] ? \WPCOM::color($options['theme_color']) : $color;
$br_l = $is_theme && isset($options['border-radius-l']) && $options['border-radius-l'] ? $options['border-radius-l'] : '8px';
$br_m = $is_theme && isset($options['border-radius-m']) && $options['border-radius-m'] ? $options['border-radius-m'] : '3px';
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?php echo $this->title; ?></title>
<style>
* {
padding: 0;
margin: 0;
}
:root {
--member-color: <?php echo $color; ?>;
--payment-color: <?php echo $this->color; ?>
}
body {
background: var(--payment-color);
max-width: 600px;
margin: 0 auto;
padding: 0;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, Ubuntu, Helvetica Neue, Helvetica, Arial, PingFang SC, Hiragino Sans GB, Microsoft YaHei UI, Microsoft YaHei, Source Han Sans CN, sans-serif;
font-size: 14px;
line-height: 1.42857;
color: #fff;
}
<?php if (!$this->modal) { ?>body {
padding-top: 30px;
}
<?php } ?>.order-details {
padding: 0 30px;
margin-bottom: 10px;
text-align: center;
}
.order-details-title {
display: block;
font-size: 26px;
line-height: 32px;
font-weight: 500;
}
.order-details-title span{
display: inline-flex;
align-items: center;
gap: 2px;
}
.order-details-title span span {
font-size: 22px;
font-weight: 400;
gap: 0;
}
.order-details-title svg.icon{
font-size: .9em;
}
.order-details-value {
display: block;
font-size: 16px;
line-height: 26px;
}
.order-payment {
padding: 15px 20px 0;
}
.order-payment-inner {
padding: 20px 15px;
color: #333;
background: #fff;
border-radius: <?php echo $br_l; ?>;
text-align: center;
}
.order-payment-logo {
margin-bottom: 20px;
}
.order-payment-logo img {
max-width: 60%;
max-height: 42px;
vertical-align: top;
}
.order-payment-for-wallet .order-payment-logo,.order-payment-for-points .order-payment-logo {
display: flex;
align-items: center;
justify-content: center;
font-size: 26px;
font-weight: 300;
color: var(--payment-color);
user-select: none;
}
.order-payment-for-wallet .order-payment-logo .wpcom-icon,.order-payment-for-points .order-payment-logo .wpcom-icon {
margin-right: 5px;
font-size: 36px;
line-height: 36px;
}
.order-payment-for-wallet .order-payment-logo .wpcom-icon svg,.order-payment-for-points .order-payment-logo .wpcom-icon svg {
width: 1em;
height: 1em;
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
}
.order-status {
padding: 30px;
text-align: center;
}
.order-status p {
font-size: 16px;
margin-top: 10px;
}
.order-status-icon {
display: block;
width: 96px;
height: 96px;
margin: 0 auto;
background-repeat: no-repeat;
background-size: 100%;
}
.order-status-success {
color: #52c41a;
}
.order-status-success .order-status-icon {
background-image: url("data:image/svg+xml,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M512 64q190.016 4.992 316.512 131.488T960 512q-4.992 190.016-131.488 316.512T512 960q-190.016-4.992-316.512-131.488T64 512q4.992-190.016 131.488-316.512T512 64zm-56 536l-99.008-99.008q-12-11.008-27.488-11.008t-27.008 11.488-11.488 26.496 11.008 27.008l127.008 127.008q11.008 11.008 27.008 11.008t27.008-11.008l263.008-263.008q15.008-15.008 9.504-36.512t-27.008-27.008-36.512 9.504z' fill='%2352c41a'/%3E%3C/svg%3E");
}
.order-status-fail {
color: #f66;
}
.order-status-fail .order-status-icon {
background-image: url("data:image/svg+xml;base64,PHN2ZyBjbGFzcz0iaWNvbiIgdmlld0JveD0iMCAwIDEwMjQgMTAyNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iMjQiIGhlaWdodD0iMjQiPjxwYXRoIGQ9Ik01MTIgNjRxMTkwLjAxNiA0Ljk5MiAzMTYuNTEyIDEzMS40ODhUOTYwIDUxMnEtNC45OTIgMTkwLjAxNi0xMzEuNDg4IDMxNi41MTJUNTEyIDk2MHEtMTkwLjAxNi00Ljk5Mi0zMTYuNTEyLTEzMS40ODhUNjQgNTEycTQuOTkyLTE5MC4wMTYgMTMxLjQ4OC0zMTYuNTEyVDUxMiA2NHptMCAxOTJxLTI2LjAxNiAwLTQzLjAwOCAxOS4wMDhUNDUzLjk4NCAzMjBsMjMuMDA4IDI1NnEyLjAxNiAxNC4wMTYgMTEuNDg4IDIyLjQ5NnQyMy40ODggOC41MTIgMjMuNDg4LTguNTEyVDU0Ni45NDQgNTc2bDIzLjAwOC0yNTZxMi4wMTYtMjYuMDE2LTE1LjAwOC00NC45OTJUNTExLjkzNiAyNTZ6bTAgNTEycTIyLjAxNi0uOTkyIDM2LjUxMi0xNS4wMDh0MTQuNDk2LTM2LTE0LjQ5Ni0zNi41MTJUNTEyIDY2NS45ODR0LTM2LjUxMiAxNC40OTYtMTQuNDk2IDM2LjUxMiAxNC40OTYgMzZUNTEyIDc2OHoiIGZpbGw9IiNmNjYiLz48L3N2Zz4=");
}
.btn {
display: inline-block;
padding: 10px 13px;
color: #fff;
font-size: 14px;
line-height: 14px;
border-radius: <?php echo $br_m; ?>;
background: var(--payment-color);
text-decoration: none;
border: 0;
cursor: pointer;
box-sizing: border-box;
}
.btn-border {
padding: 9px 12px;
border: 1px solid var(--payment-color);
color: var(--payment-color);
background: #fff;
}
.btn+.btn {
margin-left: 10px;
}
.btn:hover {
position: relative;
z-index: 0;
}
.btn:hover:after {
pointer-events: none;
position: absolute;
z-index: -1;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: #fff;
opacity: .1;
border-radius: inherit;
content: ''
}
.btn.loading {
opacity: .7;
cursor: default;
}
.btn.loading:hover:after {
display: none;
}
.btn-help {
margin-top: 20px;
}
.btn-view {
display: block;
width: 100%;
padding: 10px 15px;
margin-top: 30px;
font-size: 16px;
line-height: 18px;
}
svg.icon {
display: inline-block;
width: 1em;
height: 1em;
vertical-align: -0.15em;
fill: currentColor;
overflow: hidden;
}
.loading-img {
width: 36px;
height: 36px;
margin: 10px auto;
background-size: 100% 100%;
background-image: url("data:image/svg+xml,%3Csvg class='icon' viewBox='0 0 1024 1024' xmlns='http://www.w3.org/2000/svg' width='24' height='24'%3E%3Cpath d='M512 85.333A42.667 42.667 0 0 1 554.667 128v128a42.667 42.667 0 0 1-85.334 0V128A42.667 42.667 0 0 1 512 85.333zm0 640A42.667 42.667 0 0 1 554.667 768v128a42.667 42.667 0 0 1-85.334 0V768A42.667 42.667 0 0 1 512 725.333zM938.667 512A42.667 42.667 0 0 1 896 554.667H768a42.667 42.667 0 0 1 0-85.334h128A42.667 42.667 0 0 1 938.667 512zm-640 0A42.667 42.667 0 0 1 256 554.667H128a42.667 42.667 0 0 1 0-85.334h128A42.667 42.667 0 0 1 298.667 512zm515.029 301.696a42.667 42.667 0 0 1-60.33 0L662.868 723.2a42.667 42.667 0 0 1 60.331-60.33l90.496 90.453a42.667 42.667 0 0 1 0 60.373zM361.131 361.131a42.667 42.667 0 0 1-60.331 0l-90.453-90.454a42.667 42.667 0 0 1 60.33-60.373l90.454 90.496a42.667 42.667 0 0 1 0 60.33zM210.347 813.696a42.667 42.667 0 0 1 0-60.33l90.496-90.497a42.667 42.667 0 1 1 60.33 60.331l-90.453 90.496a42.667 42.667 0 0 1-60.373 0zm452.522-452.565a42.667 42.667 0 0 1 0-60.331l90.454-90.496a42.667 42.667 0 0 1 60.373 60.33L723.2 361.132a42.667 42.667 0 0 1-60.33 0z' fill='%23777'/%3E%3C/svg%3E");
animation: rotating 2s linear infinite;
}
@keyframes rotating {
0% {
transform: rotate(0deg)
}
to {
transform: rotate(1turn)
}
}
.loading-text {
color: #666;
line-height: 2;
font-size: 14px;
}
</style>
</head>
<body>
<?php $this->order_detail($order_id); ?>
<div class="order-payment order-payment-for-<?php echo esc_attr($this->id); ?>">
<div class="order-payment-inner">
<div class="order-payment-logo">
<?php if ($this->id === 'wallet') { ?>
<i class="wpcom-icon wi"><?php echo $this->icon; ?></i>钱包余额
<?php } else if($this->id === 'points') { ?>
<i class="wpcom-icon wi"><?php echo $this->icon; ?></i>我的积分
<?php }else{ ?>
<img src="<?php echo esc_url($this->icon); ?>" alt="<?php echo esc_attr($this->title); ?>">
<?php } ?>
</div>
<?php echo $html; ?>
</div>
</div>
</body>
</html>
<?php }
function order_detail($order_id) {
if (is_array($order_id)) { // 出错的情况下返回
if (isset($order_id['order_id']) && $order_id['order_id']) {
$order = Order::get_order($order_id['order_id']);
} else {
$order = new \stdClass;
$order->price = $order_id['total'];
$order->number = '-';
}
} else {
$order = Order::get_order($order_id);
}
$points = $order && isset($order->payment_gateway) && $order->payment_gateway === 'points';
?>
<div class="order-details">
<?php if($points){ ?>
<span class="order-details-title"><span><span>订单价格:<?php echo $this->icon;?></span><?php echo number_format($order->price, 0, '.', ''); ?></span></span>
<?php } else { ?>
<span class="order-details-title"><span><span>订单价格:¥</span><?php echo $order->price; ?></span></span>
<?php } ?>
<span class="order-details-value"><?php echo $order->number; ?></span>
</div>
<?php }
public function check_response($order_id) {
}
public function receipt_page($order_id) {
}
public function return_page($order_id) {
$order = Order::get_order($order_id);
/**
* 备用,一般订单状态会通过异步请求同步,个别情况下可能同步失败,
* 此hook方便支付接口返回页面再次进行校验,例如支付宝
*/
$status = apply_filters('wpcom_return_page_order_status', $order->status, $order_id);
$target = isset($this->modal) && $this->modal ? 'target="_parent"' : '';
if ($status === 'paid') { ?>
<div class="order-status order-status-success">
<div class="order-status-icon"></div>
<p>订单支付成功</p>
<?php if (get_current_user_id()) { ?>
<a class="btn btn-view" <?php echo $target; ?> href="<?php echo esc_url(Order::order_url($order->ID)); ?>">查看订单</a>
<?php } else if (isset($this->modal) && $this->modal) { ?>
<a class="btn btn-view" href="javascript:(parent ? parent : window).location.reload();">刷新查看</a>
<?php } else {
$ref = Session::get('_order_referer_' . $order->ID);
if ($ref) { ?>
<a class="btn btn-view" <?php echo $target; ?> href="<?php echo esc_url(urldecode($ref)); ?>">返回支付发起页面</a>
<?php } else { ?>
<span style="display:block;margin-top:5px;opacity:0.85;">具体购买信息请返回付款发起页面刷新查看,如有问题请及时联系我们。</span>
<?php }
} ?>
</div>
<?php } else {
$help_url = wpcom_mp_options('help_url'); ?>
<div class="order-status order-status-fail" style="padding: 30px 15px;">
<div class="order-status-icon"></div>
<p>订单暂未完成支付</p>
<p style="margin-top: 2px;">如有疑问请联系网站客服获取帮助</p>
<a class="btn btn-help" href="javascript:window.location.reload();">已支付?刷新试试</a>
<?php if ($help_url) { ?><a class="btn btn-help btn-border" <?php echo $target; ?> href="<?php echo $help_url; ?>">支付遇到问题</a><?php } ?>
</div>
<?php }
}
public function get_order_title($order) {
$id = $order->number;
$title = get_option('blogname') . " #{$id}";
/**
* 用于自定义商品支付订单标题
* @param string $title 标题
* @param object $order 订单信息
* @param string $this->id 使用的支付接口标识
*/
$title = apply_filters('wpcom_order_payment_title', $title, $order, $this->id);
if (strlen($title) >= 127) {
if (function_exists('mb_strcut')) {
$title = mb_strcut($title, 0, 123, 'UTF-8') . '…';
} else {
// 降级方案:使用正则粗略处理 UTF-8 字符
$truncated = preg_replace('/^(.{0,123})[\s\S]*/u', '$1', $title);
$title = $truncated . '…';
}
}
return $title;
}
public static function add_log($log, $type) {
$_dir = _wp_upload_dir();
$folder = apply_filters('wpcom_static_cache_path', 'wpcom');
$dir = $_dir['basedir'] . '/' . $folder;
if (wp_mkdir_p($dir)) {
@file_put_contents($dir . '/payment-' . current_time('Ym') . '.log', '[' . current_time('mysql') . '][' . $type . ']: ' . $log . "\r\n", FILE_APPEND);
}
}
public function is_mobile() {
$ua = isset($_SERVER['HTTP_USER_AGENT']) ? strtolower($_SERVER['HTTP_USER_AGENT']) : '';
if (strpos($ua, 'ipad') || strpos($ua, 'iphone') || strpos($ua, 'android') || strpos($ua, 'mobile')) {
return true;
}
return false;
}
}
class_alias(Payment::class, 'WPCOM_Payment');