mirror of
https://github.com/yunluo/gdk.git
synced 2024-05-04 23:43:23 +02:00
优化代码
This commit is contained in:
parent
be86126aa6
commit
24ab10892e
|
@ -21,13 +21,13 @@ function gdk_enqueue_script_frontend()
|
|||
wp_enqueue_style('gdk_css', GDK_BASE_URL . 'assets/css/gdk.css', false, GDK_PLUGIN_VER, 'all');
|
||||
wp_deregister_script('jquery');
|
||||
wp_enqueue_script('jquery', 'https://cdn.jsdelivr.net/npm/jquery@2.1.0/dist/jquery.min.js', false, GDK_PLUGIN_VER, true); //加载自定义jQuery2.0.3
|
||||
wp_enqueue_script('code_prettify_js', GDK_BASE_URL . 'assets/js/prettify.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('fancybox_js', GDK_BASE_URL . 'assets/js/fancybox.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('lazyload_js', GDK_BASE_URL . 'assets/js/lazyload.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('sweetalert_js', 'https://cdn.jsdelivr.net/combine/npm/sweetalert@2.0.0,npm/qrious@4.0.2', [], GDK_PLUGIN_VER, true);
|
||||
//wp_enqueue_script('code_prettify_js', GDK_BASE_URL . 'assets/js/prettify.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
//wp_enqueue_script('fancybox_js', GDK_BASE_URL . 'assets/js/fancybox.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('libs_js', GDK_BASE_URL . 'assets/js/libs.min.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
//wp_enqueue_script('sweetalert_js', 'https://cdn.jsdelivr.net/combine/npm/sweetalert@2.0.0,npm/qrious@4.0.2', [], GDK_PLUGIN_VER, true);
|
||||
wp_enqueue_script('gdk_js', GDK_BASE_URL . 'assets/js/gdk.js', array('jquery'), GDK_PLUGIN_VER, true);
|
||||
wp_localize_script('gdk_js', 'ajax', [
|
||||
'url' => admin_url('admin-ajax.php'),
|
||||
wp_localize_script('gdk_js', 'gdk', [
|
||||
'ajaxurl' => admin_url('admin-ajax.php'),
|
||||
'pass_nonce' => wp_create_nonce('pass_nonce'),
|
||||
'pay_points' => wp_create_nonce('pay_points'),
|
||||
'check_pay_points' => wp_create_nonce('check_pay_points'),
|
||||
|
@ -35,6 +35,7 @@ function gdk_enqueue_script_frontend()
|
|||
'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'),
|
||||
'gdk_payjs_alipay' => gdk_option('gdk_payjs_alipay'),
|
||||
'user_id' => get_current_user_id(),
|
||||
]);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,13 @@
|
|||
jQuery(function ($) { /**声明加载jQuery */
|
||||
|
||||
$(".fancybox").fancybox();/**启动fancybox */
|
||||
$("img").lazyload({ effect: "fadeIn", threshold: 180 });/**图片懒加载 */
|
||||
window.prettyPrint && prettyPrint();/**加载代码高亮 */
|
||||
|
||||
/**
|
||||
*
|
||||
* @param {string} a 日志内容
|
||||
*/
|
||||
function glog(a) {
|
||||
console.log(a);
|
||||
}
|
||||
|
@ -69,11 +77,11 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
$("#submit_pass_view").click(function () {
|
||||
var ajax_data = {
|
||||
action: $('#submit_pass_view').data('action'),
|
||||
pass_nonce: ajax.pass_nonce,
|
||||
pass_nonce: gdk.pass_nonce,
|
||||
id: $('#submit_pass_view').data('id'),
|
||||
pass: $('#pass_view').val()
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (c) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (c) {
|
||||
c = $.trim(c); /**Ajax返回有空行,这里处理一下.妈的花了老子3个小时 */
|
||||
if (c !== '400') {
|
||||
show_hide_content('.pass_viewbox', c);
|
||||
|
@ -153,12 +161,12 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
|
||||
function check_pay_points(a, b) {
|
||||
var ajax_data = {
|
||||
check_pay_points: ajax.check_pay_points,
|
||||
check_pay_points: gdk.check_pay_points,
|
||||
action: 'check_pay_points',
|
||||
id: a,
|
||||
orderid: b
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (c) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (c) {
|
||||
c = $.trim(c);
|
||||
if (c == '200') {
|
||||
swal("支付成功!", "为支付详情已发送到您的邮箱", "success"); //ok
|
||||
|
@ -186,7 +194,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
way: b,
|
||||
id: c
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (e) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (e) {
|
||||
e = $.trim(e);
|
||||
if (e !== '400') {
|
||||
var g = document.createElement("img"),
|
||||
|
@ -244,7 +252,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
action: 'get_content',
|
||||
id: a
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (c) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (c) {
|
||||
c = $.trim(c);
|
||||
if (c !== '400') {
|
||||
show_hide_content('#hide_notice', c);
|
||||
|
@ -266,7 +274,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
id: a,
|
||||
code: b
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (c) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (c) {
|
||||
c = $.trim(c);
|
||||
if (c == '200') {
|
||||
swal("输入成功", "您的支付提取码是" + b, "success");
|
||||
|
@ -283,12 +291,12 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
|
||||
function check_pay_view(a, b) {
|
||||
var ajax_data = {
|
||||
check_pay_view: ajax.check_pay_view,
|
||||
check_pay_view: gdk.check_pay_view,
|
||||
action: 'check_pay_view',
|
||||
id: a,
|
||||
orderid: b
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (c) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (c) {
|
||||
c = $.trim(c);
|
||||
if (c == '200') {
|
||||
swal("支付成功!", "为了方便您后续再次查看,建议您输入您的常用邮箱作为提取码", "info", {
|
||||
|
@ -314,12 +322,12 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
|
||||
function check_code(a, b) {
|
||||
var ajax_data = {
|
||||
check_code: ajax.check_code,
|
||||
check_code: gdk.check_code,
|
||||
action: 'check_code',
|
||||
id: a,
|
||||
code: b
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (c) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (c) {
|
||||
c = $.trim(c);
|
||||
if (c == '200') {
|
||||
get_content(a);
|
||||
|
@ -426,7 +434,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
data: a,
|
||||
email: c
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (b) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (b) {
|
||||
b = $.trim(b); //登陆信息
|
||||
if (b !== '400' && b == '200') {
|
||||
window.location.reload();
|
||||
|
@ -455,7 +463,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
action: 'bind_email_check',
|
||||
email: `${value}`
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (b) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (b) {
|
||||
b = $.trim(b);
|
||||
if (b == '200') {//邮箱已存在
|
||||
swal("邮箱绑定错误", "您输入的邮箱已被绑定,请更换邮箱或者联系管理员,谢谢", { icon: "error", dangerMode: true });
|
||||
|
@ -482,11 +490,11 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
*/
|
||||
function check_weauth_login() {
|
||||
var ajax_data = {
|
||||
gdk_weauth_check: ajax.gdk_weauth_check,
|
||||
gdk_weauth_check: gdk.gdk_weauth_check,
|
||||
action: 'gdk_weauth_check',
|
||||
key: $('#weauth_key').text()
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (b) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (b) {
|
||||
b = $.trim(b); //登陆||信息
|
||||
if (b.length > 100) {
|
||||
swal("微信登录成功!", "跳转刷新中!", "success", {
|
||||
|
@ -509,7 +517,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
var ajax_data = {
|
||||
action: a
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (b) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (b) {
|
||||
b = $.trim(b); //登陆信息
|
||||
if (b !== '400') {
|
||||
var c = document.createElement("img"),
|
||||
|
@ -558,7 +566,7 @@ jQuery(function ($) { /**声明加载jQuery */
|
|||
point: $("#pay_points").data("point")
|
||||
|
||||
};
|
||||
$.post(ajax.url, ajax_data, function (b) {
|
||||
$.post(gdk.ajaxurl, ajax_data, function (b) {
|
||||
b = $.trim(b);
|
||||
if ('' !== b) {
|
||||
show_hide_content('#hide_notice', b);
|
||||
|
|
38
assets/js/libs.min.js
vendored
Normal file
38
assets/js/libs.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
180
class/wechat.php
180
class/wechat.php
|
@ -1,65 +1,25 @@
|
|||
<?php
|
||||
//error_reporting(0);
|
||||
|
||||
/**
|
||||
* 微信(或易信)公共平台处理类
|
||||
*
|
||||
* 用于创建微信(或易信)公共平台服务
|
||||
*
|
||||
* @author: Specs
|
||||
* Email: specs@9iphp.com
|
||||
* Blog: http://www.9iphp.com
|
||||
*/
|
||||
class WeChat
|
||||
class Wechat_Captcha
|
||||
{
|
||||
|
||||
private $__token = ""; //TOKEN值
|
||||
private $__callback_function = null; //回调函数名称
|
||||
|
||||
public $fromUser = ""; //当前消息的发送者
|
||||
public $toUser = ""; //当前消息的接收者
|
||||
|
||||
/**
|
||||
* 构造函数
|
||||
*
|
||||
* @param string $token 设置在公共平台的TOKEN值
|
||||
* @param callable $callback_function_name 回调函数名称
|
||||
*/
|
||||
public function __construct($token, $callback_function_name)
|
||||
public function __construct($wx_token, $wx_captcha)
|
||||
{
|
||||
$this->token = $token;
|
||||
$this->callback_function = $callback_function_name;
|
||||
$this->token = $wx_token;
|
||||
$this->captcha = $wx_captcha;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查签名是否正确
|
||||
*
|
||||
* @return boolean 正确返回true,否则返回false
|
||||
*/
|
||||
private function __checkSignature()
|
||||
{
|
||||
$signature = $_GET["signature"];
|
||||
$timestamp = $_GET["timestamp"];
|
||||
$nonce = $_GET["nonce"];
|
||||
|
||||
$token = $this->token;
|
||||
|
||||
$tmpArr = array($token, $timestamp, $nonce);
|
||||
$token = $this->token;
|
||||
$tmpArr = array($token, $timestamp, $nonce);
|
||||
sort($tmpArr, SORT_STRING);
|
||||
$tmpStr = implode($tmpArr);
|
||||
$tmpStr = sha1($tmpStr);
|
||||
|
||||
if ($tmpStr == $signature) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $tmpStr == $signature ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证签名是否有效
|
||||
*/
|
||||
protected function _valid()
|
||||
{
|
||||
$echoStr = $_GET["echostr"];
|
||||
|
@ -71,23 +31,19 @@ class WeChat
|
|||
echo 'error signature';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理来自微信服务器的消息
|
||||
*/
|
||||
public function process()
|
||||
public function responseMsg()
|
||||
{
|
||||
//如果是验证请求,则执行签名验证并退出
|
||||
if (!empty($_GET["echostr"])) {
|
||||
$this->valid(); //验证签名是否有效
|
||||
return; //返回退出
|
||||
$this->valid();
|
||||
//验证签名是否有效
|
||||
return;
|
||||
//返回退出
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
|
||||
echo '';
|
||||
return;
|
||||
}
|
||||
|
||||
//如果不是验证请求,则
|
||||
//首先,取得POST原始数据(XML格式)
|
||||
//$postData = $GLOBALS["HTTP_RAW_POST_DATA"];
|
||||
|
@ -95,95 +51,41 @@ class WeChat
|
|||
if (empty($postData)) {
|
||||
echo '';
|
||||
return;
|
||||
} //如果没有POST数据,则退出
|
||||
|
||||
//解析POST数据(XML格式)
|
||||
$object = simplexml_load_string($postData, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
$messgeType = trim($object->MsgType); //取得消息类型
|
||||
$this->fromUser = $object->FromUserName; //记录消息发送方(不是发送者的微信号,而是一个加密后的OpenID)
|
||||
$this->toUser = $object->ToUserName; //记录消息接收方(就是公共平台的OpenID)
|
||||
|
||||
//如果回调函数没有设置,则退出
|
||||
if (!is_callable($this->callback_function)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($messgeType == "text") {
|
||||
call_user_func($this->callback_function, $this, "text", $object->Content, "", "");
|
||||
//如果没有POST数据,则退出
|
||||
if (!empty($postData)) {
|
||||
//解析POST数据(XML格式)
|
||||
$object = simplexml_load_string($postData, 'SimpleXMLElement', LIBXML_NOCDATA);
|
||||
$messgeType = trim($object->MsgType); //取得消息类型
|
||||
$this->fromUser = "" . $object->FromUserName;
|
||||
$this->toUser = "" . $object->ToUserName;
|
||||
$keyword = trim($object->Content);
|
||||
if ($messgeType == 'text' && $keyword == '验证码') {
|
||||
$response_content = '您的验证码为:【' . $this->captcha . '】,验证码有效期为2分钟,请抓紧使用,过期需重新申请';
|
||||
$xmlTemplate = "<xml>
|
||||
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||
<CreateTime>%s</CreateTime>
|
||||
<MsgType><![CDATA[text]]></MsgType>
|
||||
<Content><![CDATA[%s]]></Content>
|
||||
<FuncFlag>%d</FuncFlag>
|
||||
</xml>";
|
||||
$xmlText = sprintf($xmlTemplate, $this->fromUser, $this->toUser, time(), $response_content, 0);
|
||||
echo $xmlText;
|
||||
}
|
||||
} else {
|
||||
echo "";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 形成 文本消息响应值
|
||||
*
|
||||
* @param string $toUser
|
||||
* @param string $fromUser
|
||||
* @param string $content
|
||||
* @param integer $flag
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _textResponse($toUser, $fromUser, $content, $flag = 0)
|
||||
{
|
||||
$xmlTemplate = "<xml>
|
||||
<ToUserName><![CDATA[%s]]></ToUserName>
|
||||
<FromUserName><![CDATA[%s]]></FromUserName>
|
||||
<CreateTime>%s</CreateTime>
|
||||
<MsgType><![CDATA[text]]></MsgType>
|
||||
<Content><![CDATA[%s]]></Content>
|
||||
<FuncFlag>%d</FuncFlag>
|
||||
</xml>";
|
||||
|
||||
$xmlText = sprintf($xmlTemplate, $toUser, $fromUser, time(), $content, $flag);
|
||||
|
||||
return $xmlText;
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送文本内容
|
||||
*
|
||||
* @param string $content 文本内容
|
||||
*/
|
||||
public function sendText($content)
|
||||
{
|
||||
echo $this->textResponse($this->fromUser, $this->toUser, $content);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
add_action('pre_get_posts', 'wx_preprocess', 4);
|
||||
/**
|
||||
* 预处理函数
|
||||
*
|
||||
* @param $wp_query
|
||||
*/
|
||||
function wx_preprocess($wp_query)
|
||||
function wx_process()
|
||||
{
|
||||
global $object;
|
||||
$wx_token = trim(gdk_option('gdk_wxmp_token'));
|
||||
if (!isset($object)) {
|
||||
//创建一个WeChat类的实例, 回调函数名称为"CaptchaMessage",即消息处理函数
|
||||
$object = new WeChat($wx_token, "CaptchaMessage");
|
||||
$object->process(); //处理消息
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 消息处理函数
|
||||
*
|
||||
* @param WeChat $object
|
||||
* @param string $messageType
|
||||
* @param string $content
|
||||
* @param string $arg1
|
||||
* @param string $arg2
|
||||
*/
|
||||
function CaptchaMessage(WeChat $object, $messageType, $content, $arg1, $arg2)
|
||||
{
|
||||
if ($messageType == "text") {
|
||||
$keyword = trim($content);
|
||||
if (in_string($keyword, '验证码')) {
|
||||
$object->sendText('您的验证码为:【' . wx_captcha() . '】,验证码有效期为2分钟,请抓紧使用,过期需重新申请');
|
||||
}
|
||||
}
|
||||
$object = new Wechat_Captcha($wx_token, wx_captcha());
|
||||
$object->responseMsg();
|
||||
return;
|
||||
}
|
||||
add_action('pre_get_posts', 'wx_process', 4);
|
||||
|
|
|
@ -23,8 +23,13 @@ function gdk_add_content($content)
|
|||
{
|
||||
$before = gdk_option('gdk_artical_top');
|
||||
$after = gdk_option('gdk_artical_bottom');
|
||||
$content = $before . '<br>' . $content . '<br>' . $after;
|
||||
return $content;
|
||||
if(empty($before) && empty($after)){
|
||||
return $content;
|
||||
}else{
|
||||
return $before . '<br>' . $content . '<br>' . $after;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
add_filter('the_content', 'gdk_add_content');
|
||||
|
||||
|
@ -163,10 +168,10 @@ function gdk_link_go($content)
|
|||
//邮箱SMTP设置
|
||||
function gdk_smtp($phpmailer)
|
||||
{
|
||||
$phpmailer->FromName = gdk_option('gdk_smtp_username'); //邮箱地址
|
||||
$phpmailer->FromName = gdk_option('gdk_smtp_username'); //昵称
|
||||
$phpmailer->Host = gdk_option('gdk_smtp_host'); //服务器地址
|
||||
$phpmailer->Port = gdk_option('gdk_smtp_port'); //端口
|
||||
$phpmailer->Username = gdk_option('gdk_smtp_mail'); //昵称
|
||||
$phpmailer->Username = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->Password = gdk_option('gdk_smtp_password'); //密码
|
||||
$phpmailer->From = gdk_option('gdk_smtp_mail'); //邮箱地址
|
||||
$phpmailer->SMTPAuth = true;
|
||||
|
|
|
@ -228,9 +228,9 @@ function gdk_secret_view($atts, $content = null)
|
|||
return '<div class="cm-grid cm-card pass_viewbox">
|
||||
<div class="cm-row">
|
||||
<div class="cm-col-md-4">
|
||||
<img src="https://p.ssl.qhimg.com/t0162cc8398cbf7dea3.jpg" class="cm-resp-img">
|
||||
<img src="'.gdk_option('gdk_mp_qr').'" class="cm-resp-img">
|
||||
</div>
|
||||
<div class="cm-col-md-8">
|
||||
<div class="cm-col-md-8" style="margin-top:4%;">
|
||||
<div class="hide_content_info" style="margin:10px 0">
|
||||
<div class="cm-alert primary">本段内容已被隐藏,您需要扫码关注微信公众号申请验证码查看,发送【验证码】获取验证码,验证码2分钟有效</div>
|
||||
<input type="text" id="pass_view" placeholder="输入验证码并提交" style="width:70%"> <input id="submit_pass_view" class="cm-btn success" data-action="gdk_pass_view" data-id="' . $pid . '" type="button" value="提交">
|
||||
|
|
Loading…
Reference in a new issue