Thinkphp仿京东手机找回密码【原创

来源:https://www.sucaihuo.com/php/2076.html 2017-06-01 17:53浏览(2085) 收藏

演示部分的手机短信无法获取,需要设置创蓝短信账户和密码,验证码输入 sucaihuo ,即可验证通过。

Thinkphp仿京东手机短信找回密码,Thinkphp忘记密码整个流程已走通,分为三步骤:验证身份、设置新密码、完成。
Thinkphp仿京东手机找回密码
分类:PHP > Thinkphp 难易:初级
下载资源 下载积分: 240 积分

Thinkphp路由配置 Application\Home\Conf\config.php

return array(
    'URL_ROUTER_ON' => true,
    'URL_ROUTE_RULES' => array(
        'forget' => 'Pwd/find',
        'sendtip' => 'Pwd/send_tip',
    ),
);

安装方法:

1.导入数据demo_2076.sql
2.修改数据库配置文件 :Application\Common\Conf\config.php

创蓝接口短信账号和密码设置(Application\Common\Org\Lan.class.php):

$this->api_account = '';
$this->api_password = '';

发送注册验证码

$code = I('post.code');
$mtype = I('post.mtype');
$phone = I('post.phone');
if ($mtype != 'change_bank_code') {
    if (strtolower($code) != $_SESSION["helloweba_gg"]) {
        echo json_encode(array("error" => "验证码有误!", "code" => "verify_code_wrong"));
        exit;
    }
}
if (!in_array($mtype, array("reg_code", "find_pwd_code", "find_paypwd_code", 'change_bank_code'))) {
    getError("验证码类型有误!", 'code_type_error');
    exit;
}

if ($mtype == 'reg_code') {
    $info = M("user")->field("id")->where("phone = '" . $phone . "'")->find();
    if ($info) {
        $rs = array('code' => -1, "error" => "该手机号已被注册");
        echo json_encode($rs);
        exit;
    }
}
$content = "注册验证码为:" . rand(1000, 9999);
$rs = sendMobile($phone, $content, $mtype);
if ($rs['code'] == 101) {
    $rs['error'] = '短信配置有误!';
}
echo json_encode($rs);

验证短信验证码

$phone = I('post.phone');
$code = I('post.code');
if ($code == 'sucaihuo') {
    echo json_encode(array("code" => 200, "rand_set" => "sucaihuo"));
    exit;
}
$pattern = "/^1[3|4|5|7|8][0-9]{9}$/";
if (preg_match($pattern, $phone) == 0) {
    echo json_encode(array("code" => "phone_error", "result" => "手机格式不正确"));
    exit;
}
$detail_short = getSendPhoneInfo($phone, 'find_pwd_code');
if ($detail_short['rand'] == $code) {
    $rs['code'] = 200;
    $rs['rand_set'] = $detail_short['rand'] . $detail_short['id'];
} else {
    $rs['error'] = "短信验证码错误";
}
echo json_encode($rs);

设置新密码

$phone = I('post.phone'); //用户传过来的邮箱
$rand_set = I('post.rand_set'); //用户的随机数
if ($rand_set == 'sucaihuo') {
    M("user")->where("phone = '" . $phone . "'")->save(array("pwd" => md5(I('post.pwd'))));
    echo json_encode(array("code" => 200));
    exit;
}
$id = substr($rand_set, 4);
$code = substr($rand_set, 0, 4);
$detail_short = M("shorts")->field("content,id")->where("phone='" . $phone . "' AND id = '" . $id . "'")->find();
$code_content = getContentCode($detail_short['content']);
if ($code_content == $code && $code != '') {
    $data['pwd'] = md5(I('post.pwd')); //用户传过来的pwd
    M("user")->where("phone = '" . $phone . "'")->save($data);
    $rs['code'] = 200;
    M("shorts")->where("id = " . $detail_short['id'] . "")->delete();
} else {
    $rs['error'] = "你的短信验证码已使用或已失效,请重新找回密码!~";
}
echo json_encode($rs);

用户表:user 和短信记录表 shorts

DROP TABLE IF EXISTS `mall_shorts`;
CREATE TABLE `mall_shorts` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `uid` int(11) DEFAULT NULL,
  `ip` varchar(20) NOT NULL,
  `phone` text NOT NULL,
  `content` varchar(500) NOT NULL,
  `error` varchar(500) DEFAULT NULL,
  `num` int(6) NOT NULL,
  `state` int(4) DEFAULT '0',
  `code` varchar(30) NOT NULL,
  `addtime` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

-- ----------------------------
-- Records of mall_shorts
-- ----------------------------

-- ----------------------------
-- Table structure for mall_user
-- ----------------------------
DROP TABLE IF EXISTS `mall_user`;
CREATE TABLE `mall_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '用户的ID',
  `name` varchar(50) NOT NULL COMMENT '用户账号',
  `pwd` varchar(50) NOT NULL COMMENT '密码',
  `phone` varchar(30) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=593 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;

-- ----------------------------
-- Records of mall_user
-- ----------------------------
INSERT INTO `mall_user` VALUES ('1', '13812345678', '96e79218965eb72c92a549dd5a330112', '13812345678');
INSERT INTO `mall_user` VALUES ('2', '13811111111', 'e10adc3949ba59abbe56e057f20f883e', '13811111111');
声明:本文为原创文章,如需转载,请注明来源sucaihuo.com并保留原文链接:https://www.sucaihuo.com/php/2076.html
评论0
头像

系统已开启自动识别垃圾评论机制,识别到的自动封号,下载出错或者资源有问题请联系全栈客服QQ 1915635791

1 2