update
This commit is contained in:
24
admin/application/admin/controller/Wechat.php
Normal file
24
admin/application/admin/controller/Wechat.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2025/3/22} {14:10}
|
||||
*/
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
|
||||
use app\admin\logic\GewechatLogic;
|
||||
use app\common\controller\Backend;
|
||||
|
||||
class Wechat extends Backend
|
||||
{
|
||||
|
||||
//查询微信好友列表
|
||||
function getFriendList()
|
||||
{
|
||||
$res = (new GewechatLogic())->getFriendDetailList();
|
||||
dump($res);die;
|
||||
}
|
||||
}
|
||||
74
admin/application/admin/logic/BaseLogic.php
Normal file
74
admin/application/admin/logic/BaseLogic.php
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2025/3/22} {14:06}
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
class BaseLogic
|
||||
{
|
||||
|
||||
static function curl_post_json(string $url, array $postdata, $header=[]) {
|
||||
$tokenArr = (new TokenLogic())->getToken();
|
||||
$postdata['appId'] = $tokenArr['appId'];
|
||||
$domain = config('gewechat.base_url');
|
||||
$timeout = 4;
|
||||
$connect_timeout = 1;
|
||||
$set_time_limit = 5;
|
||||
if($timeout + $connect_timeout < $set_time_limit) throw new \Exception('脚本超时值必须大于等于连接超时与请求处理超时之和');
|
||||
set_time_limit($set_time_limit);
|
||||
$header = array_merge($header, array(
|
||||
'X-GEWE-TOKEN:' .$tokenArr['token'],
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json'
|
||||
));
|
||||
|
||||
//初始化
|
||||
$curl = curl_init();
|
||||
//设置抓取的url
|
||||
curl_setopt($curl, CURLOPT_URL, $domain.$url);
|
||||
//设置头文件的信息作为数据流输出
|
||||
curl_setopt($curl, CURLOPT_HEADER, 0);
|
||||
//设置获取的信息以文件流的形式返回,而不是直接输出。
|
||||
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
||||
// 超时设置
|
||||
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
|
||||
//发起连接前等待的时间,如果设置为0,则无限等待。
|
||||
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, $connect_timeout);
|
||||
|
||||
// 超时设置,以毫秒为单位
|
||||
// curl_setopt($curl, CURLOPT_TIMEOUT_MS, 500);
|
||||
|
||||
// 设置请求头
|
||||
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
|
||||
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE );
|
||||
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE );
|
||||
|
||||
//设置post方式提交
|
||||
curl_setopt($curl, CURLOPT_POST, 1);
|
||||
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($postdata,JSON_UNESCAPED_UNICODE));
|
||||
//执行命令
|
||||
$data = curl_exec($curl);
|
||||
|
||||
// 显示错误信息
|
||||
if (curl_error($curl)) {
|
||||
throw new \Exception('cURL error: ' . curl_error($curl));
|
||||
//返回错误码
|
||||
//return ['code'=>curl_errno($curl), 'msg'=>curl_error($curl)];
|
||||
} else {
|
||||
//关闭句柄
|
||||
curl_close($curl);
|
||||
// 返回的内容
|
||||
$res = json_decode($data, true);
|
||||
if($res['ret'] != 200){
|
||||
throw new \Exception($res['msg']);
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
}
|
||||
81
admin/application/admin/logic/GewechatLogic.php
Normal file
81
admin/application/admin/logic/GewechatLogic.php
Normal file
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2025/3/22} {14:11}
|
||||
*/
|
||||
|
||||
namespace app\admin\logic;
|
||||
|
||||
|
||||
use wanghua\general_utility_tools_php\http\Curl;
|
||||
use wanghua\general_utility_tools_php\tool\Tools;
|
||||
|
||||
class GewechatLogic extends BaseLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* desc:查询微信好友列表[不带昵称]
|
||||
* author:wh
|
||||
* @return array 返回的是好友的微信id,需要昵称就要调好友查询接口
|
||||
*
|
||||
* array(3) {
|
||||
["ret"] => int(200)
|
||||
["msg"] => string(12) "操作成功"
|
||||
["data"] => array(3) {
|
||||
["friends"] => array(11) {
|
||||
[0] => string(8) "fmessage"
|
||||
[1] => string(9) "medianote"
|
||||
[2] => string(11) "floatbottle"
|
||||
[3] => string(8) "qmessage"
|
||||
[4] => string(6) "qqmail"
|
||||
[5] => string(6) "weixin"
|
||||
[6] => string(19) "wxid_lqhlkt5nq80n12"
|
||||
[7] => string(19) "wxid_xazzsfs57xt321"
|
||||
[8] => string(8) "antas001"
|
||||
[9] => string(19) "wxid_28a3dob3olc522"
|
||||
[10] => string(19) "wxid_b7m1xkqu2s7l22"
|
||||
}
|
||||
["chatrooms"] => array(3) {
|
||||
[0] => string(19) "7037032174@chatroom"
|
||||
[1] => string(20) "52468523601@chatroom"
|
||||
[2] => string(20) "52984126208@chatroom"
|
||||
}
|
||||
["ghs"] => array(1) {
|
||||
[0] => string(15) "gh_3dfda90e39d6"
|
||||
}
|
||||
}
|
||||
}
|
||||
*
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
function getFriendWxIdsList()
|
||||
{
|
||||
$url = '/contacts/fetchContactsList';
|
||||
$post_data = [];
|
||||
Tools::log_to_write_txt(['查询微信好友列表[不带昵称],入参:$post_data'=>$post_data]);
|
||||
$res = self::curl_post_json($url, $post_data);
|
||||
Tools::log_to_write_txt(['查询微信好友列表[不带昵称],出参:$res'=>$res]);
|
||||
return $res;
|
||||
}
|
||||
/**
|
||||
* desc:查询微信好友列表[带昵称]
|
||||
* author:wh
|
||||
* @return array 返回的是好友的微信id,需要昵称就要调好友查询接口
|
||||
* @throws \Exception
|
||||
*/
|
||||
function getFriendDetailList()
|
||||
{
|
||||
$wxids_arr = $this->getFriendWxIdsList();
|
||||
$wxids = $wxids_arr['data']['friends'];
|
||||
$url = '/contacts/getDetailInfo';
|
||||
$post_data = ['wxids'=>$wxids];
|
||||
Tools::log_to_write_txt(['查询微信好友列表[带昵称],入参:$post_data'=>$post_data]);
|
||||
$res = self::curl_post_json($url, $post_data);
|
||||
Tools::log_to_write_txt(['查询微信好友列表[带昵称],出参:$res'=>$res]);
|
||||
return $res;
|
||||
}
|
||||
}
|
||||
35
admin/application/admin/logic/TokenLogic.php
Normal file
35
admin/application/admin/logic/TokenLogic.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
/*
|
||||
* description:
|
||||
* author:wh
|
||||
* email:
|
||||
* createTime:{2025/3/22} {14:04}
|
||||
*/
|
||||
namespace app\admin\logic;
|
||||
|
||||
class TokenLogic extends BaseLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
static function getToken()
|
||||
{
|
||||
$url = 'https://wechat-api-test.excn.vip/vip_groups/auth_info';
|
||||
$res = \wanghua\general_utility_tools_php\http\Curl::curl_post($url, []);
|
||||
$res_data = json_decode($res['data'], true);
|
||||
return [
|
||||
'token' => $res_data['gewe-token'],
|
||||
'appId' => $res_data['appId'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -507,7 +507,3 @@ EOT;
|
||||
return $icon;
|
||||
}
|
||||
}
|
||||
// 微信接口域名
|
||||
function wxApiDomain(){
|
||||
return 'https://gewechat-api-test.excn.vip';
|
||||
}
|
||||
|
||||
@@ -337,4 +337,7 @@ return [
|
||||
//API接口地址
|
||||
'api_url' => 'https://api.fastadmin.net',
|
||||
],
|
||||
'gewechat'=>[
|
||||
'base_url'=>'https://wechat-api-test.excn.vip/v2/api'
|
||||
]
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user