1
0
Fork 0
mirror of https://github.com/yunluo/gdk.git synced 2024-05-23 16:42:19 +02:00
gdk/assets/js/pay.js

153 lines
4.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
});
}