Commit 5b1320a3 by 庄钊鑫

注册模块代码

parent 4d9b51a7
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with NO BOM" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/personal.iml" filepath="$PROJECT_DIR$/.idea/personal.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/vendor/aliApiSdk/Dysmsapi" />
<excludeFolder url="file://$MODULE_DIR$/vendor/aliApiSdk/aliyun-php-sdk-core" />
<excludeFolder url="file://$MODULE_DIR$/vendor/jpush/jpush" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="PhpIncludePathManager">
<include_path>
<path value="$PROJECT_DIR$/vendor/jpush/jpush" />
<path value="$PROJECT_DIR$/vendor/aliApiSdk/Dysmsapi" />
<path value="$PROJECT_DIR$/vendor/aliApiSdk/aliyun-php-sdk-core" />
</include_path>
</component>
<component name="PhpProjectSharedConfiguration" php_language_level="5.4.0" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
...@@ -84,8 +84,8 @@ class Send extends Base ...@@ -84,8 +84,8 @@ class Send extends Base
$this->check($request, 'Base.sendSms'); $this->check($request, 'Base.sendSms');
if ($request['sms_type'] != 'login' and $request['sms_type'] != 'bind') { if ($request['sms_type'] != 'login' and $request['sms_type'] != 'bind') {
$bool = UserLogic::checkUser($request['mobile']); $bool = UserLogic::checkUser($request['mobile']);
if(empty($bool)){ if(!empty($bool)){
$this->returnmsg(403, [], [],"", [], "该手机号注册"); $this->returnmsg(403, [], [],"", [], "该手机号注册");
} }
} }
...@@ -93,6 +93,6 @@ class Send extends Base ...@@ -93,6 +93,6 @@ class Send extends Base
if ($info === false) { if ($info === false) {
$this->returnmsg(403, [], [], "", [], "验证码错误"); $this->returnmsg(403, [], [], "", [], "验证码错误");
} }
$this->render("验证成功",200); $this->render(200,['success'=>'验证码正确']);
} }
} }
...@@ -157,4 +157,71 @@ class User extends Base ...@@ -157,4 +157,71 @@ class User extends Base
$data !== false ? $this->render($data) : $this->returnmsg(403,"","","","","登录失败"); $data !== false ? $this->render($data) : $this->returnmsg(403,"","","","","登录失败");
} }
/**
* @author:
* @time: 2019年3月
* description 手机号验证
*/
public function validateMobile()
{
$requestData = $this->selectParam(['mobile','sms_type' => 'bind']);
$this->check($requestData, 'Base.sendSms');
$this->render(200,['success'=>'手机号码验证成功']);
}
/**
* @author:
* @time: 2019年3月
* description 发送验证码
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function sendCode()
{
$request = $this->selectParam(['mobile', 'sms_type' => 'pass']);
$request['sendPartnerSms'] = $request['sms_type'];
$this->check($request, 'Base.sendSms');
if ($request['sms_type'] == 'pass') {
$bool = UserLogic::checkUser($request['mobile']);
if(!empty($bool)){
$this->returnmsg(403, [], [],"", [], "该手机号已注册");
}
}
//$info = true;
$info = SendLogic::SendSms($request['mobile'], $request['sms_type']);
if ($info === false) {
$this->returnmsg(403, [], [],"", [], "信息发送出现了一点小问题哟~");
}
//发送成功
$this->render(200,['success'=>'验证码发送成功']);
}
/**
* @author:
* @time: 2019年3月
* description 注册
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function register()
{
$request = $this->selectParam(['mobile', 'password','password2']);
$this->check($request, 'Base.register');
$bool = UserLogic::checkUser($request['mobile']);
if(!empty($bool)){
$this->returnmsg(403, [], [],"", [], "该手机号已注册");
}
$result = UserModel::build()->register($request);
if ($result) {
$this->render(200,['success'=>'注册成功!']);
} else {
$this->returnmsg(403, $data = [], $header = [], $type = "", "Login error", $message = "注册失败");
}
}
} }
...@@ -30,7 +30,7 @@ class UserLogic ...@@ -30,7 +30,7 @@ class UserLogic
*/ */
public static function checkUser($mobile) public static function checkUser($mobile)
{ {
$bool = User::build()->where(['mobile' => $mobile, 'is_banned' => 0])->find(); $bool = User::build()->where(['mobile' => $mobile])->find();
return empty($bool) ? false : true; return empty($bool) ? false : true;
} }
......
...@@ -54,6 +54,8 @@ class Sms extends Model ...@@ -54,6 +54,8 @@ class Sms extends Model
{ {
// 调用sdk发送短信 // 调用sdk发送短信
$aliConfig = config('alidayu'); $aliConfig = config('alidayu');
$aliConfig['AccessKey'] = 'LTAIHsoQGZrGjIxs';
$aliConfig['SecretKey'] = 'BkrK54Rm2fbSwhW7Ig4dOuSMBsMJHs';
// 加载区域结点配置 // 加载区域结点配置
// 初始化用户Profile实例 // 初始化用户Profile实例
$profile = \DefaultProfile::getProfile("cn-hangzhou", $aliConfig['AccessKey'], $aliConfig['SecretKey']); $profile = \DefaultProfile::getProfile("cn-hangzhou", $aliConfig['AccessKey'], $aliConfig['SecretKey']);
...@@ -66,9 +68,9 @@ class Sms extends Model ...@@ -66,9 +68,9 @@ class Sms extends Model
// 必填,设置雉短信接收号码 // 必填,设置雉短信接收号码
$request->setPhoneNumbers($mobile); $request->setPhoneNumbers($mobile);
// 必填,设置签名名称 // 必填,设置签名名称
$request->setSignName($aliConfig['smsType'][$smsType]['signName']); $request->setSignName('庄钊鑫');
// 必填,设置模板CODE // 必填,设置模板CODE
$request->setTemplateCode($aliConfig['smsType'][$smsType]['templateCode']); $request->setTemplateCode('SMS_139239868');
$params = array( $params = array(
'code' => $code, 'code' => $code,
); );
...@@ -80,7 +82,7 @@ class Sms extends Model ...@@ -80,7 +82,7 @@ class Sms extends Model
date_default_timezone_set("Asia/Shanghai");//短信SDK强行转换了时区导致PHP无法识别使用了默认时区,这里需要强制转换回上海时区 date_default_timezone_set("Asia/Shanghai");//短信SDK强行转换了时区导致PHP无法识别使用了默认时区,这里需要强制转换回上海时区
//修改其它验证码的有效性 //修改其它验证码的有效性
self::build()->update(['is_effected' => 0], ['mobile' => $mobile, 'sms_type' => $smsType]); self::build()->update(['is_effected' => 0,'update_time' => timeToDate(time())], ['mobile' => $mobile, 'sms_type' => $smsType]);
// 写入数据库 // 写入数据库
$bool = self::build()->insert([ $bool = self::build()->insert([
'uuid' => uuid(), 'uuid' => uuid(),
...@@ -91,7 +93,7 @@ class Sms extends Model ...@@ -91,7 +93,7 @@ class Sms extends Model
'create_time' => timeToDate(time()), 'create_time' => timeToDate(time()),
'update_time' => timeToDate(time()), 'update_time' => timeToDate(time()),
]); ]);
return $bool; return true;
} }
......
...@@ -91,4 +91,30 @@ class User extends Model ...@@ -91,4 +91,30 @@ class User extends Model
} }
/**
* @author:
* @time: 2019年3月
* description 注册
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function register($request)
{
Db::startTrans();
//创建新用户
$user['uuid'] = uuid();
$user['mobile'] = $request['mobile'];
$user['name'] = replaceToStar($request['mobile']);
$user['create_time'] = timeToDate(time());
$result = self::build()->insert($user);
if (!$result) {
Db::rollback();
return false;
}
Db::commit();
return true;
}
} }
\ No newline at end of file
...@@ -20,10 +20,11 @@ class Base extends Validate ...@@ -20,10 +20,11 @@ class Base extends Validate
'id' => 'require|number|gt:0', 'id' => 'require|number|gt:0',
'content' => 'require|max:255', 'content' => 'require|max:255',
'mobile' => 'require|number|length:11|regex:mobile', 'mobile' => 'require|number|length:11|regex:mobile',
'sms_type' => 'require|in:login,bind,pay_password', 'sms_type' => 'require|in:login,bind,pay_password,pass',
'partner_sms_type' => 'require|in:pass,set_pay,bind_card', 'partner_sms_type' => 'require|in:pass,set_pay,bind_card',
'code' => 'require|max:6', 'code' => 'require|max:6',
'password' => 'require|min:6', 'password' => 'require|min:6|confirm:password2',
'password2' => 'require',
'message_type' => 'require|in:con,chat,system', 'message_type' => 'require|in:con,chat,system',
'province' => 'chsAlpha', 'province' => 'chsAlpha',
'school_name' => 'chsAlpha', 'school_name' => 'chsAlpha',
...@@ -61,6 +62,7 @@ class Base extends Validate ...@@ -61,6 +62,7 @@ class Base extends Validate
'code' => '验证码格式错误', 'code' => '验证码格式错误',
'password.require' => '密码必须', 'password.require' => '密码必须',
'password.min' => '密码过短', 'password.min' => '密码过短',
'password.confirm' => '两次密码输入不一致',
'message_type' => '消息类型错误', 'message_type' => '消息类型错误',
'province' => '省份设置错误', 'province' => '省份设置错误',
'city.json' => '城市设置错误', 'city.json' => '城市设置错误',
...@@ -86,7 +88,7 @@ class Base extends Validate ...@@ -86,7 +88,7 @@ class Base extends Validate
'id' => ['id'], 'id' => ['id'],
'uuid' => ['uuid'], 'uuid' => ['uuid'],
'sendSms' => ['mobile', 'sms_type'], 'sendSms' => ['mobile', 'sms_type'],
'register' => ['mobile','password','password2'],
'sendPartnerSms' => ['mobile', 'sms_type_partner'], 'sendPartnerSms' => ['mobile', 'sms_type_partner'],
'validatePartnerCode' => ['mobile', 'sms_type_partner', 'code'], 'validatePartnerCode' => ['mobile', 'sms_type_partner', 'code'],
......
...@@ -17,11 +17,14 @@ Route::resource(':version/app/User', 'api/:version.app.User');//用户 //注册 ...@@ -17,11 +17,14 @@ Route::resource(':version/app/User', 'api/:version.app.User');//用户 //注册
//restful方法中另外一个方法等。。。 //restful方法中另外一个方法等。。。
Route::rule(':version/app/User/login', 'api/:version.app.User/login');//用户登录 Route::rule(':version/app/User/login', 'api/:version.app.User/login');//用户登录
Route::rule(':version/app/User/validateMobile', 'api/:version.app.User/validateMobile');//验证用户手机号
Route::rule(':version/app/User/sendCode', 'api/:version.app.User/sendCode');//发送验证码
Route::rule(':version/app/User/register', 'api/:version.app.User/register');//注册
Route::rule(':version/app/User/updateToken', 'api/:version.app.User/updateToken');//更新token Route::rule(':version/app/User/updateToken', 'api/:version.app.User/updateToken');//更新token
Route::rule(':version/app/User/publicLogin', 'api/:version.app.User/publicLogin');//公众号授权 Route::rule(':version/app/User/publicLogin', 'api/:version.app.User/publicLogin');//公众号授权
Route::rule(':version/app/User/pointDeal', 'api/:version.app.User/pointDeal');//积分明细 Route::rule(':version/app/User/pointDeal', 'api/:version.app.User/pointDeal');//积分明细
Route::rule(':version/app/User/getShareSign', 'api/:version.app.User/getShareSign'); Route::rule(':version/app/User/getShareSign', 'api/:version.app.User/getShareSign');
Route::rule(':version/app/Send/validate', 'api/:version.app.Send/validate');//验证 Route::rule(':version/app/Send/validate', 'api/:version.app.Send/validateCode');//验证
Route::miss('Error/index'); Route::miss('Error/index');
......
This source diff could not be displayed because it is too large. You can view the blob instead.
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