AVRIL_START_JANCOKALIVEAVRIL_END_JANCOK
| Server IP : dzynews.com / Your IP : 216.73.217.105 Web Server : nginx/1.30.3 System : Linux cloud-tdkldl-avd6 5.15.0-91-generic #101-Ubuntu SMP Tue Nov 14 13:30:08 UTC 2023 x86_64 User : www ( 1000) PHP Version : 8.2.31 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/dzynews.com/wp-content/themes/archive-document/Modules/Common/ |
Upload File : |
<?php
namespace B2\Modules\Common;
class Verify
{
//获取公众号二维码
public static function get_verify_info()
{
$allow = b2_get_option('verify_main', 'verify_allow');
if (!$allow)
return array('error' => __('认证已关闭', 'b2'));
$user_id = b2_get_current_user_id();
if (!$user_id)
return array('error' => __('请先登录', 'b2'));
$status = 0;
//获取当前用户的认证数据
$data = self::get_verify_data($user_id);
$qrcode = self::get_qrcode();
return array(
'data' => $data,
'qrcode' => $qrcode,
'is_weixin' => b2_is_weixin()
);
}
//获取二维码
public static function get_qrcode()
{
$allow = b2_get_option('verify_main', 'verify_allow');
if (!$allow)
return array('error' => __('认证已关闭', 'b2'));
$settings = b2_get_option('verify_main', 'verify_type');
if (!in_array('2', $settings))
return '';
$user_id = b2_get_current_user_id();
$ticket = Wecatmp::get_ticket('verify');
try {
$wechat = new \WeChat\Qrcode(Wecatmp::get_wecat_option());
return $wechat->url($ticket['ticket']);
} catch (\Exception $e) {
return array('error' => $e->getMessage());
}
}
//检查用户是否已经关注
public static function check_subscribe()
{
$user_id = b2_get_current_user_id();
$data = self::get_verify_data($user_id);
if ((int) $data['mp'] !== 1) {
return false;
}
if ((int) $data['status'] === 3) {
return false;
}
return true;
}
//获取认证数据
public static function get_verify_data($user_id)
{
global $wpdb;
$table_name = $wpdb->prefix . 'b2_verify';
$res = $wpdb->get_row(
$wpdb->prepare(
"
SELECT * FROM $table_name
WHERE user_id=%d
",
$user_id
),
ARRAY_A
);
if (!$res) {
return array(
'date' => current_time('mysql'),
'user_id' => 0,
'verified' => 0,
'name' => '',
'identification' => '',
'card' => '',
'mp' => 0,
'money' => 0,
'title' => '',
'status' => 0
);
}
return $res;
}
public static function add_verify_data($data)
{
$allow = b2_get_option('verify_main', 'verify_allow');
if (!$allow)
return array('error' => __('认证已关闭', 'b2'));
global $wpdb;
$table_name = $wpdb->prefix . 'b2_verify';
//检查之前是否有相同数据
$res = $wpdb->get_results(
$wpdb->prepare(
"
SELECT * FROM $table_name
WHERE user_id = %d
",
$data['user_id']
)
,
ARRAY_A
);
if ($res) {
$old = $res[0];
$data = array_merge($old, $data);
$where = array('id' => $old['id']);
$wpdb->update(
$table_name,
$data,
array('id' => $old['id']),
array(
'%d',//id
'%s',//date
'%d',//user_id
'%d',//verified
'%s',//name
'%s',//identification
'%s',//card
'%d',//mp
'%f',//money
'%s',//title
'%d'//status
),
array('%d')
);
} else {
$_data = array(
'date' => current_time('mysql'),
'user_id' => 0,
'verified' => 0,
'name' => '',
'identification' => '',
'card' => '',
'mp' => 0,
'money' => 0,
'title' => '',
'status' => 0
);
$data = array_merge($_data, $data);
$wpdb->insert(
$table_name,
$data,
array(
'%s',//date
'%d',//user_id
'%d',//verified
'%s',//name
'%s',//identification
'%s',//card
'%d',//mp
'%f',//money
'%s',//title
'%d'//status
)
);
}
return $data;
}
public static function submit_verify($data)
{
$data = apply_filters('b2_submit_verify_before', $data);
if (isset($data['error']))
return array('error' => $data['error']);
$allow = b2_get_option('verify_main', 'verify_allow');
if (!$allow)
return array('error' => __('认证已关闭', 'b2'));
$user_id = b2_get_current_user_id();
if (!$user_id)
return array('error' => __('请先登录', 'b2'));
$settings = b2_get_option('verify_main', 'verify_type');
$censor = apply_filters('b2_text_censor', $data['name'] . $data['title']);
if (isset($censor['error']))
return $censor;
//检查实名信息
if (in_array('1', $settings)) {
if (!self::validation_filter_id_card($data['identification'])) {
return array('error' => __('身份证号码错误', 'b2'));
}
if (mb_strlen($data['name'], 'UTF-8') > 6) {
return array('error' => __('姓名超出长度', 'b2'));
}
if (empty($data['card'])) {
return array('error' => __('请上传证件照', 'b2'));
}
$data['name'] = str_replace(array('{{', '}}'), '', sanitize_text_field($data['name']));
$data['name'] = sanitize_textarea_field($data['name']);
}
if (empty($data['title']))
return array('error' => __('请填写称号', 'b2'));
$_data = self::get_verify_data($user_id);
if (in_array('2', $settings)) {
if (!isset($_data['mp']) || (int) $_data['mp'] !== 1) {
return array('error' => __('请先关注公众号', 'b2'));
}
}
if (in_array('3', $settings)) {
if (!isset($_data['money']) || (float) $_data['money'] == 0) {
return array('error' => __('请先支付费用', 'b2'));
}
}
if (isset($_data['status']) && $_data['status'] === 3) {
return array('error' => __('已拉黑,无法继续认证', 'b2'));
}
if (mb_strlen($data['title'], 'UTF-8') > 30) {
return array('error' => __('称号超出长度', 'b2'));
}
$data['title'] = str_replace(array('{{', '}}'), '', wp_strip_all_tags($data['title']));
$data['title'] = sanitize_textarea_field(wp_unslash($data['title']));
$data['card'] = esc_url($data['card']);
$check = (int) b2_get_option('verify_main', 'verify_check');
$arg = array(
'date' => current_time('mysql'),
'user_id' => $user_id,
'verified' => 0,
'name' => $data['name'],
'identification' => $data['identification'],
'card' => $data['card'],
'title' => $data['title'],
'status' => $check === 0 ? 4 : 2
);
$data = self::add_verify_data($arg);
if ($check === 1) {
$task_check = get_user_meta($user_id, 'b2_task_check', true);
if ($task_check === '') {
$credit = b2_get_option('normal_task', 'task_user_verify');
if ((int) $credit !== 0) {
// $total = Credit::credit_change($user_id,$credit);
Gold::update_data([
'date' => current_time('mysql'),
'to' => $user_id,
'gold_type' => 0,
'post_id' => 0,
'no' => $credit,
'msg' => __('认证任务完成奖励', 'b2'),
'type' => 'user_verify',
'type_text' => __('认证完成', 'b2')
]);
//积分记录
// Message::add_message(array(
// 'user_id'=>$user_id,
// 'msg_type'=>60,
// 'msg_read'=>0,
// 'msg_date'=>current_time('mysql'),
// 'msg_users'=>'',
// 'msg_credit'=>$credit,
// 'msg_credit_total'=>$total,
// 'msg_key'=>'',
// 'msg_value'=>''
// ));
Message::update_data([
'date' => current_time('mysql'),
'from' => 0,
'to' => $user_id,
'post_id' => 0,
'msg' => __('您已经完成了认证任务', 'b2'),
'type' => 'user_verify',
'type_text' => __('认证成功', 'b2')
]);
update_user_meta($user_id, 'b2_task_check', 1);
}
}
update_user_meta($user_id, 'b2_title', $data['title']);
wp_cache_delete('b2_user_' . $user_id, 'b2_user_data');
do_action('b2_submit_verify_after', $data);
do_action('b2_user_rebuild_title', $user_id);
return 'success';
} else {
do_action('b2_submit_verify_after', $data);
return 'success';
}
return array('error' => __('数据存储失败', 'b2'));
}
public static function validation_filter_id_card($idCard)
{
// 检查长度
if (strlen($idCard) !== 18) {
return false;
}
// 检查地区代码,前6位表示地区
$areaCodes = [
'11',
'12',
'13',
'14',
'15',
'21',
'22',
'23',
'31',
'32',
'33',
'34',
'35',
'36',
'37',
'41',
'42',
'43',
'44',
'45',
'46',
'50',
'51',
'52',
'53',
'54',
'61',
'62',
'63',
'64',
'65',
'71',
'81',
'82',
'91'
];
$areaCode = substr($idCard, 0, 2);
if (!in_array($areaCode, $areaCodes)) {
return false;
}
// 检查出生日期
$birthDate = substr($idCard, 6, 8);
if (!checkdate(substr($birthDate, 4, 2), substr($birthDate, 6, 2), substr($birthDate, 0, 4))) {
return false;
}
// 检查校验位
$factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
$checkSum = 0;
for ($i = 0; $i < 17; $i++) {
$checkSum += substr($idCard, $i, 1) * $factor[$i];
}
$remainder = $checkSum % 11;
$checkCodeMap = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
$checkCode = $checkCodeMap[$remainder];
if (strtoupper(substr($idCard, 17, 1)) !== $checkCode) {
return false;
}
return true;
}
}