修改接口支持app访问
This commit is contained in:
@@ -19,11 +19,13 @@ abstract class BaseController extends REST_Controller
|
||||
|
||||
const CODE_BM = 'bm'; //报名
|
||||
const CODE_BANK = 'bank'; //绑定银行卡
|
||||
const CODE_LOGIN = 'login'; //登录验证码
|
||||
|
||||
//短信验证码类型
|
||||
protected $codeCachePre = [
|
||||
self::CODE_BM => 'AUTO_BM_%s',
|
||||
self::CODE_BANK => 'AUTO_BANK_%s'
|
||||
self::CODE_BANK => 'AUTO_BANK_%s',
|
||||
self::CODE_LOGIN => 'AUTO_LOGIN_%s'
|
||||
];
|
||||
const SERVICE_PHONE = '13388887777';
|
||||
const APP_ID = 1; //应用id
|
||||
|
||||
@@ -82,24 +82,37 @@ class Config extends BaseController
|
||||
];
|
||||
$latitude = $this->input_param('latitude');
|
||||
$longitude = $this->input_param('longitude');
|
||||
if (!$latitude || !$longitude) {
|
||||
$this->return_json('参数错误');
|
||||
}
|
||||
$tcGeocoder = new TcGeocoder();
|
||||
$result = $tcGeocoder->reverseGeocode($latitude, $longitude);
|
||||
debug_log("解析结果:".json_encode($result),'local.log');
|
||||
if (!$result) {
|
||||
$this->return_json('地址解析失败');
|
||||
}
|
||||
$adcode = $result['ad_info']['adcode'];
|
||||
$row = $this->area_model->get(['county_id' => $adcode]);
|
||||
if ($row) {
|
||||
$data = [
|
||||
'provinceId' => $row['province_id'],
|
||||
'provinceName' => $row['province_name'],
|
||||
'cityId' => $row['city_id'],
|
||||
'cityName' => $row['city_name'],
|
||||
];
|
||||
$cityId = $this->input_param('cityId');
|
||||
if($cityId){
|
||||
$row = $this->area_model->get(['city_id' => $cityId]);
|
||||
if ($row) {
|
||||
$data = [
|
||||
'provinceId' => $row['province_id'],
|
||||
'provinceName' => $row['province_name'],
|
||||
'cityId' => $row['city_id'],
|
||||
'cityName' => $row['city_name'],
|
||||
];
|
||||
}
|
||||
}else{
|
||||
if (!$latitude || !$longitude) {
|
||||
$this->return_json('参数错误');
|
||||
}
|
||||
$tcGeocoder = new TcGeocoder();
|
||||
$result = $tcGeocoder->reverseGeocode($latitude, $longitude);
|
||||
debug_log("解析结果:".json_encode($result),'local.log');
|
||||
if (!$result) {
|
||||
$this->return_json('地址解析失败');
|
||||
}
|
||||
$adcode = $result['ad_info']['adcode'];
|
||||
$row = $this->area_model->get(['county_id' => $adcode]);
|
||||
if ($row) {
|
||||
$data = [
|
||||
'provinceId' => $row['province_id'],
|
||||
'provinceName' => $row['province_name'],
|
||||
'cityId' => $row['city_id'],
|
||||
'cityName' => $row['city_name'],
|
||||
];
|
||||
}
|
||||
}
|
||||
$this->return_response($data);
|
||||
}
|
||||
|
||||
@@ -48,7 +48,42 @@ class Login extends BaseController
|
||||
}
|
||||
|
||||
/** @var MyResponse $response */
|
||||
$response = $this->autoUserModel->initUser($ret['openid'], $accountId, $from, $otherInfo);
|
||||
$response = $this->autoUserModel->initUser('', $ret['openid'], $accountId, $from, $otherInfo);
|
||||
if (!$response->isSuccess()) {
|
||||
$this->return_json($response->getMessage());
|
||||
}
|
||||
$responseData = $response->getData();
|
||||
$data = [
|
||||
'Authorization' => generateToken([$responseData['id'], $responseData['orgId'] ?: 0], 'jwt_key_auto'),
|
||||
];
|
||||
$this->return_response($data, API_CODE_SUCCESS);
|
||||
} catch (Exception $e) {
|
||||
$this->return_json($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function mobile_post()
|
||||
{
|
||||
try {
|
||||
$accountId = $this->input_param('accountId');
|
||||
$from = $this->input_param('from');
|
||||
$mobile = $this->input_param('mobile');
|
||||
$code = $this->input_param('code');
|
||||
if (!mobile_valid($mobile)) {
|
||||
throw new Exception('请输入正确手机号');
|
||||
}
|
||||
//校验验证码
|
||||
$redis = &load_cache();
|
||||
$key = $this->getCodeCacheKey(self::CODE_LOGIN, $mobile);
|
||||
$cacheCode = $redis->get($key);
|
||||
if (!$cacheCode || $cacheCode != $code) {
|
||||
throw new Exception("验证码错误");
|
||||
}
|
||||
/** @var MyResponse $response */
|
||||
$response = $this->autoUserModel->initUser($mobile, '', $accountId, $from);
|
||||
if (!$response->isSuccess()) {
|
||||
$this->return_json($response->getMessage());
|
||||
}
|
||||
|
||||
@@ -31,11 +31,14 @@ class Sms extends BaseController
|
||||
case self::CODE_BANK:
|
||||
$cacheKey = $this->getCodeCacheKey(self::CODE_BANK, $mobile);
|
||||
break;
|
||||
case self::CODE_LOGIN:
|
||||
$cacheKey = $this->getCodeCacheKey(self::CODE_LOGIN, $mobile);
|
||||
break;
|
||||
default:
|
||||
$this->return_json('验证码类型错误');
|
||||
}
|
||||
$redis = &load_cache();
|
||||
// $key = $this->getCodeCacheKey(self::CODE_BM, $mobile);
|
||||
$code = $this->get($cacheKey);
|
||||
if (!$redis->get($cacheKey)) {
|
||||
$this->load->helper('string');
|
||||
$code = random_string('numeric', 4);
|
||||
@@ -46,6 +49,16 @@ class Sms extends BaseController
|
||||
ems_sms($mobile, $content);
|
||||
$redis->save($cacheKey, $code, 600);
|
||||
}
|
||||
$this->return_response([], '发送成功');
|
||||
$this->return_response([], '发送成功' . $code);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function login_post()
|
||||
{
|
||||
$this->index_post();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -19,28 +19,39 @@ class Coupon extends BaseController
|
||||
public function index_post()
|
||||
{
|
||||
try {
|
||||
$user = $this->autoUserModel->get(['id' => $this->userId]);
|
||||
if (!$this->userId) {
|
||||
throw new Exception("请先登录");
|
||||
}
|
||||
$couponId = $this->post('couponId');
|
||||
$mobile = $this->post('mobile');
|
||||
$code = $this->post('code');
|
||||
$cityId = $this->post('cityId');
|
||||
if (!$couponId || !$mobile || !$code) {
|
||||
if (!$couponId) {
|
||||
throw new Exception("参数错误");
|
||||
}
|
||||
//校验验证码
|
||||
$redis = &load_cache();
|
||||
$key = $this->getCodeCacheKey(self::CODE_BM, $mobile);
|
||||
$cacheCode = $redis->get($key);
|
||||
if (!$cacheCode || $cacheCode != $code) {
|
||||
throw new Exception("验证码错误");
|
||||
if (checkua() == 'wx') {
|
||||
$mobile = $this->post('mobile');
|
||||
$code = $this->post('code');
|
||||
if (!$mobile) {
|
||||
throw new Exception("请填写手机号");
|
||||
}
|
||||
//校验验证码
|
||||
$redis = &load_cache();
|
||||
$key = $this->getCodeCacheKey(self::CODE_BM, $mobile);
|
||||
$cacheCode = $redis->get($key);
|
||||
if (!$cacheCode || $cacheCode != $code) {
|
||||
throw new Exception("验证码错误");
|
||||
}
|
||||
$redis->delete($key);
|
||||
} else {
|
||||
$mobile = $user['mobile'];
|
||||
if (!$mobile) {
|
||||
throw new Exception("请先绑定手机号");
|
||||
}
|
||||
}
|
||||
$result = $this->auto_user_coupon_model->getCoupon(self::APP_ID, $this->userId, $couponId, $mobile, $cityId);
|
||||
if (!$result->isSuccess()) {
|
||||
throw new Exception($result->getMessage());
|
||||
}
|
||||
$redis->delete($key);
|
||||
$this->return_response([], '领取成功');
|
||||
} catch (Exception $e) {
|
||||
$this->return_json($e->getMessage());
|
||||
|
||||
@@ -26,9 +26,8 @@ class ApiAuthHook
|
||||
];
|
||||
//h5白名单
|
||||
$this->route_un_auto = [
|
||||
'auto/config/*', 'auto/login/*', 'auto/area/*',
|
||||
'auto/car/brand', 'auto/car/product/list',
|
||||
'auto/car/coupon/bizs',
|
||||
'auto/config/*', 'auto/login/*', 'auto/area/*', 'auto/car/brand', 'auto/car/product/list',
|
||||
'auto/car/coupon/bizs','auto/visit','auto/brand/*','auto/car/product/detail','auto/sms/login'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ class Auto_user_model extends HD_Model
|
||||
* @param array $otherInfo
|
||||
* @return MyResponse
|
||||
*/
|
||||
public function initUser($openid, $accountId, $from = '', $otherInfo = [])
|
||||
public function initUser($mobile, $openid, $accountId, $from = '', $otherInfo = [])
|
||||
{
|
||||
try {
|
||||
$userModel = self::MAP_USER_MODEL[$from];
|
||||
@@ -35,9 +35,10 @@ class Auto_user_model extends HD_Model
|
||||
} else {
|
||||
$this->load->model('agent/pingan/pingan_users_model', 'pingAnUsers');
|
||||
}
|
||||
$user = $this->get(['openid' => $openid]);
|
||||
$user = $this->get(['mobile' => $mobile, 'openid' => $openid]);
|
||||
if (!$user) {
|
||||
$user = [
|
||||
'mobile' => $mobile,
|
||||
'openid' => $openid,
|
||||
'createTime' => date('Y-m-d H:i:s'),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user