添加虚拟注册
parent
4af138bb9d
commit
d00a119b8b
@ -0,0 +1,122 @@
|
||||
<?php
|
||||
|
||||
namespace Sdk\Controller;
|
||||
|
||||
use Think\Controller;
|
||||
use User\Api\MemberApi;
|
||||
use Think\Log;
|
||||
|
||||
class SimulationRegisterController extends Controller
|
||||
{
|
||||
public function _initialize()
|
||||
{
|
||||
C(api('Config/lists'));
|
||||
$data = I('request.');
|
||||
unset($data['PHPSESSID']);
|
||||
if (empty($data['time_stamp']) || time() - 60 * 10 > $data['time_stamp']) {
|
||||
return $this->set_message(2002, 'fail,', '链接已过期');
|
||||
} else {
|
||||
$sign = $data['sign'];
|
||||
unset($data['sign']);
|
||||
ksort($data);
|
||||
reset($data);
|
||||
$str = "";
|
||||
foreach ($data as $k => $v) {
|
||||
$str = $str . $k . "=" . $v;
|
||||
}
|
||||
$str = $str . 'key=' . C('REGISTER_KEY');
|
||||
if (md5($str) != $sign) {
|
||||
return $this->set_message(2001, 'fail,', '参数错误');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function user_register()
|
||||
{
|
||||
|
||||
#获取SDK上POST方式传过来的数据 然后base64解密 然后将json字符串转化成数组
|
||||
$user = I('request.');
|
||||
$user['register_type'] = 7;//模拟注册
|
||||
#判断数据是否为空
|
||||
if (empty($user)) {
|
||||
$this->set_message(1001, "fail", "注册数据不能为空");
|
||||
}
|
||||
Log::write('mn_user_register:' . date('Y-m-d H:i:s') . ' ---- ' . json_encode($user), 'INFO');
|
||||
/**是否开启ucenter**/
|
||||
if (C('UC_OPEN') == 1) {
|
||||
//Ucenter注册
|
||||
//1.验证本平台是否存在账号
|
||||
$is_user_info = M('user', 'tab_')->where(['account' => $user['account']])->find();
|
||||
if (!empty($is_user_info)) {
|
||||
$this->set_message(1017, "fail", "用户名已存在");
|
||||
}
|
||||
//2.验证其他平台是否存在账号
|
||||
$domain = C('UC_OTHER_WEB_URL');
|
||||
if (!empty($domain)) {
|
||||
$url = "http://{$domain}/Api/user/checkUserName?account={$user['account']}";
|
||||
$check_res = json_decode(file_get_contents($url), true);
|
||||
if ($check_res['status'] == 0) {
|
||||
$this->set_message(1017, "fail", "用户名已存在");
|
||||
}
|
||||
}
|
||||
//3.ucenter注册账号
|
||||
$ucresult = uc_user_checkname($user['account']);
|
||||
if ($ucresult == -1) {
|
||||
$this->set_message(0, "fail", "用户名不合法");
|
||||
} elseif ($ucresult == -2) {
|
||||
$this->set_message(0, "fail", "包含要允许注册的词语");
|
||||
} elseif ($ucresult == -3) {
|
||||
$this->set_message(1017, "fail", "用户名已存在");
|
||||
} else {
|
||||
//同步ucenter注册
|
||||
cus_uc_register($user['account'], $user['password'], $user['account'] . '@vlcms.com');
|
||||
}
|
||||
}
|
||||
$this->reg_data($user);
|
||||
|
||||
}
|
||||
|
||||
|
||||
//注册信息
|
||||
private function reg_data($user, $type = 1)
|
||||
{
|
||||
|
||||
#实例化用户接口
|
||||
$userApi = new MemberApi();
|
||||
|
||||
if (!preg_match('/^[0-9a-zA-Z]{6,12}$/', $user['password'])) {
|
||||
$this->set_message(1027, "fail", "密码长度为6-12位");
|
||||
}
|
||||
if (strlen($user['account']) < 6 || strlen($user['account']) > 15) {
|
||||
$this->set_message(1027, "fail", "账号长度为6-15位");
|
||||
} elseif (!preg_match('/^[0-9]+[a-zA-Z]+[0-9a-zA-Z]*|[a-zA-Z]+[0-9]+[0-9a-zA-Z]*$/', $user['account'])) {
|
||||
$this->set_message(1027, "fail", "账号必须字母数字组合");
|
||||
}
|
||||
$result = $userApi->sdk_register_($user['account'], $user['password'], 1, $user['register_type'], $user['promote_id'], get_promote_name($user['promote_id']), $phone = "", $user["game_id"], get_game_name($user["game_id"]), $user['sdk_version'], $user['device_type'], $user['unique_code']);
|
||||
if ($result > 0) {
|
||||
$this->set_message(200, "success", "注册成功");
|
||||
} else {
|
||||
|
||||
switch ($result) {
|
||||
case -3:
|
||||
$this->set_message(1017, "fail", "用户名已存在");
|
||||
break;
|
||||
default:
|
||||
$this->set_message(1027, "fail", "注册失败");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function set_message($status=0,$return_code="fail",$return_msg="操作失败"){
|
||||
$msg = array(
|
||||
"status" => $status,
|
||||
"return_code" => $return_code,
|
||||
"return_msg" => $return_msg
|
||||
);
|
||||
$this->ajaxReturn($msg);
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue