修改短信接口

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
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; //用户名不合法
@ -213,35 +214,32 @@ 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) {
public function smsVerify($phone = '' , $code = '', $type = 2){
$taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $code);
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
if($type == 1){
$this->respondSuccess('正确');
} else {
return true;
}
} else {
switch ($result['code']) {
case 1021:{
$this->respondError('验证码已失效,请重新获取');
};break;
case 1022:{
$this->respondError('验证码不正确,请重新输入');
};break;
default:
$this->respondError($result['msg']);
if($type == 1){
$this->respondError($result['message']);
} else {
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 {
@ -398,24 +399,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 +440,23 @@ 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));
public function sms_verify($phone = '' ,$code = '', $type = 2){
if($result['code']==200) {
if($type==1){
$this->set_message(200,"success","正确");
}else{
$taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $vcode);
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
if ($type == 2) {
return true;
}
$this->set_message(200, "success", "验证成功");
} 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']);
if ($type == 2) {
return false;
}
$this->set_message(1000, "fail", $result['message']);
}
}
/**

@ -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
{
@ -577,17 +578,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;
}
@ -619,21 +618,18 @@ class UserController extends BaseController
*/
public function checksafecode($phone, $vcode, $flag = true)
{
$result = R('Common/Sms/verify_sms_code', array($phone, $vcode, false));
if ($result['code'] == 200) {
$taskClient = new TaskClient();
$result = $taskClient->checkSms($phone, $vcode);
$data = [];
if ($result['code'] == TaskClient::SUCCESS) {
$data['status'] = 1;
if ($flag) {
echo json_encode($data);
exit;
}
} else {
$data['status'] = 0;
$data['msg'] = $result['msg'];
}
$data['msg'] = $result['message'];
echo json_encode($data);
exit;
}
}
/**
* 忘记密码

Loading…
Cancel
Save