53 lines
1.6 KiB
PHP
53 lines
1.6 KiB
PHP
<?php
|
||
/*
|
||
* description:
|
||
* author:wh
|
||
* email:
|
||
* createTime:{2025/3/22} {14:04}
|
||
*/
|
||
namespace app\api\logic;
|
||
|
||
class TokenWechatLogic extends BaseWechatLogic
|
||
{
|
||
public function __construct()
|
||
{
|
||
}
|
||
|
||
/**
|
||
* desc:
|
||
*
|
||
* array(3) {
|
||
["code"] => int(200)
|
||
["msg"] => string(7) "cURL ok"
|
||
["data"] => string(84) "{"gewe-token":"8bd053cb84f24770ae4df11441500427","appId":"wx_N3vKyMW8nl41epbcu891k"}"
|
||
}
|
||
* author:wh
|
||
* @return string
|
||
* @throws \Exception
|
||
*/
|
||
function getToken($url ='')
|
||
{
|
||
if (empty($url)){
|
||
throw new \Exception('获取url失败');
|
||
}
|
||
|
||
// $url = 'https://wechat-api-test.excn.vip/vip_groups/auth_info';
|
||
$base_url = parse_url($url);
|
||
if (!is_array($base_url) || !isset($base_url['scheme']) || !isset($base_url['host'])) {
|
||
throw new \Exception("URL解析失败: 输入的URL格式不正确 - {$url}");
|
||
}
|
||
$url = $base_url['scheme'].'://'.$base_url['host'].'/vip_groups/auth_info';
|
||
$res = \wanghua\general_utility_tools_php\http\Curl::curl_post($url, []);
|
||
if (empty($res['data'])) {
|
||
throw new \Exception("获取数据失败: 接口返回为空 - URL: {$url}");
|
||
}
|
||
$res_data = json_decode($res['data'], true);
|
||
if (!is_array($res_data) || !isset($res_data['gewe-token']) || !isset($res_data['appId'])) {
|
||
throw new \Exception("JSON解析失败或缺少必要字段: 返回数据 - " . print_r($res_data, true));
|
||
}
|
||
return [
|
||
'token' => $res_data['gewe-token'],
|
||
'appId' => $res_data['appId'],
|
||
];
|
||
}
|
||
} |