2020-01-27 15:28:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2020-01-29 04:41:36 +01:00
|
|
|
*Ajax操作文件
|
2020-01-27 15:28:34 +01:00
|
|
|
*/
|
|
|
|
|
2020-02-05 19:44:30 +01:00
|
|
|
/**
|
|
|
|
* 200 ok
|
|
|
|
* 400 fail
|
|
|
|
*/
|
|
|
|
|
|
|
|
//后台邮箱检测
|
2020-01-27 19:03:14 +01:00
|
|
|
function gdk_test_email() {
|
2020-01-27 15:28:34 +01:00
|
|
|
$is_error = !wp_mail('donotreply@mywpku.com', '测试发信', 'WP 积木测试发信');
|
|
|
|
if ($is_error) {
|
2020-02-05 19:44:30 +01:00
|
|
|
exit('500');
|
2020-01-27 15:28:34 +01:00
|
|
|
}else{
|
2020-02-05 19:44:30 +01:00
|
|
|
exit('200');
|
2020-01-27 15:28:34 +01:00
|
|
|
}
|
|
|
|
}
|
2020-01-27 19:03:14 +01:00
|
|
|
add_action('wp_ajax_nopriv_gdk_test_email', 'gdk_test_email');
|
|
|
|
add_action('wp_ajax_gdk_test_email', 'gdk_test_email');
|
|
|
|
|
|
|
|
|
2020-01-30 09:47:37 +01:00
|
|
|
//粘贴上传图片
|
|
|
|
function gdk_pasteup_imag() {
|
2020-02-05 19:44:30 +01:00
|
|
|
if( !isset( $_POST['pui_nonce'] ) || !wp_verify_nonce($_POST['pui_nonce'], 'pui-nonce') ) exit('400');
|
2020-01-30 09:47:37 +01:00
|
|
|
if($_FILES) {
|
|
|
|
global $post;
|
|
|
|
$post_ID = $post->ID;
|
|
|
|
$wp_upload_dir = wp_upload_dir();
|
2020-02-06 11:51:43 +01:00
|
|
|
$file = $_FILES['imageFile'];
|
|
|
|
$result=array ('success'=>false,'message'=>'Null');
|
|
|
|
if (in_array($file['type'],array ('image/gif','image/jpeg','image/pjpeg','image/png'))) {
|
|
|
|
if ($file['error']>0) {
|
|
|
|
$result['message']='error';
|
2020-01-30 09:47:37 +01:00
|
|
|
} else {
|
2020-02-06 11:51:43 +01:00
|
|
|
$file_name = md5_file($file['tmp_name']).str_replace('image/','.',$file['type']);//img name
|
|
|
|
$file_url = $wp_upload_dir['url'].'/'.$file_name;
|
|
|
|
$file_path = $wp_upload_dir['path'].'/'.$file_name;
|
2020-01-30 09:47:37 +01:00
|
|
|
if (!file_exists($file_path)) {
|
2020-02-06 11:51:43 +01:00
|
|
|
move_uploaded_file($file['tmp_name'],$file_path);
|
2020-01-30 09:47:37 +01:00
|
|
|
$attachment = [
|
2020-01-30 17:45:05 +01:00
|
|
|
'guid' => $wp_upload_dir['url'] . '/' . basename( $file_path ),
|
|
|
|
'post_mime_type' => $file['type'],
|
|
|
|
'post_title' => $file_name,
|
|
|
|
'post_content' => '',
|
|
|
|
'post_status' => 'inherit'
|
|
|
|
];
|
2020-01-30 09:47:37 +01:00
|
|
|
$attach_id = wp_insert_attachment( $attachment, $file_name, $post_ID);
|
|
|
|
//这是wp内置的上传附件的函数
|
|
|
|
require_once( ABSPATH . 'wp-admin/includes/image.php' );
|
|
|
|
$attach_data = wp_generate_attachment_metadata( $attach_id, $file_path );
|
|
|
|
wp_update_attachment_metadata( $attach_id, $attach_data );
|
|
|
|
}
|
2020-02-05 19:44:30 +01:00
|
|
|
$result['success'] = true;
|
|
|
|
$result['message'] = $file_url;
|
2020-01-30 09:47:37 +01:00
|
|
|
}
|
|
|
|
} else {
|
2020-02-06 11:51:43 +01:00
|
|
|
$result['message'] = '400';
|
2020-01-30 09:47:37 +01:00
|
|
|
}
|
|
|
|
echo(json_encode($result));
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action('wp_ajax_nopriv_gdk_pasteup_imag', 'gdk_pasteup_imag');
|
2020-02-03 19:12:24 +01:00
|
|
|
add_action('wp_ajax_gdk_pasteup_imag', 'gdk_pasteup_imag');
|
|
|
|
|
2020-02-05 19:44:30 +01:00
|
|
|
//密码可见
|
2020-02-03 19:12:24 +01:00
|
|
|
function gdk_pass_view() {
|
2020-02-05 19:44:30 +01:00
|
|
|
if( !isset( $_POST['pass_nonce'] ) || !wp_verify_nonce($_POST['pass_nonce'], 'pass_nonce') ) exit('400');
|
2020-02-03 19:12:24 +01:00
|
|
|
$action = $_POST['action'];
|
|
|
|
$post_id = $_POST['id'];
|
|
|
|
$pass = $_POST['pass'];
|
2020-02-15 12:37:30 +01:00
|
|
|
$wxcaptcha = wx_captcha();
|
2020-02-05 19:44:30 +01:00
|
|
|
if(!isset( $action ) || !isset( $post_id ) || !isset( $pass ) ) exit('400');
|
2020-02-15 12:37:30 +01:00
|
|
|
if($pass == $wxcaptcha ) {
|
2020-02-03 19:12:24 +01:00
|
|
|
$pass_content = get_post_meta($post_id, '_pass_content')[0];
|
|
|
|
exit($pass_content);
|
|
|
|
}else{
|
2020-02-05 19:44:30 +01:00
|
|
|
exit('400');
|
2020-02-03 19:12:24 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action('wp_ajax_nopriv_gdk_pass_view', 'gdk_pass_view');
|
2020-02-04 18:14:04 +01:00
|
|
|
add_action('wp_ajax_gdk_pass_view', 'gdk_pass_view');
|
|
|
|
|
2020-02-06 11:51:43 +01:00
|
|
|
//密码可见end
|
2020-02-05 19:44:30 +01:00
|
|
|
|
2020-02-06 11:51:43 +01:00
|
|
|
|
|
|
|
|
2020-02-07 16:57:46 +01:00
|
|
|
//在线积分充值开始
|
2020-02-05 19:44:30 +01:00
|
|
|
function pay_points() {
|
2020-02-06 19:54:19 +01:00
|
|
|
if( !isset( $_POST['action'] ) || $_POST['action'] !== 'pay_points' ) exit('400');
|
2020-02-06 11:51:43 +01:00
|
|
|
if (!isset($_POST['money']) || !isset($_POST['way'])) exit('400');//无脑输出400错误
|
|
|
|
if (isset($_POST['id'])) {
|
|
|
|
payjs_action('积分充值',$_POST['id']);
|
2020-02-05 19:44:30 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_pay_points', 'pay_points' );
|
|
|
|
add_action( 'wp_ajax_nopriv_pay_points', 'pay_points' );
|
|
|
|
|
2020-02-06 11:51:43 +01:00
|
|
|
//检查积分充值
|
|
|
|
function check_pay_points(){
|
|
|
|
if( !isset( $_POST['check_pay_points'] ) || !wp_verify_nonce($_POST['check_pay_points'], 'check_pay_points') ) exit('400');
|
|
|
|
if (!isset($_POST['id']) || !isset($_POST['orderid'])) exit('400');//无脑输出400错误
|
|
|
|
if ( $_POST['action'] == 'check_pay_points') {
|
|
|
|
if(gdk_check( $_POST['orderid'] , $_POST['id'])){
|
|
|
|
exit('200');
|
|
|
|
}else{
|
|
|
|
exit('400');
|
2020-02-04 18:14:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-02-06 11:51:43 +01:00
|
|
|
add_action( 'wp_ajax_check_pay_points', 'check_pay_points' );
|
|
|
|
add_action( 'wp_ajax_nopriv_check_pay_points', 'check_pay_points' );
|
2020-02-04 18:14:04 +01:00
|
|
|
|
2020-02-07 16:57:46 +01:00
|
|
|
//积分充值结束
|
2020-02-04 18:14:04 +01:00
|
|
|
|
2020-02-07 16:57:46 +01:00
|
|
|
//游客付费可见开始
|
2020-02-06 19:54:19 +01:00
|
|
|
function pay_view() {
|
|
|
|
if( !isset( $_POST['action'] ) || $_POST['action'] !== 'pay_view' ) exit('400');
|
|
|
|
if (!isset($_POST['money']) || !isset($_POST['way'])) exit('400');//无脑输出400错误
|
|
|
|
if (isset($_POST['id'])) {
|
|
|
|
payjs_action('在线付费查看',$_POST['id']);//标题,文章id
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_pay_view', 'pay_view' );
|
|
|
|
add_action( 'wp_ajax_nopriv_pay_view', 'pay_view' );
|
2020-02-05 19:44:30 +01:00
|
|
|
|
2020-02-07 16:57:46 +01:00
|
|
|
//添加提取码
|
|
|
|
function add_code() {
|
|
|
|
$id = $_POST['id'];
|
|
|
|
$code = $_POST['code'];
|
|
|
|
if(empty($id) || empty($code)) exit('400');
|
|
|
|
if ( $_POST['action'] == 'add_code') {
|
|
|
|
$code = trim($code);//清理一下
|
|
|
|
$pay_log = get_post_meta($id, 'pay_log', true);//获取旧的购买记录数据
|
|
|
|
add_post_meta($id, 'pay_log', $code, true) or update_post_meta($id, 'pay_log', $pay_log.','.$code);//没有新建,有就更新
|
|
|
|
$pay_log = get_post_meta($id, 'pay_log', true);//获取新的购买记录数据
|
|
|
|
$pay_arr = explode(",", $pay_log);
|
|
|
|
if(in_array($code,$pay_arr)) {
|
|
|
|
exit('200');//OK
|
|
|
|
}else{
|
|
|
|
exit('400');//NO
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_add_code', 'add_code' );
|
|
|
|
add_action( 'wp_ajax_nopriv_add_code', 'add_code' );
|
|
|
|
|
|
|
|
//检测提取码
|
|
|
|
function check_code() {
|
|
|
|
$check_code_nonce = $_POST['check_code'];
|
|
|
|
$code = $_POST['code'];
|
|
|
|
$action = $_POST['action'];
|
|
|
|
$id = $_POST['id'];
|
|
|
|
if( !isset( $check_code_nonce ) || !wp_verify_nonce($check_code_nonce, 'check_code') ) exit('400');
|
|
|
|
if (!isset($code) || !isset($action) || !isset($id)) exit('400');//无脑输出400错误
|
|
|
|
if ( $action == 'check_code') {
|
|
|
|
$code = trim($code);//清理一下
|
|
|
|
$pay_log = get_post_meta($id, 'pay_log', true);//购买记录数据
|
|
|
|
$pay_arr = explode(",", $pay_log);
|
|
|
|
if(in_array($code,$pay_arr)) {
|
|
|
|
exit('200');
|
|
|
|
} else {
|
|
|
|
exit('400');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_check_code', 'check_code' );
|
|
|
|
add_action( 'wp_ajax_nopriv_check_code', 'check_code' );
|
|
|
|
|
|
|
|
//获取加密内容
|
|
|
|
function get_content(){
|
|
|
|
if ( !isset($_POST['action']) || $_POST['action'] !== 'get_content') exit('400');//无脑输出400错误
|
|
|
|
if ( isset($_POST['id'])) {
|
|
|
|
$pay_content = get_post_meta($_POST['id'], '_pay_content', true);
|
|
|
|
exit($pay_content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_get_content', 'get_content' );
|
|
|
|
add_action( 'wp_ajax_nopriv_get_content', 'get_content' );
|
2020-02-05 19:44:30 +01:00
|
|
|
|
2020-02-06 19:54:19 +01:00
|
|
|
//检查付费可见订单
|
|
|
|
function check_pay_view() {
|
|
|
|
if( !isset( $_POST['check_pay_view'] ) || !wp_verify_nonce($_POST['check_pay_view'], 'check_pay_view') ) exit('400');
|
2020-02-07 16:57:46 +01:00
|
|
|
if (!isset($_POST['id']) || !isset($_POST['orderid'])) exit('400');//无脑输出400错误
|
2020-02-06 19:54:19 +01:00
|
|
|
if ( $_POST['action'] == 'check_pay_view') {
|
|
|
|
$sid = get_transient('PP'.$_POST['id']);
|
|
|
|
if(in_string($sid,'E20') && $orderid == $sid) {
|
|
|
|
exit('200');//OK
|
|
|
|
} else {
|
|
|
|
exit('400');//no
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_check_pay_view', 'check_pay_view' );
|
|
|
|
add_action( 'wp_ajax_nopriv_check_pay_view', 'check_pay_view' );
|
2020-02-07 16:57:46 +01:00
|
|
|
|
2020-02-06 11:51:43 +01:00
|
|
|
/**END */
|
2020-02-07 16:57:46 +01:00
|
|
|
|
|
|
|
//开始微信登陆
|
|
|
|
//ajax生成登录二维码
|
|
|
|
function gdk_weauth_qr_gen() {
|
|
|
|
if (isset($_POST['action']) && $_POST['action'] == 'gdk_weauth_qr_gen') {
|
2020-02-08 17:48:45 +01:00
|
|
|
$rest = implode('|', gdk_weauth_qr());
|
2020-02-07 16:57:46 +01:00
|
|
|
exit($rest);
|
|
|
|
} else {
|
|
|
|
exit('400');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_gdk_weauth_qr_gen', 'gdk_weauth_qr_gen' );
|
|
|
|
add_action( 'wp_ajax_nopriv_gdk_weauth_qr_gen', 'gdk_weauth_qr_gen' );
|
|
|
|
|
2020-02-08 17:48:45 +01:00
|
|
|
|
2020-02-08 18:32:22 +01:00
|
|
|
//检查微信登录状况
|
2020-02-08 17:48:45 +01:00
|
|
|
function gdk_weauth_check(){
|
|
|
|
if( !isset($_POST['key']) || !isset( $_POST['gdk_weauth_check'] ) || !wp_verify_nonce($_POST['gdk_weauth_check'], 'gdk_weauth_check') ) exit('400');
|
|
|
|
if (!in_string($_POST['key'],'@') || $_POST['action'] !== 'gdk_weauth_check') exit('400');
|
|
|
|
$sk = substr(trim($_POST['key']),-12);//sk
|
|
|
|
$user_info = get_transient($sk.'-info');//user_info
|
|
|
|
if (!empty($user_info)) {
|
|
|
|
exit($user_info);//user_info
|
|
|
|
}
|
2020-02-07 16:57:46 +01:00
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_gdk_weauth_check', 'gdk_weauth_check' );
|
2020-02-08 17:48:45 +01:00
|
|
|
add_action( 'wp_ajax_nopriv_gdk_weauth_check', 'gdk_weauth_check' );
|
|
|
|
|
2020-02-08 18:32:22 +01:00
|
|
|
//开始自动登陆
|
2020-02-08 17:48:45 +01:00
|
|
|
function gdk_auto_login(){
|
|
|
|
if (!isset($_POST['data']) || $_POST['action'] !== 'gdk_auto_login') exit('400');
|
2020-02-08 19:19:32 +01:00
|
|
|
$mail = $_POST['email'] ?? '';
|
2020-02-08 17:48:45 +01:00
|
|
|
$userdata = gdk_str2arr($_POST['data'],'|');
|
|
|
|
$user_id = create_user_id($userdata);
|
|
|
|
if(is_numeric($user_id) && $user_id){
|
|
|
|
$user = get_user_by('id', $user_id );
|
|
|
|
wp_set_current_user( $user_id , $user->user_login);
|
|
|
|
wp_set_auth_cookie( $user_id ,true);
|
|
|
|
do_action( 'wp_login', $user->user_login );
|
2020-02-08 19:19:32 +01:00
|
|
|
if($mail && !empty($mail) && is_email($mail)){
|
|
|
|
wp_update_user( array( 'ID' => $user_id, 'user_email' => $mail ) );//绑定邮箱
|
|
|
|
}
|
2020-02-08 17:48:45 +01:00
|
|
|
exit('200');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_gdk_auto_login', 'gdk_auto_login' );
|
|
|
|
add_action( 'wp_ajax_nopriv_gdk_auto_login', 'gdk_auto_login' );
|
|
|
|
|
|
|
|
//邮箱绑定
|
|
|
|
function bind_email_check(){
|
|
|
|
$mail = isset($_POST['email']) ? $_POST['email'] : false;
|
|
|
|
if($mail && $_POST['action'] == 'bind_email_check'){
|
|
|
|
$user_id = email_exists( $email );
|
|
|
|
if ($user_id) {
|
|
|
|
exit('200');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
add_action( 'wp_ajax_bind_email_check', 'bind_email_check' );
|
|
|
|
add_action( 'wp_ajax_nopriv_bind_email_check', 'bind_email_check' );
|
|
|
|
|