1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-05-11 10:46:52 +02:00

优化远程通知功能

This commit is contained in:
云落 2020-03-20 21:22:58 +08:00
parent d57a7d87f9
commit 065e31e070
2 changed files with 6 additions and 159 deletions

View file

@ -1,153 +0,0 @@
setCookie('wp-nocache', 1, 500);
function addcode(a, b) { //ID 提取码
var ajax_data = {
action: 'addcode',
id: a,
code: b,
};
$.post(ajax.url, ajax_data,
function(c) {
if (c == '1') {
swal("输入成功", "您的邮箱提取码是" + b, "success");
localStorage.setItem(a,b);
}
});
}
function checkpayjs(a, b) { //ID订单号
var ajax_data = {
action: 'checkpayjs',
id: a,
orderid: b,
};
$.post(ajax.url, ajax_data,
function(c) {
if (c == '1') {
swal("支付成功!", "为了方便您后续再次查看,建议您输入您的常用邮箱作为提取码", "info", {
dangerMode: true,
closeOnClickOutside: false,
content: "input",
})
.then((d) => {
gdk_getcontent(a);
addcode(a, `${d}`);
}); //ok
} else {
swal("查看失败", "您的支付没有成功,请重试", "error");
}
});
}
function payjs(a, b, c) {
var ajax_data = {
action: 'payjs_view',
id: a,
money: b,
way: c,
};
$.post(ajax.url, ajax_data,
function(d) {
if (d) {
var f = document.createElement("img"),
e = d.split('|'),
g = e[2];
f.id = 'pqrious';
swal("支付金额:" + e[0] + "元", {
content: f,
closeOnClickOutside: false,
button: "支付已完成",
})
.then((value) => {
checkpayjs(a, g);
});
var h = new QRious({
element: document.getElementById("pqrious"),
size: 300,
value: e[1]
});
}
});
}
function payway(a, b) { //id,money
swal("点此开始扫码", "支持支付宝、微信,支付过程中请勿刷新页面!", "warning", {
buttons: ["支付宝", "微信"],
dangerMode: true,
closeOnClickOutside: false,
})
.then((way) => {
if (way) { //微信
payjs(a, b, 0);
} else { //支付宝
payjs(a, b, 1);
}
});
}
function gdk_getcontent(a) {
var ajax_data = {
action: 'gdk_getcontent',
id: a
};
$.post(ajax.url, ajax_data,
function(c) {
if (c) {
$("#hide_notice").hide();
$("#hide_notice").after("<div class='content-hide-tips'><span class='rate label label-warning'>付费内容:</span><p>" + c + "</p></div>");
}
});
}
function checkcode(a, b) {
var ajax_data = {
action: 'gdk_check_code',
id: a,
code: b
};
$.post(ajax.url, ajax_data,
function(c) {
if (c == 1) {
localStorage.setItem('ID:'+a,b);
gdk_getcontent(a);
} else {
swal("Write something here:", {
content: "input",
})
.then((value) => {
swal(`You typed: ${value}`);
});
}
});
}
function pay_view() {
var id = $("#pay_view").data("id"),
money = $("#pay_view").data("money");
swal("查看付费内容", "如未支付,请先支付,如已支付,请点击已支付", "warning", {
buttons: ["扫码支付", "我已支付"],
dangerMode: true,
closeOnClickOutside: false,
})
.then((pay) => {
if (pay) {/* 我已支付*/
var key = localStorage.getItem('ID:'+id);
if(key !== null){
checkcode(id, key);
}else{
swal("请输入您的支付提取码:", {
content: "input",
button: "验证提取码"
})
.then((code) => {
checkcode(id, `${code}`);
});
}
} else {/* 未支付,选择支付方式*/
payway(id, money);
}
});
}

View file

@ -890,16 +890,16 @@ function randomString($length = 11)
return substr(str_shuffle(str_repeat($x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', ceil($length / strlen($x)))), 1, $length);
}
//获取云落的远程通知加入缓存1一次
function gdk_get_Yunluo_Notice()
//获取云落的远程通知加入缓存12小时一次
function gdk_Remote_Notice($url = 'https: //u.gitcafe.net/api/notice.txt', $hours = 12)
{
$Yunluo_Notice = get_transient('Yunluo_Notice');
if (false === $Yunluo_Notice) {
$Yunluo_Notice = wp_remote_get('https://u.gitcafe.net/api/notice.txt')['body'];
if (is_array($Yunluo_Notice) && !is_wp_error($Yunluo_Notice) && $Yunluo_Notice['response']['code'] == '200') {
set_transient('Yunluo_Notice', $Yunluo_Notice, 60 * 60 * 12); //缓存12小时
$response = wp_remote_get($url);
if (is_array($response) && !is_wp_error($response)) {
set_transient('Yunluo_Notice', $response['body'], 60 * 60 * $hours); //缓存12小时
} else {
set_transient('Yunluo_Notice', '有点小尴尬哈啊,服务器菌暂时有点累了呢,先休息一会儿~', 60 * 60 * 2); //缓存2小时
set_transient('Yunluo_Notice', '有点小尴尬哈啊,服务器菌暂时有点累了呢,先休息一会儿~', 60 * 60 * $hours); //缓存12小时
}
}
return $Yunluo_Notice;