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

View File

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

View File

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

View File

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

View File

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