开发uTools插件时要与uToolsApi交互,这里写一个获取uTools用户信息的api对接示例:
class UToolsService {
private $plugin_id;
private $secret;
private $baseurl = "https://open.u-tools.cn";
private $baseinfo_uri = "/baseinfo";
public function __construct($plugin_id, $secret) {
$this->plugin_id = $plugin_id;
$this->secret = $secret;
}
/**
* 获取登录基础信息
* @param array $access_token
* @return mixed
*/
public function getLoginBaseInfo($access_token) {
$params = [
"access_token" => $access_token,
];
$data = $this->sendGetRequest($this->baseinfo_uri, $params);
return $data;
}
/**
* 获取完整参数
* @param array $params
* @return array
*/
private function getFullParams(array $params) {
$params["plugin_id"] = $this->plugin_id;
$params["timestamp"] = time();
ksort($params);
$str = http_build_query($params);
$params["sign"] = hash_hmac("sha256", $str, $this->secret);
return $params;
}
/**
* 发送请求
* @param string $uri
* @param array $params
* @return mixed
*/
private function sendGetRequest($uri, $params) {
$params = $this->getFullParams($params);
$url = $this->baseurl . $uri . "?" . http_build_query($params);
$header = [
"Accept:application/json"
];
$result = curl($url, null, $header);
return $result;
}
}
curl方法自行实现啊,这里就不写上去了。