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 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
| @Service("timService") public class TimService { private static final Logger log = LoggerFactory.getLogger(TimService.class); public static final String HOST = "https://console.tim.qq.com";
@Autowired private RestTemplate restTemplate;
@SysLog("单账号导入") public ProcessResult accountImport(String Identifier) { String userSig = getUserSig(); String url = formatUrl("im_open_login_svc", "account_import", userSig); Map jsonObj = Collections.singletonMap("Identifier",Identifier); HttpEntity<String> formEntity = new HttpEntity<String>(JsonUtil.toJSON(jsonObj)); Map<String, String> result = restTemplate.postForObject(url, formEntity, Map.class); if ("OK".equalsIgnoreCase(result.get("ActionStatus"))) { return new ProcessResult(ProcessResult.SUCCESS,"single account import success"); } return new ProcessResult(ProcessResult.ERROR,"single account import failure"); }
@SysLog("创建群组") public String createGroup(GoVideo goVideo) { String userSig = getUserSig(); String url = formatUrl("group_open_http_svc", "create_group", userSig); Map<String, Object> jsonObj = new HashMap<>(); jsonObj.put("Type","AVChatRoom"); jsonObj.put("Name","Group-"+goVideo.getId()); jsonObj.put("GroupId","live-"+goVideo.getId()); HttpEntity<String> formEntity = new HttpEntity<String>(JsonUtil.toJSON(jsonObj)); Map<String, String> result = restTemplate.postForObject(url, formEntity, Map.class); return result.get("ActionStatus"); }
@SysLog("APP自定义脏字") @PostMapping(value = "/addDirtyWOrd") public ProcessResult addDirtyWord(@RequestBody String jsonString) { Map jsonObj = JsonUtil.fromJSON(jsonString, Map.class); String userSig = getUserSig(); String url = formatUrl("openim_dirty_words", "add", userSig); HttpEntity<String> formEntity = new HttpEntity<String>(JsonUtil.toJSON(jsonObj)); Map<String, String> rowData = restTemplate.postForObject(url, formEntity, Map.class); String actionStatus = rowData.get("ActionStatus"); if("OK".equalsIgnoreCase(actionStatus)) { return new ProcessResult(ProcessResult.SUCCESS,"add dirty word success"); } return new ProcessResult(ProcessResult.ERROR,"add dirty word failure :: " + JsonUtil.toJSON(rowData)); }
@SysLog("解散群组") @PostMapping(value = "/destroyGroup") public String destroyGroup(GoVideo goVideo) { Map<String,Object> jsonObj = new HashMap(); jsonObj.put("GroupId",goVideo.getGroupId()); String userSig = getUserSig(); String url = formatUrl("group_open_http_svc", "destroy_group", userSig); HttpEntity<String> formEntity = new HttpEntity<String>(JsonUtil.toJSON(jsonObj)); Map<String, String> rowData = restTemplate.postForObject(url, formEntity, Map.class); log.info("===========解散群组================== {}", goVideo.getGroupId()); return rowData.get("ActionStatus"); }
public String registe(String uuid,String nickName,String faceUrl){ String userSig = getUserSig(); String url = formatUrl("im_open_login_svc","account_import",userSig); Map<String,Object> jsonObj = new HashMap(); jsonObj.put("Identifier",uuid); jsonObj.put("Nick",nickName); jsonObj.put("FaceUrl",faceUrl); Map<String, String> result = restTemplate.postForObject(url, jsonObj, Map.class); return result.get("ActionStatus"); }
public String updateImFaceUrl(User user) { String userSig = getUserSig(); String url = formatUrl("profile", "portrait_set", userSig); ArrayList<Object> profileItem = new ArrayList<>(); HashMap<String, Object> jsonObj = new HashMap<>(); jsonObj.put("Tag", "Tag_Profile_IM_Image"); jsonObj.put("Value", user.getAvatar()); profileItem.add(jsonObj); MapBuild<String, String> obj = new MapBuild<String, String>().put("From_Account",user.getUuid()).put("ProfileItem", profileItem); Map<String, String> result = restTemplate.postForObject(url, obj.build(), Map.class); return result.get("ActionStatus"); }
public String updateImNick(String uuid,String nickName) { String userSig = getUserSig(); String url = formatUrl("profile", "portrait_set", userSig); ArrayList<Object> profileItem = new ArrayList<>(); HashMap<String, Object> jsonObj = new HashMap<>(); jsonObj.put("Tag", "Tag_Profile_IM_Nick"); jsonObj.put("Value", nickName); profileItem.add(jsonObj); MapBuild<String, String> obj = new MapBuild<String, String>().put("From_Account", uuid).put("ProfileItem", profileItem); Map<String, String> result = restTemplate.postForObject(url, obj.build(), Map.class); return result.get("ActionStatus"); }
public String getProfilePortrait(String uuid){ String userSig = getUserSig(); String url = formatUrl("profile","portrait_get",userSig); MapBuild<String, String[]> obj = new MapBuild<String, String[]>().put("To_Account",new String[] {uuid}) .put("TagList",new String[] {"Tag_Profile_IM_Nick","Tag_Profile_IM_Image"}); Map<String, String> result = restTemplate.postForObject(url, obj.build(), Map.class); return result.get("ActionStatus"); }
private String formatUrl(String serviceName, String cmdName, String usersig) { double rd = Math.random() * 999_999_999; String url = String.format("%s/v4/%s/%s?usersig=%s&identifier=%s&sdkappid=%s&random=%d&contenttype=json", HOST, serviceName, cmdName, usersig, Constant.IDENTIFIER, Constant.SDK_APPID, (int) rd); return url; }
@SysLog("获取userSig") public String getUserSig() { TLSSigAPIv2 api = new TLSSigAPIv2(Constant.SDK_APPID, Constant.KEY); String userSig = api.genSig(Constant.IDENTIFIER , 180 * 86400); return userSig; }
|