function show() { /* echo date("Y-m-d",541008000); $model = new Model(); $sql = "UPDATE student SET age=284 WHERE id=1"; $result = $model->execute($sql); var_dump($result);*/ /* 1451790866 $time = 1452096000; echo timeToString($time);*/ /* $uid = $_REQUEST['uid']; $strTitle = '你有新的消息了'; $strText = 'PLAN有新的版本了,赶快去下载,有红包相送哦'; echo "uid=$uid title=$strTitle text=$strText<br><br>"; getuiSendDeviceUnicast($uid,$strTitle,$strText); newOrderNotification('1369','1367');*/ /* Vendor('GetuiPush.GetuiPush'); show(); pushMessageToSingle(); echo __ROOT__; strtotime("-2 day"); die(); echo strtotime('1984-03-07')."<br>"; $passwd = "0093chenrenjie"; echo sha1($passwd);*/ /* curl -X POST -i "https://a1.easemob.com/plan/plan/users" -d '{"username":"******","password":"******"}' $url = 'https://a1.easemob.com/plan/chatdemoui/token'; $data['grant_type'] = 'client_credentials'; $data['client_id'] = 'YXA6zOQxoEyAEeWJs5OjVUur7g'; $data['client_secret'] = 'YXA63rRzrvgElyfAR2uGrEouPUf0-x0'; $result = http_post($url,json_encode($data)); var_dump($result);*/ Vendor('EasemobApi.EasemobApi'); $e = new \Easemob(); //获取token $token = $e->getToken(); echo $token; //注册单个用户 $result = $e->registerUser('1111111', sha1('123456'), 'kaka'); echo json_encode($result); /* $data[] = array('username'=>'aaabbb','password'=>sha1('123456')); $data[] = array('username'=>'aaaccc','password'=>sha1('123456')); $result = $e->registerManyUser($data); echo json_encode($result);*/ // $e->deleteUser(); }
function register() { $param = json_decode(file_get_contents('php://input'), true); //用户名 $username = $param['username']; if (empty($username)) { err_ret(-205, 'lack of param', '缺少参数'); } //密码 $password = $param['password']; if (empty($password)) { err_ret(-205, 'lack of param', '缺少参数'); } //昵称 $nicker = $param['nicker']; if (empty($nicker)) { err_ret(-205, 'lack of param', '缺少参数'); } $gender = $param['gender']; if ($gender != 0 && $gender != 1) { $gender = 0; //默认 男 } //头像 $header = $param['header']; if (empty($header)) { $header = ''; } //短信验证码 $verifycode = $param['verifycode']; if (empty($verifycode)) { err_ret(-306, 'lack of param verfiy', '验证码不能为空'); } //注册时间 $regtime = time(); $model = new Model('user_info'); //判断手机号是否注册过 $data['username'] = $username; $result = $model->where($data)->select(); if (count($result) > 0) { err_ret(-305, 'phone number is registered', '手机号已经注册过'); } //数据库插入一条记录,生成新用户 $data['username'] = $username; $data['password'] = $password; $data['nicker'] = $nicker; $data['header'] = $header; $data['regtime'] = $regtime; $data['gender'] = $gender; $lastId = $model->add($data); if (!$lastId) { err_ret(-311, 'register add new user failed', '注册添加新用户时失败'); } //删除此用户临时短信验证码 $delete_model = new Model('verify_tmp'); $condition['phone'] = $username; $condition['verifycode'] = $verifycode; $delete_model->where($condition)->delete(); // 删除id为最大的用户的短信验证码 //生成用户token并保存 $token = token_generate($lastId); $where['id'] = $lastId; $save['xtoken'] = $token; $count = $model->where($where)->save($save); if ($count == 0) { err_ret(-501, 'save token failed', '保存token失败'); } //注册环信 Vendor('EasemobApi.EasemobApi'); $ease = new \Easemob(); $result_arr = $ease->registerUser($username, $password, $nicker); if (isset($result_arr['error'])) { $delete_data['username'] = $username; $model->where($delete_data)->delete(); err_ret(-205, 'failed registered', '注册失败'); } $info['errno'] = 0; $info['xtoken'] = $token; $info['data']['nicker'] = $nicker; $info['data']['header'] = $header; $info['data']['uid'] = $lastId; echo json_encode($info); }