这一周总体来说学习的知识点不多,更多的是进行实际的练习锻炼,我们花了一天的时间搭建和熟悉Phalcon+Nginx+PHP-FPM开发环境,理解mvc设计模式,然后围绕秀野堂用户登录注册系统设计属于各自的api,我们为了转变思维,熟悉并接受api设计流程足足花了两天的时间,深深感受到理论与实践相结合并不是那么顺畅的事,理论掌握的再好不能做出东西也是白搭。期间我还首次系统了解到微信应用开发流程,了解OAuth2.0认证和授权原理,直到这周周六晚上,我们定下了接下来的10天合力完成秀野堂微信公众号翻新计划,可以预见接下来一周我们的主要精力都将放在微信公众平台开发上。
用户注册、修改信息api
public function reg($app, $responseObj)
{
$user_name = $app->request->getPost('user_name');
$user_phone = $app->request->getPost('user_phone');
$password = $app->request->getPost('password');
$yzm = $app->request->getPost('yzm');
if ($user_phone == '' || $password == '' || $yzm == '') {
$responseObj['status'] = 0;
$responseObj['msg'] = '手机号、密码、验证码均不能为空';
return $responseObj;
}
if(!(preg_match("/1[3456789]{1}d{9}$/", $user_phone))){
$responseObj['status'] = 0;
$responseObj['msg'] = '请检查你的手机号';
return $responseObj;
}
$passwordOK = self::isPasswordOk($password);
// $passwordOK = true;
$authenOK = self::isAuthOK($yzm, $user_phone);
// $authenOK = true;
if ($passwordOK && $authenOK) {
//跟据手机号先判断用户是否存在,如果存在。则不必再注册!
$feedback = self::userRegChecker($app, $user_phone, 'mobile');
// $feedck = 1;
if (!$feedback) {
// TODO:::
// !0 = ?
$responseObj['status'] = 0;
$responseObj['msg'] = '此用户已存在,不必重复注册!';
return $responseObj;
}
$user = new User();
$user->mobile = $user_phone;
$user->password = md5($password);
// $user->yzm = $yzm;
$user->username = $user_name;
//设置用户默认信息
$intN = 1;
// $dataT = date('y-m-d h:i:s',time());
$dataT = "2008-08-03 14:52:10";
$varC = 'a';
$user->email = $varC;
$user->birthday = $dataT;
$user->sex = $intN;
$user->money = $intN;
$user->county_code = $intN;
$user->city_code = $intN;
$user->update_times = $intN;
$user->create_at = $dataT;
$user->avatar_index = $intN;
$user->create_ip = $varC;
$user->last_update_ip = $varC;
$user->deviceid = $varC;
$user->devicetype = $intN;
$user->latitude = $intN;
$user->longitude = $intN;
$user->comefromplatform = $intN;
$user->comefromperson = $intN;
$user->comefromapp = $intN;
$user->PUID = $varC;
$user->PUPWD = $varC;
$user->modi_pwd = $intN;
$user->authroize_string = $varC;
$user->tk = $varC;
$user->level = $intN;
// 存储用户信息
$res = $user->save();
// 判断是否插入成功
if ($res) {
$checkResult = self::userMobileCheckLogic($app, $user_phone, md5($password));
$user_token = self::makeNewToekn($user_phone, $password);
$responseObj['status'] = 1;
$responseObj['msg'] = '注册成功';
$responseObj['data'] = [
'usrname' => strval($checkResult->username),//将数组及类之外的变量类型转换成字符串类型
'token' => strval($user_token),
];
}
else {
$responseObj['status'] = 0;
$responseObj['msg'] = $res;
}
}
else {
$responseObj['status'] = 0;
$responseObj['msg'] = '密码不合法 或 验证码或密码无效';
}
return $responseObj;
}
文章回复删除api
<?php
class DeleteDocRepController extends PhalconMvcController
{
const MANAGER = "root"; //管理员名字
/**
* 检查用户是否存在 @gyc 2016/09/23
* @param [type] $username [description]
* @param [type] $password [description]
* @return boolean [description]
*/
private static function isUserExisit($app, $username, $password)
{
$password = md5($password);
$phql = "SELECT * FROM User WHERE username = '".$username."' and password = '".$password."'";
$rs = $app->modelsManager->executeQuery($phql);
$count = $rs->count();
if ($count) {
return true;
}
else {
return false;
}
}
/**
* 删除文章(仅限管理员(username:root; password:12345678a)) @gyc 2016/09/23
* @param [type] $app [description]
* @param [type] $responseObj [description]
* @return [type] [description]
*/
public function deleteDoc($app, $responseObj)
{
$username = $app->request->getPost('username');
$password = $app->request->getPost('password');
$rid = $app->request->getPost('did');
$rid = (int)$rid;
if ($username !== self::MANAGER) {
$responseObj['status'] = 0;
$responseObj['msg'] = '权限不足';
$responseObj['data'] = '';
return $responseObj;
}
$check = self::isUserExisit($app, $username, $password);
if ($check) {
$phql = "DELETE from Doc WHERE did = ".$rid."";
$query = $app->modelsManager->createQuery($phql);
$rows = $query->execute();
if ($rows->success()) {
$responseObj['status'] = 1;
$responseObj['msg'] = '删除成功!';
$responseObj['data'] = [
'title' => '',
'did' => $rid,
];
}
else {
$responseObj['status'] = 0;
$responseObj['msg'] = '删除失败!';
$responseObj['data'] = '';
}
}
else {
$responseObj['status'] = 0;
$responseObj['msg'] = '权限不足';
$responseObj['data'] = '';
}
return $responseObj;
}
/**
* 删除回复(仅限管理员(username:root; password:12345678a)) @gyc 2016/09/23
* @param [type] $app [description]
* @param [type] $responseObj [description]
* @return [type] [description]
*/
public function deleteReply($app, $responseObj)
{
$username = $app->request->getPost('username');
$password = $app->request->getPost('password');
$rid = $app->request->getPost('rid');
$rid = (int)$rid;
if ($username !== 'root') {
$responseObj['status'] = 0;
$responseObj['msg'] = '权限不足';
$responseObj['data'] = '';
return $responseObj;
}
$check = self::isUserExisit($app, $username, $password);
if ($check) {
$phql = "DELETE from Reply WHERE rid = ".$rid."";
$query = $app->modelsManager->createQuery($phql);
$rows = $query->execute();
if ($rows->success()) {
$responseObj['status'] = 1;
$responseObj['msg'] = '删除成功!';
$responseObj['data'] = [
'title' => '',
'rid' => $rid,
];
}
else {
$responseObj['status'] = 0;
$responseObj['msg'] = '删除失败!';
$responseObj['data'] = '';
}
}
else {
$responseObj['status'] = 0;
$responseObj['msg'] = '权限不足';
$responseObj['data'] = '';
}
return $responseObj;
}
}
相关文章推荐: