diff --git a/assets/assets_load.php b/assets/assets_load.php index 7d69894..ac8e317 100644 --- a/assets/assets_load.php +++ b/assets/assets_load.php @@ -34,6 +34,8 @@ function gdk_enqueue_script_frontend() { 'check_pay_points' => wp_create_nonce('check_pay_points'), 'check_pay_view' => wp_create_nonce('check_pay_view'), 'check_code' => wp_create_nonce('check_code'), + 'gdk_weauth_qr_gen' => wp_create_nonce('gdk_weauth_qr_gen'), + 'gdk_weauth_check' => wp_create_nonce('gdk_weauth_check'), ]); diff --git a/assets/js/gdk.js b/assets/js/gdk.js index 207e6d3..d35f490 100644 --- a/assets/js/gdk.js +++ b/assets/js/gdk.js @@ -114,55 +114,6 @@ function check_pay_points(a, b) { } -/** - * 获取隐藏内容 - * @param {init} a 文章ID - * @param {string} b 提取码 - */ -function getcontent(a,b) { - var ajax_data = { - action: 'getcontent', - id: a - }; - $.post(ajax.url, ajax_data, - function(c) { - if (c) { - show_hide_content('#hide_notice',c); - } - }); -} - -/** */ -/** - * 检查服务器是否有付费可见订单 - * @param {init} a 文章ID - * @param {string} b 订单号 - */ -function check_pay_view(a, b) { - var ajax_data = { - check_pay_view: ajax.check_pay_view, - action: 'check_pay_view', - id: a, - orderid: b - }; - $.post(ajax.url, ajax_data,function(c) { - c = $.trim(c); - if (c == '200') { - swal("支付成功!", "为了方便您后续再次查看,建议您输入您的常用邮箱作为提取码", "info", { - dangerMode: true, - closeOnClickOutside: false, - content: "input", - }) - .then((d) => {/**提取码 */ - getcontent(a, `${d}`); - addcode(a, `${d}`); - }); //ok - } else { - swal("支付失败", "您的支付没有成功,请重试", "error"); - } - }, - 'json'); -} /** @@ -224,14 +175,87 @@ $("#submit_pay").click(function() { } }); -////end +////end//// + + +/** + * 获取隐藏内容 + * @param {init} a 文章ID + */ +function get_content(a) { + var ajax_data = { + action: 'get_content', + id: a + }; + $.post(ajax.url, ajax_data, + function(c) { + c = $.trim(c); + if (c !== '400') { + show_hide_content('#hide_notice',c); + }else{ + show_hide_content('#hide_notice','貌似出了点网络错误,请重试'); + } + }); +} + +/** + * + * @param {init} a 文章ID + * @param {string} b 提取码 + */ +function add_code(a, b) { //ID , 提取码 + var ajax_data = { + action: 'add_code', + id: a, + code: b + }; + $.post(ajax.url, ajax_data, + function(c) { + c = $.trim(c); + if (c == '200') { + swal("输入成功", "您的支付提取码是" + b, "success"); + localStorage.setItem('payjs_view_id:'+a,b); + } + }); +} + +/** + * 检查服务器是否有付费可见订单 + * @param {init} a 文章ID + * @param {string} b 订单号 + */ +function check_pay_view(a, b) { + var ajax_data = { + check_pay_view: ajax.check_pay_view, + action: 'check_pay_view', + id: a, + orderid: b + }; + $.post(ajax.url, ajax_data,function(c) { + c = $.trim(c); + if (c == '200') { + swal("支付成功!", "为了方便您后续再次查看,建议您输入您的常用邮箱作为提取码", "info", { + dangerMode: true, + closeOnClickOutside: false, + content: "input", + }) + .then((d) => {/**提取码 */ + get_content(a); + add_code(a, `${d}`); + }); //ok + } else { + swal("支付失败", "您的支付没有成功,请重试", "error"); + } + }, + 'json'); +} /** * 检验提取码 * @param {init} a 文章ID * @param {string} b 提取码 */ -function checkcode(a, b) { +function check_code(a, b) { var ajax_data = { check_code: ajax.check_code, action: 'check_code', @@ -240,8 +264,9 @@ function checkcode(a, b) { }; $.post(ajax.url, ajax_data, function(c) { - if (c == '1') { - getcontent(a); + c = $.trim(c); + if (c == '200') { + get_content(a); localStorage.setItem('payjs_view_id:'+a,b); } else { swal("查看失败", "服务器不存在此提取码,请重新输入", "error"); @@ -262,14 +287,15 @@ function pay_way(a,b,c) { buttons: ["支付宝", "微信"], dangerMode: true, closeOnClickOutside: false, - }) - .then((way) => { - if (way) { //微信 - get_payjs_qr(b, 'wechat',a,c); - } else { //支付宝 - get_payjs_qr(b, 'alipay',a,c); - } - }); + } + ) + .then((way) => { + if (way) { //微信 + get_payjs_qr(b, 'wechat',a,c); + } else { //支付宝 + get_payjs_qr(b, 'alipay',a,c); + } + }); } @@ -292,7 +318,7 @@ function pay_view(a,b,c){ button: "验证提取码" }) .then((code) => { - checkcode(a, `${code}`);/**文章id, 提取码 */ + check_code(a, `${code}`);/**文章id, 提取码 */ }); } else {/* 未支付,选择支付方式*/ pay_way(a,b,c); @@ -310,7 +336,7 @@ if ( $("#pay_view").length > 0 ) {/**如果网站有付费可见,就执行 */ for (var i = 0; i < length; i++) { var key = localStorage.key(i),value = localStorage.getItem(key); if (key.indexOf(keys) >= 0) {/**发现目标 */ - checkcode(id, value); + check_code(id, value); break; } } @@ -328,6 +354,66 @@ $("#pay_view").click(function() { pay_view(id,money,action); }); +/** + * + * @param {string} a 微信登陆密钥key,此时是 gitcafe.net@wrhGgveq3LCj 类型,实际需要的是@后面的 + */ +function check_weauth_login(a){ + var ajax_data = { + gdk_weauth_check: ajax.gdk_weauth_check, + action: 'gdk_weauth_check', + key: a + }; + $.post(ajax.url, ajax_data, function(b) { + b = $.trim(b);//登陆信息 + if (b !== '400') { + console.log(b); + swal("获取微信信息成功", "您的登陆信息是"+b+"", "success"); + } else { + swal("发生错误", "哦嚯,好像发生了什么错误,微信二维码加载失败", "error"); + } + }); +} + +/** + * 生成微信二维码,公共调用 + * @param {string} a action操作 + */ +function get_weauth_qr(a) { + var ajax_data = { + action: a, + gdk_weauth_qr_gen: ajax.gdk_weauth_qr_gen + }; + $.post(ajax.url, ajax_data, function(b) { + b = $.trim(b);//登陆信息 + if (b !== '400') { + var c = document.createElement("img"), + d = b.split('|');/**使用|风格,分为数组 */ + c.src = d[1];//d[1]=base64 + c.width = "300"; + console.log(d[0]);//d[0]=key + swal("微信扫码并确认登陆", { + content: c, + closeOnClickOutside: true, + buttons: false + }); + console.log('未点击但是我继续执行'); + check_weauth_login(d[0]); + } else { + swal("发生错误", "哦嚯,好像发生了什么错误,微信二维码加载失败", "error"); + } + }); +} + + + + + + +$("#weixin_login_btn").click(function() { + var action = $("#weixin_login_btn").data("action");//gdk_weauth_qr_gen + get_weauth_qr(action); +}); @@ -336,16 +422,5 @@ $("#pay_view").click(function() { - - - - - - - - - - - - +/**jQuery结尾,不要超过此行 */ }); \ No newline at end of file diff --git a/class/aq_resizer.php b/class/aq_resizer.php new file mode 100644 index 0000000..8521360 --- /dev/null +++ b/class/aq_resizer.php @@ -0,0 +1,248 @@ + "$http_prefix", 1 => "$https_prefix"),$relative_prefix,$upload_url); + } + + + // Check if $img_url is local. + if ( false === strpos( $url, $upload_url ) ) + throw new Aq_Exception('Image must be local: ' . $url); + + // Define path of image. + $rel_path = str_replace( $upload_url, '', $url ); + $img_path = $upload_dir . $rel_path; + + // Check if img path exists, and is an image indeed. + if ( ! file_exists( $img_path ) or ! getimagesize( $img_path ) ) + throw new Aq_Exception('Image file does not exist (or is not an image): ' . $img_path); + + // Get image info. + $info = pathinfo( $img_path ); + $ext = $info['extension']; + list( $orig_w, $orig_h ) = getimagesize( $img_path ); + + // Get image size after cropping. + $dims = image_resize_dimensions( $orig_w, $orig_h, $width, $height, $crop ); + $dst_w = $dims[4]; + $dst_h = $dims[5]; + + // Return the original image only if it exactly fits the needed measures. + if ( ! $dims || ( ( ( null === $height && $orig_w == $width ) xor ( null === $width && $orig_h == $height ) ) xor ( $height == $orig_h && $width == $orig_w ) ) ) { + $img_url = $url; + $dst_w = $orig_w; + $dst_h = $orig_h; + } else { + // Use this to check if cropped image already exists, so we can return that instead. + $suffix = "{$dst_w}x{$dst_h}"; + $dst_rel_path = str_replace( '.' . $ext, '', $rel_path ); + $destfilename = "{$upload_dir}{$dst_rel_path}-{$suffix}.{$ext}"; + + if ( ! $dims || ( true == $crop && false == $upscale && ( $dst_w < $width || $dst_h < $height ) ) ) { + // Can't resize, so return false saying that the action to do could not be processed as planned. + throw new Aq_Exception('Unable to resize image because image_resize_dimensions() failed'); + } + // Else check if cache exists. + elseif ( file_exists( $destfilename ) && getimagesize( $destfilename ) ) { + $img_url = "{$upload_url}{$dst_rel_path}-{$suffix}.{$ext}"; + } + // Else, we resize the image and return the new resized image url. + else { + + $editor = wp_get_image_editor( $img_path ); + + if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) { + throw new Aq_Exception('Unable to get WP_Image_Editor: ' . + $editor->get_error_message() . ' (is GD or ImageMagick installed?)'); + } + + $resized_file = $editor->save(); + + if ( ! is_wp_error( $resized_file ) ) { + $resized_rel_path = str_replace( $upload_dir, '', $resized_file['path'] ); + $img_url = $upload_url . $resized_rel_path; + } else { + throw new Aq_Exception('Unable to save resized image file: ' . $editor->get_error_message()); + } + + } + } + + // Okay, leave the ship. + if ( true === $upscale ) remove_filter( 'image_resize_dimensions', array( $this, 'aq_upscale' ) ); + + // Return the output. + if ( $single ) { + // str return. + $image = $img_url; + } else { + // array return. + $image = array ( + 0 => $img_url, + 1 => $dst_w, + 2 => $dst_h + ); + } + + return $image; + } + catch (Aq_Exception $ex) { + error_log('Aq_Resize.process() error: ' . $ex->getMessage()); + + if ($this->throwOnError) { + // Bubble up exception. + throw $ex; + } + else { + // Return false, so that this patch is backwards-compatible. + return false; + } + } + } + + /** + * Callback to overwrite WP computing of thumbnail measures + */ + function aq_upscale( $default, $orig_w, $orig_h, $dest_w, $dest_h, $crop ) { + if ( ! $crop ) return null; // Let the wordpress default function handle this. + + // Here is the point we allow to use larger image size than the original one. + $aspect_ratio = $orig_w / $orig_h; + $new_w = $dest_w; + $new_h = $dest_h; + + if ( ! $new_w ) { + $new_w = intval( $new_h * $aspect_ratio ); + } + + if ( ! $new_h ) { + $new_h = intval( $new_w / $aspect_ratio ); + } + + $size_ratio = max( $new_w / $orig_w, $new_h / $orig_h ); + + $crop_w = round( $new_w / $size_ratio ); + $crop_h = round( $new_h / $size_ratio ); + + $s_x = floor( ( $orig_w - $crop_w ) / 2 ); + $s_y = floor( ( $orig_h - $crop_h ) / 2 ); + + return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h ); + } + } +} + + + + + +if(!function_exists('aq_resize')) { + + /** + * This is just a tiny wrapper function for the class above so that there is no + * need to change any code in your own WP themes. Usage is still the same :) + */ + function aq_resize( $url, $width = null, $height = null, $crop = null, $single = true, $upscale = false ) { + /* WPML Fix */ + if ( defined( 'ICL_SITEPRESS_VERSION' ) ){ + global $sitepress; + $url = $sitepress->convert_url( $url, $sitepress->get_default_language() ); + } + /* WPML Fix */ + + $aq_resize = Aq_Resize::getInstance(); + return $aq_resize->process( $url, $width, $height, $crop, $single, $upscale ); + } +} + + diff --git a/functions/Ajax.php b/functions/Ajax.php index 9c07245..6066b17 100644 --- a/functions/Ajax.php +++ b/functions/Ajax.php @@ -87,7 +87,7 @@ add_action('wp_ajax_gdk_pass_view', 'gdk_pass_view'); -//在线积分充值 +//在线积分充值开始 function pay_points() { if( !isset( $_POST['action'] ) || $_POST['action'] !== 'pay_points' ) exit('400'); if (!isset($_POST['money']) || !isset($_POST['way'])) exit('400');//无脑输出400错误 @@ -113,9 +113,9 @@ function check_pay_points(){ add_action( 'wp_ajax_check_pay_points', 'check_pay_points' ); add_action( 'wp_ajax_nopriv_check_pay_points', 'check_pay_points' ); -//积分充值end +//积分充值结束 -//游客付费可见 +//游客付费可见开始 function pay_view() { if( !isset( $_POST['action'] ) || $_POST['action'] !== 'pay_view' ) exit('400'); if (!isset($_POST['money']) || !isset($_POST['way'])) exit('400');//无脑输出400错误 @@ -126,12 +126,64 @@ function pay_view() { add_action( 'wp_ajax_pay_view', 'pay_view' ); add_action( 'wp_ajax_nopriv_pay_view', 'pay_view' ); +//添加提取码 +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' ); //检查付费可见订单 function check_pay_view() { if( !isset( $_POST['check_pay_view'] ) || !wp_verify_nonce($_POST['check_pay_view'], 'check_pay_view') ) exit('400'); - if (!isset($_POST['id']) || !isset($_POST['orderid'])) exit('400'); - //无脑输出400错误 + if (!isset($_POST['id']) || !isset($_POST['orderid'])) exit('400');//无脑输出400错误 if ( $_POST['action'] == 'check_pay_view') { $sid = get_transient('PP'.$_POST['id']); if(in_string($sid,'E20') && $orderid == $sid) { @@ -143,4 +195,33 @@ function check_pay_view() { } add_action( 'wp_ajax_check_pay_view', 'check_pay_view' ); add_action( 'wp_ajax_nopriv_check_pay_view', 'check_pay_view' ); + /**END */ + +//开始微信登陆 +//ajax生成登录二维码 +function gdk_weauth_qr_gen() { + if( !isset( $_POST['gdk_weauth_qr_gen'] ) || !wp_verify_nonce($_POST['gdk_weauth_qr_gen'], 'gdk_weauth_qr_gen') ) exit('400'); + if (isset($_POST['action']) && $_POST['action'] == 'gdk_weauth_qr_gen') { + $rest = implode("|", gdk_weauth_qr()); + 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' ); + +//检查登录状况 +function gdk_weauth_check(){ + if( !isset( $_POST['gdk_weauth_check'] ) || !wp_verify_nonce($_POST['gdk_weauth_check'], 'gdk_weauth_check') ) exit('400'); + if (isset($_POST['key']) && !in_string($_POST['key'],'@') && $_POST['action'] == 'gdk_weauth_check') exit('400'); + $sk = substr($_POST['key'],-12);//sk + $oauth_result = get_transient($sk); + if (!empty($oauth_result)) { + exit($oauth_result);//用户信息 + } + +} +add_action( 'wp_ajax_gdk_weauth_check', 'gdk_weauth_check' ); +add_action( 'wp_ajax_nopriv_gdk_weauth_check', 'gdk_weauth_check' ); \ No newline at end of file diff --git a/functions/Common.php b/functions/Common.php index 4bbf101..93f9594 100644 --- a/functions/Common.php +++ b/functions/Common.php @@ -1085,6 +1085,7 @@ function payjs_notify() { } } + //充值按钮 function buy_points(){ if(is_user_logged_in()) {//logined @@ -1108,16 +1109,78 @@ function buy_points(){

'; - //wp_enqueue_script('qrious', 'https://cdn.bootcss.com/qrious/4.0.2/qrious.min.js', array('jquery'), GDK_PLUGIN_VER, true); - }else{// no login $result = '
本页面需要您登录才可以操作,请先 点击登录 或者立即注册
'; } + return $result; +} - - +function login_modal(){ + $result = '登录 + '; return $result; + +} -} \ No newline at end of file +/**开始微信* */ +//生成随机字符 +//sk是12位随机字符, key是域名@sk +function gdk_weauth_token(){ + $strs = 'QWERTYUIOPASDFGHJKLZXCVBNM1234567890qwertyuiopasdfghjklzxcvbnm'; + $sk = substr(str_shuffle($strs),mt_rand(0,strlen($strs)-11),12);//12位 + set_transient($sk, 1, 60*6);//缓存 get_transient($sk) == 1 + $key = $_SERVER['HTTP_HOST'].'@'.$sk; + return $key; + } + + function gdk_weauth_qr(){ + $qr64 = []; + $qr64['key'] = gdk_weauth_token(); + $qr64['qrcode'] = gdk_http_request('https://wa.isdot.net/qrcode?str='.$qr64['key'])['qrcode']; + return $qr64; + } + + function weauth_rewrite_rules($wp_rewrite){ + if (get_option('permalink_structure')) { + $new_rules['^weauth'] = 'index.php?user=$matches[1]&sk=$matches[2]'; + $wp_rewrite->rules = $new_rules + $wp_rewrite->rules; + } + } + add_action('generate_rewrite_rules', 'weauth_rewrite_rules'); + +/** + * 微信登陆按钮 + */ +function weixin_login_btn(){ + $result = '微信登陆'; + return $result; +} + + +function get_weauth_oauth(){ + if(in_string($_SERVER['REQUEST_URI'],'weauth')){ + $weauth_user = trim($_GET['user']);//weauth发来用户信息 + $weauth_sk = trim($_GET['sk']);//weauth返回的12位sk信息 + $weauth_res = get_transient($weauth_sk); + if (empty($weauth_res)) return; + + $weauth_user = stripslashes($weauth_user); + $weauth_user = json_decode($weauth_user, true); + //$weauth_info['nickname'] = $weauth_user['nickName'];//微信昵称 + //$weauth_info['wxavatar'] = $weauth_user['avatarUrl'];//微信头像 + //$weauth_info['openid'] = $weauth_user['openid'];//微信Openid + $oauth_result = implode('|',$weauth_user); + set_transient($sk, $oauth_result, 60*6); + echo 'success'; +} +} + +add_action('wp','get_weauth_oauth'); \ No newline at end of file diff --git a/functions/shortcode.php b/functions/shortcode.php index 7ab8b86..09b67b0 100644 --- a/functions/shortcode.php +++ b/functions/shortcode.php @@ -12,6 +12,13 @@ function gdk_potin() { } add_shortcode('gdk_potin_btn', 'gdk_potin'); + +// +function gdk_login_fancybox() { + return weixin_login_btn(); +} +add_shortcode('gdk_login_btn', 'gdk_login_fancybox'); + //添加钮Download function gdk_DownloadUrl($atts, $content = null) { extract(shortcode_atts(array(