TalkonlinewebApplicationTests.java 2.79 KB
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
package com.lyms.talkonlineweb;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.lyms.talkonlineweb.mapper.LymsUserMapper;
import com.lyms.talkonlineweb.service.LymsUserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.servlet.function.ServerRequest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//@SpringBootTest
class TalkonlinewebApplicationTests {

@Autowired
private LymsUserMapper lymsUserMapper;

@Autowired
private LymsUserService lymsUserService;

@Test
void testSlt() {
List uLst=lymsUserMapper.selectList(null);
System.out.println(uLst.size());
uLst.forEach(e->{
System.out.println(e);
});
System.out.println("############################");
lymsUserService.list().forEach(e-> System.out.println(e));
}

// @Test
// void testHx(){
// EMProperties properties = EMProperties.builder()
// .setAppkey("1135210903239178#demo")
// .setClientId("YXA65kqQUy4pQaqHb3pwXwfnrA")
// .setClientSecret("YXA6RZaIr68MPPLcvqUnYxpqEkAEj6w")
// .build();
//
// EMService service = new EMService(properties);
// service.user().create("test122234","12345");
// }

@Test
void testRest(){
RestTemplate restTemplate=new RestTemplate();
String url="http://a1.easemob.com/1135210903239178/demo/";
Map<String,Object> param=new HashMap<>();
param.put("grant_type","client_credentials");
param.put("client_id","YXA65kqQUy4pQaqHb3pwXwfnrA");
param.put("client_secret","YXA6RZaIr68MPPLcvqUnYxpqEkAEj6w");

ResponseEntity<String> resp=restTemplate.postForEntity(url+"token",param,String.class);
System.out.println(resp);
if(resp.getStatusCodeValue()==200){

String token=JSON.parseObject(resp.getBody()).getString("access_token");

System.out.println("token="+token);
HttpHeaders headers=new HttpHeaders();
headers.add("Authorization","Bearer "+token);
List lParam=new ArrayList();
param.clear();
param.put("username","test110");
param.put("password","test110");
lParam.add(param);
HttpEntity entity=new HttpEntity(param,headers);
resp=restTemplate.postForEntity(url+"users",entity,String.class);
System.out.println(resp);
}
}

}