录医案
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

77 lines
2.2 KiB

<?php
/**
*
*/
include_once(SERVER_ROOT."/model/mBase.php");
class mUser extends mBase {
private $obj;
private $tbl;
public function __construct() {
$this->obj = new dUser();
$this->tbl = 'tcm_user';
}
public function getOpenid($code) {
$appid = MP_APPID;
$secret = MP_SECRET;
$get_openid_url = sprintf(MP_GET_OPENID_HREF, $appid, $secret, $code);
$jsonres = $this->getCUrl($get_openid_url);
$get_openid_res = json_decode($jsonres, true);
if (empty($get_openid_res['openid'])) {
$this->setError('获取openid失败');
$tool_obj = new qTool();
$tool_obj->trackLog('tcm', $get_openid_url . "|" .$jsonres, sprintf(LOG_TRACK_SAVE_PATH, date('Y-m-d'), 'tcm_get_openid'));
return false;
}
return $get_openid_res['openid'];
}
public function getUserByOpenid($openid) {
return $this->obj->select($this->tbl, array('sql' => '`openid`=?','vals' => array($openid)));
}
function createUniqueUid($openid) {
$uuid = uniqid($openid, true);
$hash = hash('sha256', $uuid);
$decimal = base_convert(substr($hash, 0, 16), 16, 10);
return substr($decimal, 0, 10);
}
public function getUserByUid($uid) {
return $this->obj->select($this->tbl, array('sql' => '`uid`=?','vals' => array($uid)));
}
public function createUser($info) {
return $this->obj->insert($this->tbl, $info);
}
public function getToken($uid) {
$secretKey = JWT_KEY;
$timestamp = time();
$data = $uid . '|' . $timestamp;
$token = hash_hmac('sha256', $data, $secretKey);
return base64_encode($data . '|' . $token);
}
public function validateToken($uid, $token) {
$secretKey = JWT_KEY;
$decodedToken = base64_decode($token);
list($valid_uid, $timestamp, $tokenHash) = explode('|', $decodedToken);
$data = $uid . '|' . $timestamp;
$validToken = hash_hmac('sha256', $data, $secretKey);
if (hash_equals($validToken, $tokenHash)) {
if (time() - $timestamp < 7200) {
return true;
}
}
return false;
}
}