Commit 1b86245d authored by wangtao's avatar wangtao

学习资料

parent 44b3818e
......@@ -36,7 +36,7 @@ class Advert extends AdminBase
$list = $this->advert->with(['coverImg'])->append(['advcatename'])->where($map)->paginate($post['limit']);
return $this->returnMsg($list);
}
$categorydata = AdvertCate::select()->toArray();
$categorydata = AdvertCate::where('is_del',0)->select()->toArray();
$this->assign('categorydata', $categorydata);
$this->assign('limit', $limit);
$this->assign('get', input());
......
......@@ -12,6 +12,7 @@ namespace app\admin\controller\cert;
use app\admin\controller\AdminBase;
use app\admin\validate\CertValidate;
use app\api\service\UtilService;
use app\model\Cert as CertModel;
use think\App;
use think\facade\Db;
......@@ -102,6 +103,7 @@ class Cert extends AdminBase
$msg = '更新成功';
$this->cert->update($post, ['id' => $post['id']]);
} else {
$post['sn'] = UtilService::generateCompactOrderNo(0, 'SMBH');
$post['createtime'] = time();
unset($post['id']);
$msg = '添加成功';
......
......@@ -44,10 +44,14 @@ class CertOrder extends AdminBase
if (isset($post['kw']) && !empty($post['kw'])) {
$hasmap[] = ['user.username|user.mobile', 'like', '%' . $post['kw'] . '%'];
}
$certmap = [];
if (isset($post['cert_title']) && !empty($post['cert_title'])) {
$certmap[] = ['cert.title', 'like', '%' . trim($post['cert_title']) . '%'];
}
if (isset($post['status']) && !empty($post['status'])) {
$map[] = ['status', '=', $post['status']];
}
$list = $this->certorder->hasWhere('userprofile', $hasmap)->where($map)->with(['certdata','userprofile'])->append(['status_text'])->order('createtime desc')->paginate($post['limit']);
$list = $this->certorder->hasWhere('userprofile', $hasmap)->hasWhere('certdata', $certmap)->where($map)->with(['certdata','userprofile'])->append(['status_text'])->order('createtime desc')->paginate($post['limit']);
return $this->returnMsg($list);
}
......
......@@ -60,7 +60,7 @@ class Project extends AdminBase
if (isset($post['user']) && !empty($post['user'])) {
$hasmap[] = ['username|mobile', 'like', '%' . $post['user'] . '%'];
}
$list = $this->project->where($map)->hasWhere('getuserdata', $hasmap)->with(['projectcatedata', 'getuserdata'])->append(['sh_status_text', 'status_text'])->order('createtime desc')->paginate($post['limit']);
$list = $this->project->where($map)->hasWhere('getuserdata', $hasmap)->with(['projectcatedata', 'getuserdata','thumb'])->append(['sh_status_text', 'status_text'])->order('createtime desc')->paginate($post['limit']);
return $this->returnMsg($list);
}
$category = projectCategory::field('*,pid as parentid')->order('sort desc')->select()->toArray();
......
......@@ -181,7 +181,7 @@ class Setting extends AdminBase
{
$d = $this->only($do ? ['@token'=>'','id/d/ID参数错误','av','af'] : ['@token'=>'','id/d/ID参数错误',$this->ptype,$this->pname,$this->ptitle,$this->pgroup,$this->ptips,'value/u','options/u','listorder/d']);
$id = $d['id'];
if(in_array($id, [1,2])) return $this->returnMsg("系统关键配置项不可修改");
// if(in_array($id, [1,2])) return $this->returnMsg("系统关键配置项不可修改");
$Myobj = S::one("id = $id");
if(!$Myobj) return $this->returnMsg("数据不存在");
if($do=='up'){
......
......@@ -11,6 +11,7 @@
<div class="layui-form-item">
<div class="layui-inline" style="width:250px;"><input type="text" name="kw" placeholder="用户名,用户手机号" autocomplete="off" class="layui-input" lay-affix="clear"/></div>
<div class="layui-inline" style="width:250px;"><input type="text" name="cert_title" placeholder="证书名称" autocomplete="off" class="layui-input" lay-affix="clear"/></div>
<div class="layui-inline" style="width:150px;">
<select name="status">
<option value="">审核状态</option>
......
......@@ -165,7 +165,8 @@
cols: [[
{type:'checkbox',fixed:'left'},
{field:'id',width:50,unresize:true,align:'center',title:'ID',sort:!0},
{field:'sn',align:'center',width:160,title:'项目编号'},
{field:'thumb',width:80,height:80,align:'center',title:'项目图片',templet:'<div class="files_itemwproject"><img src="{{d.thumb.fileurl}}" lay-event="project-event-image" /></div>'},
// {field:'sn',align:'center',width:160,title:'项目编号'},
{field:'username',align:'center',width:130,title:'发布者',templet:'<div>{{= d.getuserdata.username}}</div>'},
{field:'title',align:'center',width:240,title:'项目名称'},
{field:'cate_name',width:120,align:'center',title:'类别',templet:'<div>{{= d.projectcatedata.title}}</div>'},
......
......@@ -38,8 +38,8 @@
cols: [[
{field:'id',width:50,unresize:true,align:'center',title:'ID',sort:!0},
{field:'event',align:'center',width:160,title:'事件名称',edit:'text',editTrigger:'dblclick'},
{field:'action',align:'center',title:'控制器/方法 格式如:user/login'},
{field:'event',align:'center',title:'事件名称',edit:'text',editTrigger:'dblclick'},
// {field:'action',align:'center',title:'控制器/方法 格式如:user/login'},
{field:'exp',align:'center',width:160,title:'可获经验值',edit:'text',editTrigger:'dblclick'},
{field:'daily_limit',align:'center',width:160,title:'每日上限',edit:'text',editTrigger:'dblclick'},
{field:'interval_limit',align:'center',width:160,title:'间隔时间(秒)',edit:'text',editTrigger:'dblclick'},
......
This diff is collapsed.
......@@ -2,10 +2,17 @@
namespace app\api\controller;
use app\api\service\TokenService;
use app\model\project\User as userModel;
use think\facade\Log;
use think\Request;
use app\api\validate\ArticleValidate;
use app\BaseController;
use app\model\ArticleModel;
use app\api\service\WeChatLoginService;
use think\facade\Cache;
use app\model\project\User;
class Wecaht extends BaseController
{
......@@ -13,9 +20,36 @@ class Wecaht extends BaseController
public function index()
{
$get = input();
exit($get['echostr']);
$body = file_get_contents('php://input');
$simpleXml = simplexml_load_string($body, 'SimpleXMLElement', LIBXML_NOCDATA);
$json = json_encode($simpleXml);
$array = json_decode($json, true); // true表示转为关联数组
Log::write('微信登录事件');
Log::write($array);
if ($array['Event'] == 'SCAN' || $array['Event'] == 'subscribe') {
$EventKey = $array['EventKey'];
if ($array['Event'] == 'subscribe') {
$EventKeys = explode('_', $array['EventKey']);
$EventKey = $EventKeys[1] . '_' . $EventKeys[2];
}
$cachekey = Cache::get($EventKey);
if ($cachekey == $array['Ticket']) {
$openid = $array['FromUserName'];
Log::write('扫描成功');
Cache::set($EventKey, $openid, 1000);
$user = User::where('wx_openid', $openid)->find();
if (empty($user)) {
$user['wx_openid'] = $openid;
$user['is_del'] = 1;
$user['create_time'] = time();
$user['headico'] = vconfig('default_user') ?? null;
userModel::insert($user);
}
}
}
// // 配置 Token(需与微信公众号后台设置一致)
// define("WX_TOKEN", "YOUR_TOKEN_HERE");
// // 处理微信服务器发送的 GET 验证请求
......@@ -66,4 +100,44 @@ class Wecaht extends BaseController
}
}
//检车微信openid是否登录 2秒轮询
public function checkwxlogin()
{
$param = $this->request->post();
$cachekey = $param['cachekey'];
$openid = Cache::get($cachekey);
$user = User::where('wx_openid', $openid)->find();
if (isset($user['id']) && empty($user['mobile'])) {
$redata = ['token' => '', 'expires_in' => 0, 'user_id' => $user['id'], 'is_mobile' => 0];
} elseif ($user) {
if ($user['status'] != 1) {
return $this->returnMsg('账号禁止登录', 0);
}
if ($user['is_del'] != 0) {
return $this->returnMsg('账号已删除', 0);
}
$token = TokenService::generateToken($user['id'], $user->toArray());
$update['token'] = $token;
$update['last_login_time'] = time();
User::where(['id' => $user['id']])->update($update);
$redata = ['token' => $token, 'expires_in' => TokenService::EXPIRE, 'user_id' => $user['id'], 'is_mobile' => 1];
} else {
return $this->returnMsg("登录失败,请重新扫码", 0);
}
return $this->returnMsg("success", 1, $redata);
}
//生成二维码
public function createwxewm()
{
try {
$data = WeChatLoginService::createerwm();
} catch (\Exception $e) {
return $this->returnMsg($e->getMessage());
}
return $this->returnMsg("success", 1, $data);
}
}
\ No newline at end of file
This diff is collapsed.
......@@ -80,6 +80,8 @@ class Project extends BaseController
['user_id'=>27, 'total_money'=>2500.0, 'record_count'=>8, 'user_info'=>['username'=>'Alice', 'realname'=>'Alice Smith', 'headico'=>41, 'id'=>2]],
['user_id'=>28, 'total_money'=>2000.0, 'record_count'=>7, 'user_info'=>['username'=>'Bob', 'realname'=>'Bob Johnson', 'headico'=>42, 'id'=>3]],
['user_id'=>29, 'total_money'=>1800.0, 'record_count'=>6, 'user_info'=>['username'=>'David', 'realname'=>'David Lee', 'headico'=>43, 'id'=>4]],
['user_id'=>33, 'total_money'=>1500.0, 'record_count'=>6, 'user_info'=>['username'=>'张三', 'realname'=>'张三', 'headico'=>43, 'id'=>4]],
['user_id'=>34, 'total_money'=>1300.0, 'record_count'=>6, 'user_info'=>['username'=>'李四', 'realname'=>'李四', 'headico'=>43, 'id'=>4]],
];
}
......
<?php
namespace app\api\service;
use think\facade\Cache;
use think\facade\Log;
use think\Response;
class WeChatLoginService
{
// Token前缀
const TOKEN_PREFIX = 'wechat_login_token:';
// 过期时间(秒)
const EXPIRE = 5400; // 1.5小时
const appid = "wx24528a99c58e1919";
const appsecret = "9ff78ed83a517231754217784eab29a6";
//生成access_token
public static function createAccessToken()
{
$cacheKey = self::TOKEN_PREFIX . self::appid;
$accessToken = Cache::get($cacheKey);
if ($accessToken) {
return $accessToken;
}
$appid = self::appid;
$appsecret = self::appsecret;
$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}";
// 发送HTTP请求
$response = http_get($url);
$data = json_decode($response, true);
if (isset($data['access_token']) && $data['access_token']) {
// 存入缓存
Cache::set($cacheKey, $data['access_token'], self::EXPIRE);
return $data['access_token'];
}
throw new \Exception('access_token生成失败001');
}
//生成二维码
public static function createerwm()
{
$accessToken = self::createAccessToken();
if (!$accessToken) {
throw new \Exception('access_token生成失败002');
}
$cachekey = 'wxlogin_' . md5(self::TOKEN_PREFIX . uniqid());
$pram['expire_seconds'] = 500;
$pram['action_name'] = 'QR_STR_SCENE';
$pram['action_info']['scene'] = array(
'scene_str' => $cachekey,
'scene_id' => 1000
);
$url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=" . $accessToken;
$response = http_post($url, json_encode($pram, true));
$data = json_decode($response, true);
if (isset($data['ticket']) && $data['ticket']) {
$ewmurl = "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=" . urlencode($data['ticket']);
$returndata['cachekey'] = $cachekey;
$returndata['ewmurl'] = $ewmurl;
Cache::set($cachekey, $data['ticket'], 1000);
return $returndata;
}
throw new \Exception('二维码获取失败');
}
}
\ No newline at end of file
......@@ -14,6 +14,7 @@ class UserValidate extends BaseValidate
'token'=>'require',
'str'=>'require',
'confirm_password' => 'require|checkPasswordEqual',
'password2' => 'require|checkPasswordEqual',
'updateField'=>'require|in:username,realname,sex,headico,description,email,qq,wechat',
'updateValue'=>'require',
'zfb'=>'require',
......@@ -25,9 +26,11 @@ class UserValidate extends BaseValidate
'txType'=>'require',
'reset_token'=>'require',
'role'=>'require',
'user_id'=>'require',
];
protected $message = [
'user_id.require' => '用户id不能为空',
'name.require' => '名称必须',
'mobile.require' => '手机号不能为空',
'mobile.mobile' => '手机号格式不正确',
......@@ -36,6 +39,7 @@ class UserValidate extends BaseValidate
'token.require' => 'token必须',
'str.require' => '必填项不能为空',
'confirm_password.checkPasswordEqual' => '两次输入的密码不一致',
'password2.checkPasswordEqual' => '两次输入的密码不一致',
'updateField.require' => '必填项不能为空',
'updateField.in' => '范围不合法',
'amount.require' => '金额不能为空',
......
......@@ -610,4 +610,72 @@ function build_bill_no(string $code, string $spr = "-%03d", string $start = "-00
} else {
return '??' . date("Ymd", $day) . '001';
}
}
/**
* POST 请求
* @param string $url
* @param array $param
* @param boolean $post_file 是否文件上传
* @return string content
*/
function http_post($url, $param, $post_file = false)
{
$oCurl = curl_init();
if (stripos($url, "https://") !== FALSE) {
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
if (is_string($param) || $post_file) {
$strPOST = $param;
} else {
$aPOST = array();
foreach ($param as $key => $val) {
$aPOST[] = $key . "=" . urlencode($val);
}
$strPOST = join("&", $aPOST);
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($oCurl, CURLOPT_POST, true);
curl_setopt($oCurl, CURLOPT_POSTFIELDS, $strPOST);
// curl_setopt($oCurl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727);BURNK NT 1.0.1;");
curl_error($oCurl);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if (intval($aStatus["http_code"]) == 200) {
return $sContent;
} else {
return false;
}
}
/**
* GET 请求
* @param string $url
*/
function http_get($url)
{
$oCurl = curl_init();
if (stripos($url, "https://") !== FALSE) {
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
}
curl_setopt($oCurl, CURLOPT_URL, $url);
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
$sContent = curl_exec($oCurl);
$aStatus = curl_getinfo($oCurl);
curl_close($oCurl);
if (intval($aStatus["http_code"]) == 200) {
return $sContent;
} else {
return false;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment