public function verify() { $serverAPI = new ServerAPI("25wehl3uwk9bw", "o50nPHUuRaanG"); $result = array("status" => "-999", "message" => "", "startPath" => "", "data" => ""); $username = isset($_POST["username"]) ? $_POST["username"] : ""; $password = isset($_POST["password"]) ? $_POST["password"] : ""; if ($username == '' || $password == '') { $result["message"] = "登入請確實填寫"; } else { $user = $this->Lmodel->verify($username, $password); $token = $serverAPI->getToken($user, $username, "1"); $getdecode = json_decode($token, true); $gettoken = $getdecode['token']; $this->Lmodel->writetoken($gettoken, $username); if ($user != "-1") { @session_start(); $_SESSION["user"] = $user; $result["message"] = $gettoken; $result["status"] = "1"; $result["startPath"] = "index.php/table"; $result["data"] = $this->Lmodel->get_edit($username); } else { if ($user == "-1") { $result["status"] = "-1"; $result["message"] = "資料不正確"; } else { $reult["message"] = "帳號審核中"; } } } echo json_encode($result); }
public function gettoken() { //获取用户信息 $user = ['userId' => 'jlk4565l', 'name' => 'Ironman', 'portraitUri' => 'http%3A%2F%2Fabc.com%2Fmyportrait.jpg']; $userId = $user['userId']; $rongcloud = new \Rongcloud(); $detail = $rongcloud->getDetail($userId); if (!$detail['user_token']) { //请求融云服务器 $serverapi = new \ServerAPI($this->appKey, $this->appSecret); $result = $serverapi->getToken($user['userId'], $user['name'], $user['portraitUri']); $gettoken = json_decode($result, true); //从数据中提取token if (array_key_exists('token', $gettoken)) { $token = $gettoken['token']; $userData = ['userid' => $user['userId'], 'name' => $user['name'], 'portraitUri' => $user['portraitUri'], 'token' => $token]; $rongcloud->addDetail($userData); return $token; } else { print_r($gettoken); } } else { return $detail['user_token']; } }
public function doLogin() { import('Class.ServerAPI', APP_PATH); $mobile = I('mobile'); //手机号码 $password = I('password', '', 'md5'); //密码 //验证手机号码格式 if (!isMobile($mobile)) { $this->ajaxReturn(0, "手机号码格式错误", -1); } //判断该手机号码是否存在 if (M('user')->where(array('mobile' => $mobile))->count('id') == 0) { $this->ajaxReturn(0, "手机号码不存在", -2); } //判断密码是否正确 if (M('user')->where(array('mobile' => $mobile, 'password' => $password))->count('id') == 0) { $this->ajaxReturn(0, "密码错误", -3); } $info = M('user')->where(array('mobile' => $mobile))->find(); $uid = $info['id']; //登录用户ID $islock = M('user')->where(array('id' => $uid))->getField('islock'); if ($islock == 1) { $this->ajaxReturn(0, "该用户被锁定,无法进行登录,请与管理员进行联系", -103); } $allMessage = 0; //查找用户新赞数和新评论数 $userinfo = M('user')->field('headicon,newsupportNum,newcommentNum')->where(array('id' => $uid))->find(); $dialoginfo = M('dialog')->field('newLetterNum')->where("sendId={$uid} or receiveId={$uid}")->select(); for ($i = 0; $i < count($dialoginfo); $i++) { $allMessage += intval($dialoginfo[$i]['newLetterNum']); } $allMessage += intval($userinfo['newsupportNum']); $allMessage += intval($userinfo['newcommentNum']); $returninfo = array(); $returninfo['uid'] = $uid; $returninfo['headicon'] = headiconUrl($userinfo['headicon'], 60); $returninfo['allMessage'] = $allMessage; //appKey : //AppSecret : //此处的AppKey AppSecret 为融云SDK $p = new ServerAPI('', ''); $r = $p->getToken($uid, $info['username'], $returninfo['headicon']); //print_r($r); $returninfo['token'] = $r; $returninfo['userRefresh'] = $p->userRefresh($uid, $info['username'], $returninfo['headicon']); $returninfo['username'] = $info['username']; session('uid', $uid); $this->ajaxReturn($returninfo, "登录成功", 1); }
public function getToken() { $p = new ServerAPI('0vnjpoadnw2uz', 'hg0BUlbxV8a1'); $r = $p->getToken($this->member_id, $this->member_info['member_name'], getMemberAvatarForID($this->member_id)); print_r($r); }
<?php /** * 融云server API 接口 新版 1.0 * Class ServerAPI * @author caolong * @date 2014-12-10 15:30 * @modify 2015-02-02 10:21 * //使用 $p = new ServerAPI('appKey','AppSecret'); $r = $p->getToken('11','22','33'); print_r($r); */ $p = new ServerAPI('pgyu6atqylmeu', 'llja3dGCy9M3'); $r = $p->getToken('44', '55', '66'); print_r($r); class ServerAPI { private $appKey; //appKey private $appSecret; //secret const SERVERAPIURL = 'https://api.cn.ronghub.com'; //请求服务地址 private $format; //数据格式 json/xml /** * 参数初始化 * @param $appKey * @param $appSecret
<?php ini_set('display_errors', 'On'); include "ServerAPI.php"; $server = new ServerAPI('25wehl3uwa6hw', 'wl0oqDn8Ew'); $userName = @$_GET['name']; $userId = md5($userName); $image = 'build/images/1.jpg'; $res = json_decode($server->getToken($userId, $userName, $image), true); if ($res['code'] = 200) { $res['userName'] = $userName; $res['image'] = $image; echo json_encode($res); }
<?php require 'connection.php'; require 'ServerAPI.php'; if (isset($_POST['phonenum']) && isset($_POST['userpwd'])) { $phonenum = htmlspecialchars($_POST['phonenum']); $userpwd = htmlspecialchars($_POST['userpwd']); $sql = "insert into lo_user(phone_num, password) values('" . $phonenum . "','" . $userpwd . "')"; $result = $mysqli->query($sql); if ($result) { $id = $mysqli->insert_id; $defaultUrl = "http://zhiyequan.sinaapp.com/zhiye/logo.png"; $server = new ServerAPI('k51hidwq1b2tb', 'y22Fy12TRh54'); $rets = $server->getToken($id, $username, $defaultUrl); $array = json_decode($rets, true); $tokenSql = "update lo_user set ry_token='" . $array['token'] . "' where id=" . $id; $mysqli->query($tokenSql); $jsonArray = array('cid' => '1001', 'ret' => '1'); echo json_encode($jsonArray); } else { $jsonArray = array('cid' => '1001', 'ret' => '0'); echo json_encode($jsonArray); } $musqli->close(); } else { $jsonArray = array('cid' => '1001', 'ret' => '2'); echo json_encode($jsonArray); }