Merge branch 'feature/site_sms' into release

master
ELF 5 years ago
commit 5c0a38c02a

@ -0,0 +1,40 @@
<?php
namespace Base\Tool;
use GuzzleHttp\Client;
class TaskClient
{
const SUCCESS = '0000';
protected $client;
public function __construct()
{
$this->client = new Client([
'base_uri' => C('TASK_URL'),
'timeout' => 10.0,
]);
}
protected function post($uri, $data)
{
$response = $this->client->post($uri, [
'verify' => false,
'form_params' => $data
]);
$result = (string)$response->getBody();
return json_decode($result, true);
}
public function sendSms($mobile, $type = 'common')
{
return $this->post('/message/sms-send', ['mobile' => $mobile, 'type' => $type]);
}
public function checkSms($mobile, $code)
{
return $this->post('/message/sms-check', ['mobile' => $mobile, 'code' => $code]);
}
}

@ -1,5 +1,6 @@
<?php
namespace Common\Controller;
use Think\Controller;
use Org\XiguSDK\Xigu;
use Think\Exception;

@ -4,6 +4,7 @@ use Org\Ipa365SDK\Ipa365;
use User\Api\MemberApi;
use Think\Log;
use Base\Service\ApplyService;
use Base\Tool\TaskClient;
class CommonController extends BaseController {
const USER_NOT_ILLEGAL = -1; //用户名不合法
@ -105,7 +106,9 @@ class CommonController extends BaseController {
$gameId = $params['game_id'] ?? 0;
#验证短信验证码
$this->smsVerify($params['account'], $params['verify_code']);
if (!$this->smsVerify($params['account'], $params['verify_code'])) {
$this->respondError('验证失败');
}
$res = $this->doRegister($params['account'], $params['password'], $params['account'], $promoteId, 4, 2, $gameId);
if(empty($res)){
@ -126,7 +129,9 @@ class CommonController extends BaseController {
if (empty($params)) {
$this->respondError('基础信息不能为空');
}
$this->smsVerify($params['account'], $params['verify_code']);
if (!$this->smsVerify($params['account'], $params['verify_code'])) {
$this->respondError('验证失败');
}
//更新密码
$userApi = new MemberApi();
$userInfo = M("user", "tab_")->where("account = '".$params['account']."'")->find();
@ -213,36 +218,26 @@ class CommonController extends BaseController {
//发送验证码
public function sendPhoneCode()
{
$phone = I("phone");
$result = R('Common/Sms/send_sms_code', [$phone, 10, false]);
if ($result['code'] == 200) {
$this->setData($result['data'])->respondSuccess('发送成功');
$phone = I('phone');
$taskClient = new TaskClient();
$result = $taskClient->sendSms($phone);
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
$this->respondSuccess('发送成功');
} else {
$this->respondError('发送失败');
}
}
public function smsVerify($phone="" , $code="", $type=2){
$result = R('Common/Sms/verify_sms_code', [$phone, $code, false]);
if($result['code'] == 200) {
if($type==1){
$this->respondSuccess('正确');
}else{
return true;
}
public function smsVerify($phone = '' , $code = '')
{
$taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $code);
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
return true;
} else {
switch ($result['code']) {
case 1021:{
$this->respondError('验证码已失效,请重新获取');
};break;
case 1022:{
$this->respondError('验证码不正确,请重新输入');
};break;
default:
$this->respondError($result['msg']);
}
return false;
}
}
}

@ -3,6 +3,7 @@ namespace Mobile\Controller;
use Org\Ipa365SDK\Ipa365;
use Org\WeixinSDK\Weixin;
use User\Api\MemberApi;
use Base\Tool\TaskClient;
use Think\Log;
class SsgController extends BaseController {
@ -180,7 +181,9 @@ class SsgController extends BaseController {
$this -> set_message(1001, "fail", "注册数据不能为空");
}
#验证短信验证码
$this -> sms_verify($user['account'], $user['code']);
if (!$this->sms_verify($user['account'], $user['code'])) {
$this->set_message(1000, "fail", '验证失败');
}
$res = $this -> doRegister($user['account'],$user['password'],$user['account'],$promoteId,4,2, $game_id);
if(empty($res)){
@ -200,7 +203,9 @@ class SsgController extends BaseController {
if (empty($user)) {
$this -> set_message(1001, "fail", "基础信息不能为空");
}
$this -> sms_verify($user['account'], $user['code']);
if (!$this->sms_verify($user['account'], $user['code'])) {
$this->set_message(1000, "fail", '验证失败');
}
//更新密码
$userApi = new MemberApi();
$userInfo = M("user","tab_")->where("account = '".$user['account']."'")->find();
@ -398,24 +403,24 @@ class SsgController extends BaseController {
session("user_auth",null);
redirect(U("ssg/login"));
}
//发送验证码
public function sendPhoneCode()
{
$phone = I("phone");
$result = R('Common/Sms/send_sms_code', array($phone, 10, false));
if ($result['code'] == 200) {
$phone = I('phone');
$taskClient = new TaskClient();
$result = $taskClient->sendSms($phone);
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
$data['status'] = 1;
$data['data'] = $result['data'];
} else {
$data['status'] = 0;
}
$data['msg'] = $result['msg'];
$data['msg'] = $result['message'];
echo json_encode($data);
exit;
}
public function timediffs($begin_time, $end_time) {
if ($begin_time < $end_time) {
$starttime = $begin_time;
@ -439,29 +444,17 @@ class SsgController extends BaseController {
$res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs);
return $res;
}
public function sms_verify($phone="" ,$code="",$type=2){
$result = R('Common/Sms/verify_sms_code',array($phone,$code,false));
if($result['code']==200) {
if($type==1){
$this->set_message(200,"success","正确");
}else{
return true;
}
public function sms_verify($phone , $code)
{
$taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $code);
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
return true;
} else {
switch ($result['code']) {
case 1021:{
$this->set_message(1010,"fail","验证码已失效,请重新获取");
};break;
case 1022:{
$this->set_message(1022,"fail","验证码不正确,请重新输入");
};break;
default:
$this->set_message($result['code'],"fail",$result['msg']);
}
return false;
}
}
/**

@ -8,6 +8,7 @@ use Org\UcenterSDK\Ucservice;
use User\Api\MemberApi;
use Admin\Model\PointTypeModel;
use Think\Log;
use Base\Tool\TaskClient;
class UserController extends BaseController
{
@ -337,7 +338,9 @@ class UserController extends BaseController
$password = $safeinfo['password'];
$sex = $safeinfo['sex'];
$this->checksafecode($phone, $safecode, false);
if (!$this->checksafecode($phone, $safecode)) {
return $this->ajaxReturn(array('status' => 0, 'msg' => '验证失败'));
}
/**是否开启ucenter**/
@ -577,17 +580,15 @@ class UserController extends BaseController
*/
public function telsafecode($phone = '', $delay = 10, $flag = true)
{
$result = R('Common/Sms/send_sms_code', array($phone, $delay, false));
if ($result['code'] == 200) {
$taskClient = new TaskClient();
$result = $taskClient->sendSms($phone);
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
$data['status'] = 1;
$data['data'] = $result['data'];
} else {
$data['status'] = 0;
}
$data['msg'] = $result['msg'];
$data['msg'] = $result['message'];
echo json_encode($data);
exit;
}
@ -614,24 +615,16 @@ class UserController extends BaseController
/**
* 手机安全码验证
* @param bool $flag true 用于直接异步请求 false 用于方法调用
* @param [type] $vcode [description]
*/
public function checksafecode($phone, $vcode, $flag = true)
public function checksafecode($phone, $code)
{
$result = R('Common/Sms/verify_sms_code', array($phone, $vcode, false));
if ($result['code'] == 200) {
$data['status'] = 1;
if ($flag) {
echo json_encode($data);
exit;
}
$taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $code);
$data = [];
if ($result && $result['code'] == TaskClient::SUCCESS) {
return true;
} else {
$data['status'] = 0;
$data['msg'] = $result['msg'];
echo json_encode($data);
exit;
return false;
}
}
@ -645,8 +638,11 @@ class UserController extends BaseController
if (IS_POST) {
$phone = $_POST['phone'];
$code = $_REQUEST['code'];
$this->checksafecode($phone, $_REQUEST['code'], false);
if (!$this->checksafecode($phone, $code)) {
return $this->ajaxReturn(array('status' => 0, 'msg' => '验证失败'));
}
$this->success('验证成功', U('User/forget1', array('phone' => $phone)));
@ -662,8 +658,16 @@ class UserController extends BaseController
if (IS_POST) {
$new_pwd = $_REQUEST['new_pwd'];
$u_uid['phone'] = $_REQUEST['phone'];
$code = $_REQUEST['code'];
//验证短信验证码
$this->checksafecode($u_uid['phone'], $_REQUEST['code'], false);
if (!$this->checksafecode($u_uid['phone'], $code)) {
$this->error("验证失败");
}
$user = M('user', 'tab_')->where($u_uid)->find();
if (!$user) {
$this->error("账号不存在");
}
$result = M('user', 'tab_')->where($u_uid)->setField('password', think_ucenter_md5($new_pwd, UC_AUTH_KEY));
if ($result != false) {
$this->success("修改成功", U('User/login'));
@ -700,7 +704,6 @@ class UserController extends BaseController
exit;
}
$result = $this->telsafecode($account);
}
/**
@ -880,7 +883,10 @@ class UserController extends BaseController
if (IS_POST) {
$code = I("post.scode");
$phone = I("post.phone");
$this->checksafecode($phone, $code, false);
if (!$this->checksafecode($phone, $code)) {
echo json_encode(array('status' => 0, 'msg' => '验证失败'));
exit();
}
if (!$user['phone']) {
$where['account'] = $phone;
$where['phone'] = $phone;

@ -124,7 +124,7 @@
code:$("#code").val(),
new_pwd:new_pwd
},
success:function(result){
success:function(result) {
if(result.status == 1){
pmsg.msg("修改成功");
setTimeout(function () {

Loading…
Cancel
Save