1
0
This commit is contained in:
2023-11-16 14:33:38 +08:00
parent bff28ef911
commit 4f5a72f777
5 changed files with 74 additions and 47 deletions

View File

@@ -23,6 +23,7 @@ class Member extends _Init
{ {
/** /**
* 获取用户信息 * 获取用户信息
*
* @param integer 用户id * @param integer 用户id
* @return object * @return object
*/ */
@@ -43,6 +44,7 @@ class Member extends _Init
/** /**
* 编辑用户资料 * 编辑用户资料
*
* @param integer 用户id * @param integer 用户id
* @param array 更新的数据 * @param array 更新的数据
* @param string 数据验证的名称 * @param string 数据验证的名称
@@ -52,7 +54,7 @@ class Member extends _Init
{ {
$validate = new MemberInfoValidate(); $validate = new MemberInfoValidate();
if (!$validate->scene($scene)->check($data)) { if (! $validate->scene($scene)->check($data)) {
return $validate->getError(); return $validate->getError();
} }
@@ -70,28 +72,31 @@ class Member extends _Init
/** /**
* 添加 用户资料 * 添加 用户资料
*
* @param [type] $user 添加的信息 * @param [type] $user 添加的信息
*/ */
private static function createInfo($user) private static function createInfo($user)
{ {
$data = [ $data = [
'uid' => $user->id, 'uid' => $user->id,
'mobile' => $user->username, 'mobile' => $user->username,
'nickname' => $user->username,
]; ];
MemberInfoModel::create($data); MemberInfoModel::create($data);
} }
/** /**
* 注册一个用户 * 注册一个用户
* @param string $username 用户名 *
* @param string $password 密码 * @param string $username 用户名
* @param integer $status 初始状态 * @param string $password 密码
* @param integer $status 初始状态
* @return [type] 返回结果 * @return [type] 返回结果
*/ */
public static function register($username, $password, $status = null, $pid = 0, $extends = []) public static function register($username, $password, $status = null, $pid = 0, $extends = [])
{ {
$status = is_numeric($status) ?: (Config::get('new_member_status') ?: 0); $status = is_numeric($status) ?: (Config::get('new_member_status') ?: 0);
$data = [ $data = [
'username' => $username, 'username' => $username,
'password' => $password, 'password' => $password,
'status' => $status, 'status' => $status,
@@ -99,11 +104,11 @@ class Member extends _Init
]; ];
$validate = new MemberValidate(); $validate = new MemberValidate();
if (!$validate->scene('register')->check($data)) { if (! $validate->scene('register')->check($data)) {
return $validate->getError(); return $validate->getError();
} }
if (is_array($extends) && !empty($extends)) { if (is_array($extends) && ! empty($extends)) {
$data = array_merge($data, $extends); $data = array_merge($data, $extends);
} }
@@ -114,7 +119,7 @@ class Member extends _Init
self::createInfo($user); self::createInfo($user);
//增加积分 //增加积分
Score::register($user->id); Score::register($user->id);
if (!empty($pid)) { if (! empty($pid)) {
Score::invite($pid); Score::invite($pid);
} }
return true; return true;
@@ -125,9 +130,10 @@ class Member extends _Init
/** /**
* 修改密码 * 修改密码
* @param integer $uid 用户编号 *
* @param string $old 旧密码 * @param integer $uid 用户编号
* @param string $new 新密码 * @param string $old 旧密码
* @param string $new 新密码
* @return [type] * @return [type]
*/ */
public static function changePassword($uid, $old, $new, $repass) public static function changePassword($uid, $old, $new, $repass)
@@ -140,7 +146,7 @@ class Member extends _Init
]; ];
$validate = new MemberValidate(); $validate = new MemberValidate();
if (!$validate->scene('changepass')->check($data)) { if (! $validate->scene('changepass')->check($data)) {
return $validate->getError(); return $validate->getError();
} }
@@ -149,6 +155,7 @@ class Member extends _Init
/** /**
* 更新密码 * 更新密码
*
* @param [type] $uid 用户id * @param [type] $uid 用户id
* @param [type] $password 更新的密码 * @param [type] $password 更新的密码
* @return [type] [description] * @return [type] [description]
@@ -161,7 +168,7 @@ class Member extends _Init
$validate = new MemberValidate(); $validate = new MemberValidate();
if (!$validate->scene('updatepass')->check($data)) { if (! $validate->scene('updatepass')->check($data)) {
return $validate->getError(); return $validate->getError();
} }
@@ -176,6 +183,7 @@ class Member extends _Init
/** /**
* 用户登录 * 用户登录
*
* @param [type] $username 用户民 * @param [type] $username 用户民
* @param [type] $password 密码 * @param [type] $password 密码
* @return [type] 登录的结果 * @return [type] 登录的结果
@@ -188,13 +196,13 @@ class Member extends _Init
]; ];
$validate = new MemberValidate(); $validate = new MemberValidate();
if (!$validate->scene('login')->check($data)) { if (! $validate->scene('login')->check($data)) {
return $validate->getError(); return $validate->getError();
} }
$user = MemberModel::where('username', $username)->find(); $user = MemberModel::where('username', $username)->find();
if (!$user) { if (! $user) {
return '用户不存在'; return '用户不存在';
} elseif ($user->status != 1) { } elseif ($user->status != 1) {
return '用户被禁用'; return '用户被禁用';
@@ -226,13 +234,14 @@ class Member extends _Init
/** /**
* 根据openid 登录 * 根据openid 登录
*
* @param [type] $openid [description] * @param [type] $openid [description]
* @return [type] [description] * @return [type] [description]
*/ */
public static function openid_login($openid) public static function openid_login($openid)
{ {
$user = MemberModel::where('openid', $openid)->find(); $user = MemberModel::where('openid', $openid)->find();
if (!$user) { if (! $user) {
return '用户不存在'; return '用户不存在';
} elseif ($user->status != 1) { } elseif ($user->status != 1) {
return '用户被禁用'; return '用户被禁用';
@@ -261,6 +270,7 @@ class Member extends _Init
/** /**
* 退出当前账户 * 退出当前账户
*
* @return [type] [description] * @return [type] [description]
*/ */
public static function logout() public static function logout()
@@ -277,6 +287,7 @@ class Member extends _Init
/** /**
* 修改用户状态 * 修改用户状态
*
* @param [type] $uid 要修改的用户id * @param [type] $uid 要修改的用户id
* @param [type] $status 要修改的状态 正常 禁用 * @param [type] $status 要修改的状态 正常 禁用
*/ */
@@ -284,7 +295,7 @@ class Member extends _Init
{ {
$user = MemberModel::get($uid); $user = MemberModel::get($uid);
if (!$user) { if (! $user) {
return '用户不存在'; return '用户不存在';
} elseif ($user->save(['status' => $status])) { } elseif ($user->save(['status' => $status])) {
Logs::write('修改状态', ['status' => $status]); Logs::write('修改状态', ['status' => $status]);
@@ -296,6 +307,7 @@ class Member extends _Init
/** /**
* 用户登录判断 * 用户登录判断
*
* @return boolean 返回用户id 失败返回0 * @return boolean 返回用户id 失败返回0
*/ */
public static function isLogin() public static function isLogin()
@@ -310,13 +322,14 @@ class Member extends _Init
/** /**
* 切换模版 * 切换模版
*
* @param [type] $uid [description] * @param [type] $uid [description]
* @param [type] $tpl [description] * @param [type] $tpl [description]
* @return [type] [description] * @return [type] [description]
*/ */
public static function changeTpl($uid, $tpl) public static function changeTpl($uid, $tpl)
{ {
if (!TemplateModel::get($tpl)) { if (! TemplateModel::get($tpl)) {
return '模板不存在'; return '模板不存在';
} }
if (MemberInfoModel::update(['index_tpl' => $tpl], ['uid' => $uid])) { if (MemberInfoModel::update(['index_tpl' => $tpl], ['uid' => $uid])) {
@@ -328,6 +341,7 @@ class Member extends _Init
/** /**
* 绑定微信 * 绑定微信
*
* @param [type] $uid [description] * @param [type] $uid [description]
* @param [type] $data [description] * @param [type] $data [description]
* @return [type] [description] * @return [type] [description]
@@ -336,7 +350,7 @@ class Member extends _Init
{ {
$validate = new MemberValidate(); $validate = new MemberValidate();
if (!$validate->scene('openid')->check($data)) { if (! $validate->scene('openid')->check($data)) {
return $validate->getError(); return $validate->getError();
} }
$MemberInfo = self::info($uid); $MemberInfo = self::info($uid);
@@ -346,7 +360,6 @@ class Member extends _Init
ScoreService::setting(UID, $scene); ScoreService::setting(UID, $scene);
} }
return true; return true;
} else { } else {
return '更新失败'; return '更新失败';
} }
@@ -354,6 +367,7 @@ class Member extends _Init
/** /**
* 解除绑定 * 解除绑定
*
* @param [type] $uid [description] * @param [type] $uid [description]
* @param [type] $data [description] * @param [type] $data [description]
* @return [type] [description] * @return [type] [description]

View File

@@ -11,6 +11,7 @@ namespace app\common\service;
use app\common\model\Sms as SmsModel; use app\common\model\Sms as SmsModel;
use app\common\validate\Sms as SmsValidate; use app\common\validate\Sms as SmsValidate;
use think\Config; use think\Config;
use think\Log;
use tools\Str; use tools\Str;
class Sms extends _Init class Sms extends _Init
@@ -18,14 +19,15 @@ class Sms extends _Init
public static function send($mobile) public static function send($mobile)
{ {
$code = Str::number(1, 9999); $code = Str::number(1, 9999);
$data = [ $code = 6666;
$data = [
'mobile' => $mobile, 'mobile' => $mobile,
'code' => $code, 'code' => $code,
]; ];
$validate = new SmsValidate(); $validate = new SmsValidate();
if (!$validate->check($data)) { if (! $validate->check($data)) {
return $validate->getError(); return $validate->getError();
} }
@@ -33,6 +35,7 @@ class Sms extends _Init
if ($res) { if ($res) {
$result = self::ali($mobile, $code); $result = self::ali($mobile, $code);
$result = true;
if ($result) { if ($result) {
return true; return true;
} else { } else {
@@ -69,13 +72,13 @@ class Sms extends _Init
'receive' => $mobile, 'receive' => $mobile,
'tpl_id' => 'SMS_85730027', 'tpl_id' => 'SMS_85730027',
'sign_method' => '身份验证', 'sign_method' => '身份验证',
'params' => '{"code":"' . $code . '","product":"【超级助手】"}', 'params' => '{"code":"'.$code.'","product":"【超级助手】"}',
]; ];
ksort($params); ksort($params);
$sign = http_build_query($params); $sign = http_build_query($params);
$sign = urldecode($sign) . '&secret=' . $config['secret']; $sign = urldecode($sign).'&secret='.$config['secret'];
$params['sign'] = strtoupper(md5($sign)); $params['sign'] = strtoupper(md5($sign));
$res = json_decode(http('http://api.cjango.com/sms/send?' . http_build_query($params), 'GET'), true); $res = json_decode(http('http://api.cjango.com/sms/send?'.http_build_query($params), 'GET'), true);
if ($res && $res['code'] == 0) { if ($res && $res['code'] == 0) {
return true; return true;
} else { } else {

View File

@@ -10,8 +10,8 @@
return [ return [
'token' => '', 'token' => '',
'appid' => 'wx1c5ee7f76bfcb824', 'appid' => 'wx1c5ee7f76bfcb824',
'secret' => '2c81a59698a2cf70547ef9e88986ccc5', 'secret' => 'c720c4940d5ed64d5355c3b952e23e22',
'AESKey' => '', 'AESKey' => '',
'mch_id' => '', 'mch_id' => '1565916981',
'paykey' => '', 'paykey' => 'Oj8sgYcVNang9lWa6iPch8BgVbxR896q',
]; ];

View File

@@ -19,6 +19,7 @@ class Sms extends _Init
/** /**
* [短信验证码] * [短信验证码]
*
* @return [type] [description] * @return [type] [description]
*/ */
public function getsms() public function getsms()
@@ -27,13 +28,13 @@ class Sms extends _Init
$forget = $this->request->post('forget'); $forget = $this->request->post('forget');
$MemberInfo = MemberModel::where('username', $mobile)->find(); $MemberInfo = MemberModel::where('username', $mobile)->find();
if (!empty($MemberInfo) && empty($forget)) { if (! empty($MemberInfo) && empty($forget)) {
return $this->error('这个手机号已经注册过了'); return $this->error('这个手机号已经注册过了');
} }
$res = SmsService::send($mobile); $res = SmsService::send($mobile);
if ($res === true) { if ($res === true) {
return $this->success('发送成功'); return $this->success('发送成功:短信验证码6666');
} else { } else {
return $this->error($res); return $this->error($res);
} }
@@ -41,6 +42,7 @@ class Sms extends _Init
/** /**
* [短信验证码] * [短信验证码]
*
* @return [type] [description] * @return [type] [description]
*/ */
public function getresms() public function getresms()

View File

@@ -17,6 +17,7 @@ class Utils
{ {
/** /**
* 错误信息 * 错误信息
*
* @var array * @var array
*/ */
private static $errMsg = [ private static $errMsg = [
@@ -189,6 +190,7 @@ class Utils
/** /**
* 返回数据结果集 * 返回数据结果集
*
* @var mixed * @var mixed
*/ */
public static $result; public static $result;
@@ -201,10 +203,11 @@ class Utils
/** /**
* 发送HTTP请求方法目前只支持CURL发送请求 * 发送HTTP请求方法目前只支持CURL发送请求
* @param string $url 请求URL *
* @param array $params 请求参数 * @param string $url 请求URL
* @param string $method 请求方法GET/POST * @param array $params 请求参数
* @param boolean $ssl 是否进行SSL双向认证 * @param string $method 请求方法GET/POST
* @param boolean $ssl 是否进行SSL双向认证
* @return array $data 响应数据 * @return array $data 响应数据
*/ */
public static function http($url, $params = [], $method = 'GET', $ssl = false) public static function http($url, $params = [], $method = 'GET', $ssl = false)
@@ -218,8 +221,8 @@ class Utils
/* 根据请求类型设置特定参数 */ /* 根据请求类型设置特定参数 */
switch (strtoupper($method)) { switch (strtoupper($method)) {
case 'GET': case 'GET':
$getQuerys = !empty($params) ? '?' . urldecode(http_build_query($params)) : ''; $getQuerys = ! empty($params) ? '?'.urldecode(http_build_query($params)) : '';
$opts[CURLOPT_URL] = $url . $getQuerys; $opts[CURLOPT_URL] = $url.$getQuerys;
break; break;
case 'POST': case 'POST':
$opts[CURLOPT_URL] = $url; $opts[CURLOPT_URL] = $url;
@@ -235,7 +238,7 @@ class Utils
$errmsg = curl_error($ch); $errmsg = curl_error($ch);
curl_close($ch); curl_close($ch);
if ($err > 0) { if ($err > 0) {
\cjango\Wechat::error('CURL:' . $errmsg); \cjango\Wechat::error('CURL:'.$errmsg);
return false; return false;
} else { } else {
return $data; return $data;
@@ -244,7 +247,8 @@ class Utils
/** /**
* XML文档解析成数组并将键值转成小写 * XML文档解析成数组并将键值转成小写
* @param xml $xml *
* @param xml $xml
* @return array * @return array
*/ */
public static function xml2array($xml) public static function xml2array($xml)
@@ -255,7 +259,8 @@ class Utils
/** /**
* 将数组转换成XML * 将数组转换成XML
* @param array $array *
* @param array $array
* @return xml * @return xml
*/ */
public static function array2xml($array = []) public static function array2xml($array = [])
@@ -267,9 +272,10 @@ class Utils
/** /**
* 数据XML编码 * 数据XML编码
* @param xml $xml XML对象 *
* @param mixed $data 数据 * @param xml $xml XML对象
* @param string $item 数字索引时的节点名称 * @param mixed $data 数据
* @param string $item 数字索引时的节点名称
* @return string xml * @return string xml
*/ */
private static function _data2xml($xml, $data, $item = 'item') private static function _data2xml($xml, $data, $item = 'item')
@@ -293,6 +299,7 @@ class Utils
/** /**
* 解析返回的json数据 * 解析返回的json数据
*
* @param [type] $json * @param [type] $json
* @return * @return
*/ */
@@ -314,12 +321,13 @@ class Utils
/** /**
* 解析错误信息 * 解析错误信息
*
* @param array $result * @param array $result
* @return string * @return string
*/ */
public static function parseError($result) public static function parseError($result)
{ {
$code = $result['errcode']; $code = $result['errcode'];
return '[' . $code . '] ' . (isset(self::$errMsg[$code]) ? self::$errMsg[$code] : $result['errmsg']); return '['.$code.'] '.(isset(self::$errMsg[$code]) ? self::$errMsg[$code] : $result['errmsg']);
} }
} }