修改短信接口

master
ELF 5 years ago
parent 3559d91a32
commit e4daff1be8

@ -0,0 +1,38 @@
<?php
namespace Base\Tool;
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')
{
$result = $this->post('/message/sms-send', ['mobile' => $mobile, 'type' => $type]);
}
public function checkSms($mobile, $code)
{
$result = $this->post('/message/sms-check', ['mobile' => $mobile, 'code' => $code]);
}
}

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

@ -4,6 +4,7 @@ use Org\Ipa365SDK\Ipa365;
use User\Api\MemberApi; use User\Api\MemberApi;
use Think\Log; use Think\Log;
use Base\Service\ApplyService; use Base\Service\ApplyService;
use Base\Tool\TaskClient;
class CommonController extends BaseController { class CommonController extends BaseController {
const USER_NOT_ILLEGAL = -1; //用户名不合法 const USER_NOT_ILLEGAL = -1; //用户名不合法
@ -213,35 +214,32 @@ class CommonController extends BaseController {
//发送验证码 //发送验证码
public function sendPhoneCode() public function sendPhoneCode()
{ {
$phone = I("phone"); $phone = I('phone');
$result = R('Common/Sms/send_sms_code', [$phone, 10, false]); $taskClient = new TaskClient();
$result = $taskClient->sendSms($phone);
if ($result['code'] == 200) { $data = [];
$this->setData($result['data'])->respondSuccess('发送成功'); if ($result['code'] == TaskClient::SUCCESS) {
$this->respondSuccess('发送成功');
} else { } else {
$this->respondError('发送失败'); $this->respondError('发送失败');
} }
} }
public function smsVerify($phone="" , $code="", $type=2){ public function smsVerify($phone = '' , $code = '', $type = 2){
$taskClient = new TaskClient();
$result = R('Common/Sms/verify_sms_code', [$phone, $code, false]); $result = $taskClient->checkSms($phone, $code);
if($result['code'] == 200) { $data = [];
if($type==1){ if ($result['code'] == TaskClient::SUCCESS) {
if($type == 1){
$this->respondSuccess('正确'); $this->respondSuccess('正确');
}else{ } else {
return true; return true;
} }
} else { } else {
switch ($result['code']) { if($type == 1){
case 1021:{ $this->respondError($result['message']);
$this->respondError('验证码已失效,请重新获取'); } else {
};break; return false;
case 1022:{
$this->respondError('验证码不正确,请重新输入');
};break;
default:
$this->respondError($result['msg']);
} }
} }
} }

@ -3,6 +3,7 @@ namespace Mobile\Controller;
use Org\Ipa365SDK\Ipa365; use Org\Ipa365SDK\Ipa365;
use Org\WeixinSDK\Weixin; use Org\WeixinSDK\Weixin;
use User\Api\MemberApi; use User\Api\MemberApi;
use Base\Tool\TaskClient;
use Think\Log; use Think\Log;
class SsgController extends BaseController { class SsgController extends BaseController {
@ -398,24 +399,24 @@ class SsgController extends BaseController {
session("user_auth",null); session("user_auth",null);
redirect(U("ssg/login")); redirect(U("ssg/login"));
} }
//发送验证码 //发送验证码
public function sendPhoneCode() public function sendPhoneCode()
{ {
$phone = I("phone"); $phone = I('phone');
$result = R('Common/Sms/send_sms_code', array($phone, 10, false)); $taskClient = new TaskClient();
$result = $taskClient->sendSms($phone);
if ($result['code'] == 200) { $data = [];
if ($result['code'] == TaskClient::SUCCESS) {
$data['status'] = 1; $data['status'] = 1;
$data['data'] = $result['data'];
} else { } else {
$data['status'] = 0; $data['status'] = 0;
} }
$data['msg'] = $result['message'];
$data['msg'] = $result['msg'];
echo json_encode($data); echo json_encode($data);
exit; exit;
} }
public function timediffs($begin_time, $end_time) { public function timediffs($begin_time, $end_time) {
if ($begin_time < $end_time) { if ($begin_time < $end_time) {
$starttime = $begin_time; $starttime = $begin_time;
@ -439,29 +440,23 @@ class SsgController extends BaseController {
$res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs); $res = array("day" => $days, "hour" => $hours, "min" => $mins, "sec" => $secs);
return $res; return $res;
} }
public function sms_verify($phone="" ,$code="",$type=2){
$result = R('Common/Sms/verify_sms_code',array($phone,$code,false)); public function sms_verify($phone = '' ,$code = '', $type = 2){
if($result['code']==200) { $taskClient = new TaskClient();
if($type==1){ $result = $taskClient->checkSms($phone, $vcode);
$this->set_message(200,"success","正确"); $data = [];
}else{ if ($result['code'] == TaskClient::SUCCESS) {
if ($type == 2) {
return true; return true;
} }
$this->set_message(200, "success", "验证成功");
} else { } else {
switch ($result['code']) { if ($type == 2) {
case 1021:{ return false;
$this->set_message(1010,"fail","验证码已失效,请重新获取");
};break;
case 1022:{
$this->set_message(1022,"fail","验证码不正确,请重新输入");
};break;
default:
$this->set_message($result['code'],"fail",$result['msg']);
} }
$this->set_message(1000, "fail", $result['message']);
} }
} }
/** /**

@ -8,6 +8,7 @@ use Org\UcenterSDK\Ucservice;
use User\Api\MemberApi; use User\Api\MemberApi;
use Admin\Model\PointTypeModel; use Admin\Model\PointTypeModel;
use Think\Log; use Think\Log;
use Base\Tool\TaskClient;
class UserController extends BaseController class UserController extends BaseController
{ {
@ -577,17 +578,15 @@ class UserController extends BaseController
*/ */
public function telsafecode($phone = '', $delay = 10, $flag = true) public function telsafecode($phone = '', $delay = 10, $flag = true)
{ {
$result = R('Common/Sms/send_sms_code', array($phone, $delay, false)); $taskClient = new TaskClient();
$result = $taskClient->sendSms($phone);
if ($result['code'] == 200) { $data = [];
if ($result['code'] == TaskClient::SUCCESS) {
$data['status'] = 1; $data['status'] = 1;
$data['data'] = $result['data'];
} else { } else {
$data['status'] = 0; $data['status'] = 0;
} }
$data['msg'] = $result['message'];
$data['msg'] = $result['msg'];
echo json_encode($data); echo json_encode($data);
exit; exit;
} }
@ -619,21 +618,18 @@ class UserController extends BaseController
*/ */
public function checksafecode($phone, $vcode, $flag = true) public function checksafecode($phone, $vcode, $flag = true)
{ {
$result = R('Common/Sms/verify_sms_code', array($phone, $vcode, false)); $taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $vcode);
if ($result['code'] == 200) { $data = [];
if ($result['code'] == TaskClient::SUCCESS) {
$data['status'] = 1; $data['status'] = 1;
if ($flag) {
echo json_encode($data);
exit;
}
} else { } else {
$data['status'] = 0; $data['status'] = 0;
$data['msg'] = $result['msg']; }
$data['msg'] = $result['message'];
echo json_encode($data); echo json_encode($data);
exit; exit;
} }
}
/** /**
* 忘记密码 * 忘记密码

Loading…
Cancel
Save