|
|
@@ -1,107 +0,0 @@
|
|
|
-package com.uas.platform.b2b.support.mq;
|
|
|
-
|
|
|
-import com.uas.platform.b2b.core.util.ContextUtils;
|
|
|
-import com.uas.platform.b2b.dao.UserBaseInfoDao;
|
|
|
-import com.uas.platform.b2b.manage.model.AccountInfo;
|
|
|
-import com.uas.platform.b2b.model.AccessToken;
|
|
|
-import com.uas.platform.b2b.model.UserBaseInfo;
|
|
|
-import com.uas.platform.b2b.service.AccessTokenService;
|
|
|
-import com.uas.platform.b2b.support.SysConf;
|
|
|
-import com.uas.platform.core.util.HttpUtil;
|
|
|
-import com.uas.platform.core.util.HttpUtil.Response;
|
|
|
-import com.uas.platform.core.util.serializer.FlexJsonUtils;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-
|
|
|
-import java.io.*;
|
|
|
-import java.net.*;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-public class PushUtils {
|
|
|
-
|
|
|
- private static UserBaseInfoDao userRepository;
|
|
|
- private static AccessTokenService accessTokenService;
|
|
|
- private static SysConf sysConf;
|
|
|
-
|
|
|
- private static UserBaseInfoDao getUserRepository() {
|
|
|
- if (userRepository == null) {
|
|
|
- userRepository = ContextUtils.getBean(UserBaseInfoDao.class);
|
|
|
- }
|
|
|
- return userRepository;
|
|
|
- }
|
|
|
-
|
|
|
- private static AccessTokenService getAccessTokenService() {
|
|
|
- if (accessTokenService == null) {
|
|
|
- accessTokenService = ContextUtils.getBean(AccessTokenService.class);
|
|
|
- }
|
|
|
- return accessTokenService;
|
|
|
- }
|
|
|
-
|
|
|
- private static SysConf getSysConf() {
|
|
|
- if (sysConf == null) {
|
|
|
- sysConf = ContextUtils.getBean(SysConf.class);
|
|
|
- }
|
|
|
- return sysConf;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 调用接口注册IM
|
|
|
- *
|
|
|
- * @param user
|
|
|
- * @param enUU
|
|
|
- * @return
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- private static Map<String, Object> sendUserToManage(UserBaseInfo user, long enUU) throws Exception {
|
|
|
- Map<String, String> params = new HashMap<String, String>();
|
|
|
- params.put("data", FlexJsonUtils.toJson(new AccountInfo(user, enUU)));
|
|
|
- Response response = HttpUtil.sendPostRequest(getSysConf().getManageInner() + "/public/account", params, true);
|
|
|
- if (response.getStatusCode() == HttpStatus.OK.value()) {
|
|
|
- List<Map<String, Object>> resultMap = FlexJsonUtils.fromJsonArray(response.getResponseText(), HashMap.class);
|
|
|
- if (resultMap.size() > 0) {
|
|
|
- if ("true".equals(String.valueOf(resultMap.get(0).get("ok")))) {
|
|
|
- return resultMap.get(0);
|
|
|
- }
|
|
|
- throw new Exception(String.valueOf(resultMap.get(0).get("error")));
|
|
|
- }
|
|
|
- }
|
|
|
- throw new Exception(response.getResponseText());
|
|
|
- }
|
|
|
-
|
|
|
- public static void push(long enUU, long userUU, String title, String content, String url, String pageTitle) {
|
|
|
- UserBaseInfo user = getUserRepository().findOne(userUU);
|
|
|
- if (user != null) {
|
|
|
- // 没有IM账号的,需要先注册
|
|
|
- if (user.getUserIMId() == null) {
|
|
|
- try {
|
|
|
- Map<String, Object> res = sendUserToManage(user, enUU);
|
|
|
- Object imid = res.get("userImid");
|
|
|
- if (imid != null) {
|
|
|
- user.setUserIMId(Long.parseLong(imid.toString()));
|
|
|
- }
|
|
|
- user = getUserRepository().save(user);
|
|
|
- } catch (Exception e) {
|
|
|
- }
|
|
|
- }
|
|
|
- if (user.getUserIMId() != null && user.getUserIMId() > 0) {
|
|
|
- Map<String, Object> params = new HashMap<String, Object>();
|
|
|
- params.put("userid", user.getUserIMId());
|
|
|
- params.put("enUU", enUU);
|
|
|
- params.put("platform", "B2B");
|
|
|
- params.put("title", title);
|
|
|
- params.put("content", content);
|
|
|
- AccessToken token = getAccessTokenService().createNew(user, enUU, null, 259200);// 有效期:三天
|
|
|
- // ex: http://www.usoftchina.com/openapi/webpage?access_token=282a8ba2fa1f4fdc9e025c1eea2ad7e8&redirect_page=http%3A%2F%2Fwww.usoftchina.com%2F%23sale%2Forder%2F123
|
|
|
- try {
|
|
|
- params.put("url", String.format("%s/openapi/webpage?access_token=%s&redirect_page=%s", getSysConf().getB2b(),
|
|
|
- token.getId(), URLEncoder.encode(getSysConf().getB2b() + "/" + url, "utf-8")));
|
|
|
- // 调用推送接口
|
|
|
- Pusher.push(params);
|
|
|
- } catch (UnsupportedEncodingException e) {
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|