diff --git a/admin/application/admin/controller/Wechat.php b/admin/application/admin/controller/Wechat.php new file mode 100644 index 0000000..d7cc0e9 --- /dev/null +++ b/admin/application/admin/controller/Wechat.php @@ -0,0 +1,24 @@ +getFriendDetailList(); + dump($res);die; + } +} \ No newline at end of file diff --git a/admin/application/admin/logic/BaseLogic.php b/admin/application/admin/logic/BaseLogic.php new file mode 100644 index 0000000..a52dc5a --- /dev/null +++ b/admin/application/admin/logic/BaseLogic.php @@ -0,0 +1,74 @@ +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; + } + } +} \ No newline at end of file diff --git a/admin/application/admin/logic/GewechatLogic.php b/admin/application/admin/logic/GewechatLogic.php new file mode 100644 index 0000000..69e5b20 --- /dev/null +++ b/admin/application/admin/logic/GewechatLogic.php @@ -0,0 +1,81 @@ + 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; + } +} \ No newline at end of file diff --git a/admin/application/admin/logic/TokenLogic.php b/admin/application/admin/logic/TokenLogic.php new file mode 100644 index 0000000..9b69b32 --- /dev/null +++ b/admin/application/admin/logic/TokenLogic.php @@ -0,0 +1,35 @@ + 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'], + ]; + } +} \ No newline at end of file diff --git a/admin/application/common.php b/admin/application/common.php index 0729207..3dc14f0 100644 --- a/admin/application/common.php +++ b/admin/application/common.php @@ -507,7 +507,3 @@ EOT; return $icon; } } -// 微信接口域名 -function wxApiDomain(){ - return 'https://gewechat-api-test.excn.vip'; -} diff --git a/admin/application/config.php b/admin/application/config.php index 32db731..c568828 100644 --- a/admin/application/config.php +++ b/admin/application/config.php @@ -337,4 +337,7 @@ return [ //API接口地址 'api_url' => 'https://api.fastadmin.net', ], + 'gewechat'=>[ + 'base_url'=>'https://wechat-api-test.excn.vip/v2/api' + ] ];