白云点缀的蓝 发表于 2021-6-15 16:15

参考某东618工具接口写了几个请求




import com.alibaba.fastjson.JSONObject;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.junit.Test;

import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
public class test {
    public StringGets_token() throws Exception {
      String s_token="";
      HashMap<String, Object> stringStringHashMap = new HashMap<>();
      stringStringHashMap.put("lang","chs");
      stringStringHashMap.put("appid","300");
      stringStringHashMap.put("returnurl","https://wq.jd.com/passport/LoginRedirect?state=1621999066&returnurl=https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport");
      stringStringHashMap.put("source","wq_passport");
      JSONObject jsonObject=new JSONObject(stringStringHashMap);
      HttpClient httpClient= HttpClients.createDefault();
      HttpPost httpRequest=new HttpPost("https://plogin.m.jd.com/cgi-bin/mm/new_login_entrance");
      HttpUriRequest httpUriRequest=new HttpPost();
      StringEntity stringEntity=new StringEntity(jsonObject.toString(), StandardCharsets.UTF_8);
      stringEntity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/x-www-form-urlencoded"));
      httpRequest.setEntity(stringEntity);
      httpRequest.setHeader("Accept","application/json, text/plain, */*");
      httpRequest.setHeader("Referrer","https://plogin.m.jd.com/cgi-bin/mm/new_login_entrance?lang=chs&appid=300&returnurl=https://wq.jd.com/passport/LoginRedirect?state%3D1621999066%26returnurl%3Dhttps://home.m.jd.com/myJd/newhome.action?sceneval%3D2%26ufc%3D%26/myJd/home.action%26source%3Dwq_passport&source=wq_passport");
      httpRequest.setHeader("Accept","application/json, text/plain, */*");
      HttpResponse execute = httpClient.execute(httpRequest);
      if(execute.getEntity()!=null){
            String s = EntityUtils.toString(execute.getEntity());
            System.out.println(s);
            JSONObject jsonObject1 = JSONObject.parseObject(s);
            s_token = (String) jsonObject1.get("s_token");
            System.out.println(s_token);
      }
      return s_token;
//      System.out.println();
//      System.out.println(execute.toString());
    }
    public String GetToken() throws Exception {
      String s1 = Gets_token();
      CloseableHttpClient aDefault = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost("https://plogin.m.jd.com/cgi-bin/m/tmauthreflogurl?lang=chs&appid=300&returnurl=https://wq.jd.com/passport/LoginRedirect?state%3D1621999066%26returnurl%3Dhttps://home.m.jd.com/myJd/newhome.action?sceneval%3D2%26ufc%3D%26/myJd/home.action%26source%3Dwq_passport&source=wq_passport&s_token="+s1+"");
    httpPost.setHeader("User-Agent","Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.87 Safari/537.36");
    httpPost.setHeader("cookie","guid=79e9eef8e8c5c01a96f2e9c1504431093434233a23d605c088b6ebf4b4bfd4f6; EXPIRES=Wed, 08-Jun-2022 02:48:21 GMT; PATH=/; DOMAIN=.plogin.m.jd.com, lang=chs; PATH=/; DOMAIN=.plogin.m.jd.com, lsid=uyabtasbwcc8yjm5yqkndd2z3bb8zmiuks5e2xpza289luek; PATH=/; DOMAIN=.plogin.m.jd.com, lstoken=7ffzku2i; EXPIRES=Thu, 08-Jul-2021 02:48:21 GMT; PATH=/; DOMAIN=.plogin.m.jd.com, lsid=; Domain=.jd.com; Path=/; Expires=Fri, 02-Jan-1970 00:00:00 GMT, guid=; Domain=.jd.com; Path=/; Expires=Fri, 02-Jan-1970 00:00:00 GMT");
    httpPost.setHeader("referer","https://plogin.m.jd.com/cgi-bin/m/tmauthreflogurl?s_token=e16h3zv1");
    httpPost.setHeader("Accept","application/json, text/plain, */*");
    HashMap<String, Object> stringObjectHashMap = new HashMap<>();
    stringObjectHashMap.put("lang","chs");
    stringObjectHashMap.put("appid","300");
    stringObjectHashMap.put("returnurl","https://wq.jd.com/passport/LoginRedirect?state=1621999066&returnurl=https://home.m.jd.com/myJd/newhome.action?sceneval=2&ufc=&/myJd/home.action&source=wq_passport");
    stringObjectHashMap.put("source","wq_passport");
    stringObjectHashMap.put("s_token",s1);
      JSONObject jsonObject1 = new JSONObject(stringObjectHashMap);
      StringEntity stringEntity = new StringEntity(jsonObject1.toString());
    stringEntity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"application/x-www-form-urlencoded"));
    httpPost.setEntity(stringEntity);
    CloseableHttpResponse execute = aDefault.execute(httpPost);
    HttpEntity entity = execute.getEntity();
String Token="";
    if (entity != null) {
      String s = EntityUtils.toString(entity);
      JSONObject jsonObject = JSONObject.parseObject(s);
      System.out.println(s);
      Token= (String) jsonObject.get("Token");
      System.out.println(Token);
    }
      return Token;
//    return "1";
}
public void GetQr_code()throws Exception{
    String s = GetToken();
    CloseableHttpClient aDefault = HttpClients.createDefault();
    HttpPost httpPost = new HttpPost();
    httpPost.setURI(new URI("https://plogin.m.jd.com/cgi-bin/m/tmauth?client_type=m&appid=300&token="+s));
    HashMap<String, Object> stringObjectHashMap = new HashMap<>();
    stringObjectHashMap.put("appid","300");
    stringObjectHashMap.put("client_type","m");
    stringObjectHashMap.put("token",s);
    JSONObject jsonObject = new JSONObject(stringObjectHashMap);
    StringEntity stringEntity = new StringEntity(jsonObject.toString());
    stringEntity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,"multipart/form-data"));
    httpPost.setEntity(stringEntity);
    aDefault.execute(httpPost);
}

    public static void main(String[] args) throws Exception{
      new test().GetQr_code();
    }
}


依赖相关


<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>untitled</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
      <maven.compiler.source>8</maven.compiler.source>
      <maven.compiler.target>8</maven.compiler.target>
    </properties>
<dependencies>
    <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>4.5.13</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>1.2.76</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/junit/junit -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.13.2</version>
      <scope>test</scope>
    </dependency>

</dependencies>
</project>

1804536204 发表于 2021-6-16 03:05

感谢作者分享

0×Ret 发表于 2021-6-16 09:46


感谢作者分享,正好需要

办事靠关系 发表于 2021-6-24 18:14

请问这个是做什么用的?

白云点缀的蓝 发表于 2021-6-24 18:47

办事靠关系 发表于 2021-6-24 18:14
请问这个是做什么用的?

拿来做京东任务

2098502556 发表于 2021-8-1 02:09

支持学习!!

omgTsQ6917 发表于 2022-2-25 05:54

谢谢分享

ftN2 发表于 2022-2-25 06:09

感谢楼主

CLybc73 发表于 2022-2-28 16:27

学习永不间断!

wLlqmUDo49 发表于 2022-3-1 01:15

谢谢分享
页: [1] 2 3 4 5 6 7 8
查看完整版本: 参考某东618工具接口写了几个请求