417 lines
14 KiB
PHP
417 lines
14 KiB
PHP
<?php
|
|
header("Access-Control-Allow-Origin: *");
|
|
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, PATCH, DELETE");
|
|
header("Access-Control-Allow-Headers: Content-Type, Authorization, Content-Length, X-Requested-With");
|
|
header("Access-Control-Allow-Credentials: true");
|
|
header("Content-Type: text/html; charset=utf-8");
|
|
|
|
/**
|
|
* 获取用户信息接口
|
|
*/
|
|
use phprs\util\Verify;
|
|
use phprs\util\exceptions\Forbidden;
|
|
use phprs\util\Logger;
|
|
use phprs\util\exceptions\NotFound;
|
|
use phprs\ezsql\Sql;
|
|
use phprs\util\exceptions\BadRequest;
|
|
|
|
require_once 'apiBase.php';
|
|
|
|
/**
|
|
*
|
|
* 获取用户信息接口
|
|
* @path("/user")
|
|
*/
|
|
class User extends apiBase
|
|
{
|
|
/**
|
|
* 通过scode和sid获取用户信息
|
|
* @route({"GET","/"})
|
|
* @param({"appid","$._GET.appid"}) 应用appid
|
|
* @param({"devkey","$._GET.devkey"}) 开发者key
|
|
* @param({"market_key","$._GET.market_key"}) 商家Key
|
|
* @param({"sid","$._GET.sid"}) 服务器返回的sid
|
|
* @param({"scode","$._GET.scode"}) 客户端生成的Scode
|
|
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
|
*/
|
|
public function getUserBySid($appid = "", $devkey = "", $market_key = "", $sid = "", $scode = "")
|
|
{
|
|
// 验证公共参数是否合法
|
|
parent::init($appid, $devkey, $sid, $scode, $market_key);
|
|
$verify_result = parent::verify();
|
|
if (!is_error_api($verify_result))
|
|
{
|
|
if (!empty($market_key))
|
|
{
|
|
if ($this->marketInfo["market_key"] != $market_key)
|
|
{
|
|
$result["error"] = "1";
|
|
$result["error_code"] = 10011;
|
|
$result["msg"] = "指定的SID和market_key不符.";
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
switch ($this->userInfo["auth_type"])
|
|
{
|
|
case AUTHTYPE_WECHAT:
|
|
{
|
|
$userInfoBase = [
|
|
'openid' => $this->userInfo['weixin']['openid'],
|
|
'unionid' => $this->userInfo['weixin']['unionid'],
|
|
'country' => $this->userInfo['weixin']['country'],
|
|
'province' => $this->userInfo['weixin']['province'],
|
|
'city' => $this->userInfo['weixin']['city'],
|
|
'headImage' => $this->userInfo['weixin']['headimgurl'],
|
|
'nickName' => $this->userInfo['weixin']['nickname'],
|
|
'subscribe' => $this->userInfo['weixin']['subscribe'],
|
|
'subscribe_time' => $this->userInfo['weixin']['subscribe_time'],
|
|
'jifen' => $this->userInfo['jifen_account'],
|
|
];
|
|
|
|
$result["usertype"] = $this->userInfo["auth_type"];
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["weixin"];
|
|
return $result;
|
|
}
|
|
|
|
case AUTHTYPE_QQ:
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["qq"]["figureurl_qq_2"];
|
|
$userInfoBase["nickName"] = $this->userInfo["qq"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = $this->userInfo["auth_type"];
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["qq"];
|
|
return $result;
|
|
}
|
|
|
|
case AUTHTYPE_JKX:
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["jkx"]["headimgurl"];
|
|
$userInfoBase["nickName"] = $this->userInfo["jkx"]["realname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = $this->userInfo["auth_type"];
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["jkx"];
|
|
return $result;
|
|
}
|
|
|
|
//case AUTHTYPE_MEMBER:
|
|
//case AUTHTYPE_NIUNIUGAME:
|
|
default:
|
|
{
|
|
$result["usertype"] = $this->userInfo["auth_type"];
|
|
$result["error"] = "0";
|
|
return $result;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return $verify_result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 通过scode和sid获取用户信息
|
|
* @route({"POST","/"})
|
|
* @param({"appid","$._POST.appid"}) 应用appid
|
|
* @param({"devkey","$._POST.devkey"}) 开发者key
|
|
* @param({"market_key","$._POST.market_key"}) 门店Key
|
|
* @param({"sid","$._POST.sid"}) 服务器返回的sid
|
|
* @param({"scode","$._POST.scode"}) 客户端生成的Scode
|
|
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
|
*/
|
|
public function getUserByPostSid($appid = "", $devkey = "", $market_key = "", $sid = "", $scode = "")
|
|
{
|
|
// 验证公共参数是否合法
|
|
parent::init($appid, $devkey, $sid, $scode, $market_key);
|
|
$verify_result = parent::verify();
|
|
if (!is_error_api($verify_result))
|
|
{
|
|
if (!empty($market_key))
|
|
{
|
|
if ($this->marketInfo["market_key"] != $market_key)
|
|
{
|
|
$result["error"] = "1";
|
|
$result["error_code"] = 10011;
|
|
$result["msg"] = "指定的SID和market_key不符.";
|
|
return $result;
|
|
}
|
|
}
|
|
|
|
switch ($this->userInfo["auth_type"])
|
|
{
|
|
case AUTHTYPE_WECHAT:
|
|
{
|
|
$userInfoBase = [
|
|
'openid' => $this->userInfo['weixin']['openid'],
|
|
'unionid' => $this->userInfo['weixin']['unionid'],
|
|
'country' => $this->userInfo['weixin']['country'],
|
|
'province' => $this->userInfo['weixin']['province'],
|
|
'city' => $this->userInfo['weixin']['city'],
|
|
'headImage' => $this->userInfo['weixin']['headimgurl'],
|
|
'nickName' => $this->userInfo['weixin']['nickname'],
|
|
'subscribe' => $this->userInfo['weixin']['subscribe'],
|
|
'subscribe_time' => $this->userInfo['weixin']['subscribe_time'],
|
|
'jifen' => $this->userInfo['jifen_account'],
|
|
];
|
|
|
|
$result["usertype"] = $this->userInfo["auth_type"];
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["weixin"];
|
|
return $result;
|
|
}
|
|
|
|
case AUTHTYPE_QQ:
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["qq"]["figureurl_qq_2"];
|
|
$userInfoBase["nickName"] = $this->userInfo["qq"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = $this->userInfo["auth_type"];
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["qq"];
|
|
return $result;
|
|
}
|
|
|
|
case AUTHTYPE_JKX:
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["jkx"]["headimgurl"];
|
|
$userInfoBase["nickName"] = $this->userInfo["jkx"]["realname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = $this->userInfo["auth_type"];
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["jkx"];
|
|
return $result;
|
|
}
|
|
|
|
//case AUTHTYPE_MEMBER:
|
|
//case AUTHTYPE_NIUNIUGAME:
|
|
default:
|
|
{
|
|
$result["usertype"] = $this->userInfo["auth_type"];
|
|
$result["error"] = "0";
|
|
return $result;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return $verify_result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 直接绑定子账户到主账户
|
|
* @route({"POST","/bind"})
|
|
* @param({"devkey","$._POST.devkey"}) 开发者key
|
|
* @param({"market_key","$._POST.market_key"}) 门店Key
|
|
* @param({"sid","$._POST.sid"}) 服务器返回的sid
|
|
* @param({"scode","$._POST.scode"}) 客户端生成的Scode
|
|
* @param({"mobile_phone","$._POST.mobile_phone"}) 手机号码
|
|
* @param({"email","$._POST.email"}) 邮箱
|
|
* @param({"sign","$._POST.sign"}) 签名值
|
|
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
|
*/
|
|
public function bindMainAccount($devkey = "", $market_key = "", $sid = "", $scode = "", $mobile_phone = "", $email = "", $sign = "")
|
|
{
|
|
// 验证公共参数是否合法
|
|
parent::init($appid, $devkey, $sid, $scode);
|
|
$verify_result = parent::verify();
|
|
if (!is_error_api($verify_result))
|
|
{
|
|
if ($this->userInfo["auth_type"] == 0)
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["weixin"]["headimgurl"];
|
|
$userInfoBase["nickName"] = $this->userInfo["weixin"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = "0";
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["weixin"];
|
|
return $result;
|
|
}
|
|
else
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["qq"]["figureurl_qq_2"];
|
|
$userInfoBase["nickName"] = $this->userInfo["qq"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = "1";
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["qq"];
|
|
return $result;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return $verify_result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 判断用户是否已经绑定为主账户
|
|
* @route({"POST","/bind/check"})
|
|
* @param({"devkey","$._POST.devkey"}) 开发者key
|
|
* @param({"market_key","$._POST.market_key"}) 门店Key
|
|
* @param({"sid","$._POST.sid"}) 服务器返回的sid
|
|
* @param({"scode","$._POST.scode"}) 客户端生成的Scode
|
|
* @param({"sign","$._POST.sign"}) 签名值
|
|
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
|
*/
|
|
public function isBindMainAccount($devkey = "", $market_key = "", $sid = "", $scode = "", $sign = "")
|
|
{
|
|
// 验证公共参数是否合法
|
|
parent::init($appid, $devkey, $sid, $scode);
|
|
$verify_result = parent::verify();
|
|
if (!is_error_api($verify_result))
|
|
{
|
|
if ($this->userInfo["auth_type"] == 0)
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["weixin"]["headimgurl"];
|
|
$userInfoBase["nickName"] = $this->userInfo["weixin"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = "0";
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["weixin"];
|
|
return $result;
|
|
}
|
|
else
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["qq"]["figureurl_qq_2"];
|
|
$userInfoBase["nickName"] = $this->userInfo["qq"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = "1";
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["qq"];
|
|
return $result;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return $verify_result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 将子账户从主账户中解绑
|
|
* @route({"POST","/unbind"})
|
|
* @param({"devkey","$._POST.devkey"}) 开发者key
|
|
* @param({"market_key","$._POST.market_key"}) 门店Key
|
|
* @param({"sid","$._POST.sid"}) 服务器返回的sid
|
|
* @param({"scode","$._POST.scode"}) 客户端生成的Scode
|
|
* @param({"sign","$._POST.sign"}) 签名值
|
|
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
|
*/
|
|
public function unbindFromMainAccount($devkey = "", $market_key = "", $sid = "", $scode = "", $sign = "")
|
|
{
|
|
// 验证公共参数是否合法
|
|
parent::init($appid, $devkey, $sid, $scode);
|
|
$verify_result = parent::verify();
|
|
if (!is_error_api($verify_result))
|
|
{
|
|
if ($this->userInfo["auth_type"] == 0)
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["weixin"]["headimgurl"];
|
|
$userInfoBase["nickName"] = $this->userInfo["weixin"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = "0";
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["weixin"];
|
|
return $result;
|
|
}
|
|
else
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["qq"]["figureurl_qq_2"];
|
|
$userInfoBase["nickName"] = $this->userInfo["qq"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = "1";
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["qq"];
|
|
return $result;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return $verify_result;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取子账户的其他门店的账户信息,需要关联主账户
|
|
* @route({"POST","/other"})
|
|
* @param({"devkey","$._POST.devkey"}) 开发者key
|
|
* @param({"market_key","$._POST.market_key"}) 门店Key
|
|
* @param({"sid","$._POST.sid"}) 服务器返回的sid
|
|
* @param({"scode","$._POST.scode"}) 客户端生成的Scode
|
|
* @param({"sign","$._POST.sign"}) 签名值
|
|
* @throws({"phprs\util\exceptions\Forbidden","res", "403 Forbidden",{"error":"Forbidden"}}) cookie不可用
|
|
*/
|
|
public function getOtherMarket($devkey = "", $market_key = "", $sid = "", $scode = "", $sign = "")
|
|
{
|
|
// 验证公共参数是否合法
|
|
parent::init($appid, $devkey, $sid, $scode);
|
|
$verify_result = parent::verify();
|
|
if (!is_error_api($verify_result))
|
|
{
|
|
if ($this->userInfo["auth_type"] == 0)
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["weixin"]["headimgurl"];
|
|
$userInfoBase["nickName"] = $this->userInfo["weixin"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = "0";
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["weixin"];
|
|
return $result;
|
|
}
|
|
else
|
|
{
|
|
$userInfoBase = array();
|
|
$userInfoBase["headImage"] = $this->userInfo["qq"]["figureurl_qq_2"];
|
|
$userInfoBase["nickName"] = $this->userInfo["qq"]["nickname"];
|
|
$userInfoBase["jifen"] = $this->userInfo["jifen_account"];
|
|
$result["usertype"] = "1";
|
|
$result["error"] = "0";
|
|
$result["data"] = $userInfoBase;
|
|
$result["dataContent"] = $this->userInfo["qq"];
|
|
return $result;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return $verify_result;
|
|
}
|
|
}
|
|
|
|
/** @inject("ioc_factory") */
|
|
private $factory;
|
|
/**
|
|
* @property({"default":"@db"})
|
|
* @var PDO
|
|
*/
|
|
public $db;
|
|
// 此处删除了代码
|
|
} |