JAVA——根据QQ群号得到idkey以及QQ群加群链接[网页版本]解决方案
生活随笔
收集整理的這篇文章主要介紹了
JAVA——根据QQ群号得到idkey以及QQ群加群链接[网页版本]解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
基本概念
QQ群idkey:沒有官方解釋,在QQ群推廣頁面可以獲得。
QQ群加群鏈接:即帶有QQ群idkey的一個特殊URL。
問題描述
?QQ群推廣官網:https://qun.qq.com/join.html
可以獲得當前登入QQ號所管理的QQ群的?idkey ,但是不能自定義QQ群號并獲取QQ群的?idkey。
問題分析?
?經分析獲取QQ群的?idkey 的API如下所示:
GET請求:
參數如下所示:
注:QQ群列表以 ","(英文逗號)分割。?
必須的Request Headers如下所示:?
但查找資料過程中發現替換成
http://qun.qq.com/join.html亦可。?
Request示例:?
Response示例:
?
解決方案
JAVA版本
源代碼?
注:?HttpClientUtils為HttpClient工具類,參考:https://shentuzhigang.blog.csdn.net/article/details/104274609
package club.zstuca.myzstu.provider;import club.zstuca.myzstu.httpclient.HttpClientUtils; import org.json.JSONArray; import org.json.JSONObject; import org.springframework.stereotype.Component;import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map;/*** @Author ShenTuZhiGang* @Version 1.0.0* @Date 2020-02-18 17:58*/ @Component public class QQProvider {private static String QQQUN_JOIN_URL = "http://qun.qq.com/join.html";private static String QQQUN_GET_WPA_URL ="http://qun.qq.com/proxy/domain/shang.qq.com/wpa/g_wpa_get";public static Map<String,String> getQQqunWPA(List<String> guins){Map<String,String> headers=new HashMap<>();headers.put("Referer",QQQUN_JOIN_URL);Map<String,String> params=new HashMap<>();params.put("t","" + new Date().getTime());String guin_str="";if(guins !=null){for (String guin:guins){if (!guin_str.equals("")){guin_str = guin_str + ",";}guin_str = guin_str + guin;}}params.put("guin",guin_str);Map<String,String> guinANDkey = new HashMap<>();String Response;try {Response = HttpClientUtils.doGetRequest(QQQUN_GET_WPA_URL,headers,params);}catch (Exception e){e.printStackTrace();return guinANDkey;}try {JSONObject jsonObject = new JSONObject(Response);JSONObject result = jsonObject.getJSONObject("result");JSONArray data= result.getJSONArray("data");for (int i = 0; i < data.length(); ++i) {JSONObject item = (JSONObject) data.get(i);guinANDkey.put(item.getString("guin"),item.getString("key"));}}catch (Exception e){e.printStackTrace();return guinANDkey;}return guinANDkey;} }?JAVA TEST?
package club.zstuca.myzstu;import club.zstuca.myzstu.httpclient.HttpClientUtils; import club.zstuca.myzstu.provider.QQProvider; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;import java.util.*;/*** @Author ShenTuZhiGang* @Version 1.0.0* @Date 2020-02-18 17:34*/ @SpringBootTest public class QQqunTEST {@Autowiredprivate QQProvider qqProvider;private String testGuin = "110";//測試QQ群@Testpublic void qqqun(){Map<String,String> params=new HashMap<>();Map<String,String> headers=new HashMap<>();params.put("guin",testGuin);params.put("t","" + new Date().getTime());headers.put("Referer","http://qun.qq.com/join.html");//headers.put("Host","qun.qq.com");String s=HttpClientUtils.doGetRequest("http://qun.qq.com/proxy/domain/shang.qq.com/wpa/g_wpa_get",headers,params);System.out.println(s);}@Testpublic void qqqun2(){String[] temps=testGuin.split(",");List<String> list = new ArrayList<>();for(String string: temps ){list.add(string);}Map<String, String> qQqunWPA = qqProvider.getQQqunWPA(list);System.out.println(qQqunWPA.get(QQ群號));} }?
PHP版本
版本一
<?php $qqun=urlencode('['.'334802'.']');//群號 $t=time()*1000; $url="http://wp.qq.com/wpa/g_wpa_get?guin=".$qqun."&t=".$t; $ResArray=json_decode(curl_request($url,'post'),true); foreach ($ResArray['result']['data'] as $k => $v) {$array['guin']=$v['guin']; //群號$array['idkey']=$v['key']; // idkey$array['url']='http://wp.qq.com/wpa/qunwpa?idkey='.$v['key'];//加群鏈接 } print_r($array); //參數1:訪問的URL,參數2:post數據(不填則為GET),參數3:提交的$cookies,參數4:是否返回$cookiesfunction curl_request($url,$post='',$cookie='', $returnCookie=0){$curl = curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)');curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);curl_setopt($curl, CURLOPT_AUTOREFERER, 1);curl_setopt($curl, CURLOPT_REFERER, "http://XXX");if($post) {curl_setopt($curl, CURLOPT_POST, 1);curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));}if($cookie) {curl_setopt($curl, CURLOPT_COOKIE, $cookie);}curl_setopt($curl, CURLOPT_HEADER, $returnCookie);curl_setopt($curl, CURLOPT_TIMEOUT, 10);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);$data = curl_exec($curl);if (curl_errno($curl)) {return curl_error($curl);}curl_close($curl);if($returnCookie){list($header, $body) = explode("\r\n\r\n", $data, 2);preg_match_all("/Set\-Cookie:([^;]*);/", $header, $matches);$info['cookie'] = substr($matches[1][0], 1);$info['content'] = $body;return $info;}else{return $data;} }版本二
<?php /*免IDKEY加群 *Author:消失的彩虹海 */ error_reporting(0); function get_curl($url, $post=0, $referer=0, $cookie=0, $header=0, $ua=0, $nobaody=0) {$ch = curl_init();curl_setopt($ch, CURLOPT_URL, $url);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);if ($post) {curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, $post);}if ($header) {curl_setopt($ch, CURLOPT_HEADER, true);}if ($cookie) {curl_setopt($ch, CURLOPT_COOKIE, $cookie);}if ($referer) {curl_setopt($ch, CURLOPT_REFERER, $referer);}if ($ua) {curl_setopt($ch, CURLOPT_USERAGENT, $ua);}else {curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");}if ($nobaody) {curl_setopt($ch, CURLOPT_NOBODY, 1);}curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);$ret = curl_exec($ch);curl_close($ch);return $ret; } $qun=isset($_GET['qun'])?$_GET['qun']:'326026548'; $data=get_curl('http://shang.qq.com/wpa/g_wpa_get?guin='.$qun.'&t='.time(),0,'http://qun.qq.com/join.html'); $arr=json_decode($data,true); $idkey=$arr['result']['data'][0]['key']; $url='http://shang.qq.com/wpa/qunwpa?idkey='.$idkey; header("Location:{$url}"); exit; ?>參考文章
https://www.52pojie.cn/forum.php?mod=viewthread&tid=826998
https://blog.youngxj.cn/544.html
總結
以上是生活随笔為你收集整理的JAVA——根据QQ群号得到idkey以及QQ群加群链接[网页版本]解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 身份证号码有效性检测算法 ( js版 转
- 下一篇: angular路由传递参数_Angula