|
@@ -1,25 +1,37 @@
|
|
|
package org.jeecg.modules.okki.account.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import io.swagger.models.auth.In;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.jeecg.common.system.vo.DictModel;
|
|
|
+import org.jeecg.common.util.FastJsonUtil;
|
|
|
+import org.jeecg.modules.okki.account.dto.OkkiBindSiteDto;
|
|
|
import org.jeecg.modules.okki.account.entity.OkkiAccount;
|
|
|
import org.jeecg.modules.okki.account.mapper.OkkiAccountMapper;
|
|
|
import org.jeecg.modules.okki.account.param.OkkiAccountResetPwdParam;
|
|
|
import org.jeecg.modules.okki.account.service.IOkkiAccountService;
|
|
|
+import org.jeecg.modules.okki.site.entity.OkkiSite;
|
|
|
+import org.jeecg.modules.okki.site.service.IOkkiSiteService;
|
|
|
+import org.jeecg.modules.okki.siteuser.entity.OkkiSiteUser;
|
|
|
+import org.jeecg.modules.okki.siteuser.service.IOkkiSiteUserService;
|
|
|
import org.jeecg.modules.okki.utils.HttpClientUtils;
|
|
|
+import org.jeecg.modules.system.service.ISysDictService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.TreeMap;
|
|
|
+import java.util.*;
|
|
|
|
|
|
/**
|
|
|
* @Description: 小二账号
|
|
|
* @Author: jeecg-boot
|
|
|
- * @Date: 2024-05-22
|
|
|
+ * @Date: 2024-05-22
|
|
|
* @Version: V1.0
|
|
|
*/
|
|
|
@Slf4j
|
|
@@ -31,6 +43,13 @@ public class OkkiAccountServiceImpl extends ServiceImpl<OkkiAccountMapper, OkkiA
|
|
|
|
|
|
@Value("${OKKI.CLIENT_SECRET}")
|
|
|
private String CLIENT_SECRET;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDictService sysDictService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IOkkiSiteUserService okkiSiteUserService;
|
|
|
+
|
|
|
@Override
|
|
|
public void insertAccount(OkkiAccount okkiAccount) {
|
|
|
//查询账号是否已存在
|
|
@@ -60,7 +79,7 @@ public class OkkiAccountServiceImpl extends ServiceImpl<OkkiAccountMapper, OkkiA
|
|
|
String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
log.info(res);
|
|
|
// {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
|
|
|
- JSONObject jsonObject= JSONObject.parseObject(res);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
if (jsonObject.get("code").equals(0)) {
|
|
|
Object data = jsonObject.get("data");
|
|
|
JSONObject jsonObject1 = JSONObject.parseObject(data.toString());
|
|
@@ -73,7 +92,62 @@ public class OkkiAccountServiceImpl extends ServiceImpl<OkkiAccountMapper, OkkiA
|
|
|
if (!okkiAccount.getSiteIds().equals("")) {
|
|
|
bindSites(okkiAccount);
|
|
|
}
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void insertAccountV2(OkkiAccount okkiAccount) {
|
|
|
+ //查询账号是否已存在
|
|
|
+ OkkiAccount one = this.getOne(new LambdaQueryWrapper<OkkiAccount>().eq(OkkiAccount::getAccount, okkiAccount.getAccount()));
|
|
|
+ if (one != null) {
|
|
|
+ throw new RuntimeException("账号已存在,请新增其他账号!");
|
|
|
+ }
|
|
|
+ //创建小二账号
|
|
|
+ // 请求okki平台接口
|
|
|
+ Map<String, String> query = new TreeMap<>();
|
|
|
+ query.put("sign_method", "hmac-md5");
|
|
|
+ query.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ query.put("site_id", "sp_weichi");
|
|
|
+ query.put("method", "dumpUser");
|
|
|
+ Map<String, Object> postData = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String queryStr = HttpClientUtils.buildQueryString(query);
|
|
|
+ postData.put("email", okkiAccount.getAccount());
|
|
|
+ postData.put("pwd", okkiAccount.getPassword());
|
|
|
+ postData.put("user_role", okkiAccount.getUserRole());
|
|
|
+ postData.put("nickname", okkiAccount.getName());
|
|
|
+ postData.put("account", okkiAccount.getAccount());
|
|
|
+ postData.put("phone", okkiAccount.getPhone());
|
|
|
+ log.info("postData:{}", FastJsonUtil.toJSONString(postData));
|
|
|
+
|
|
|
+ String body = HttpClientUtils.toJsonString(postData);
|
|
|
+ String signStr = queryStr + body;
|
|
|
+ query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
|
|
|
+ String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
|
|
|
+ log.info("url:" + okkiUrl + ",body:" + body);
|
|
|
+ String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
+ log.info(res);
|
|
|
+ // {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ if (jsonObject.get("code").equals(0)) {
|
|
|
+ Object data = jsonObject.get("data");
|
|
|
+ JSONObject jsonObject1 = JSONObject.parseObject(data.toString());
|
|
|
+ Integer userId = (Integer) jsonObject1.get("user_id");
|
|
|
+ Integer userStatus = (Integer) jsonObject1.get("user_status");
|
|
|
+ okkiAccount.setUserId(userId);
|
|
|
+ okkiAccount.setStatus(userStatus);
|
|
|
+ this.save(okkiAccount);
|
|
|
+ //关联站点
|
|
|
+ if (!"".equals(okkiAccount.getSiteIds())) {
|
|
|
+// bindSites(okkiAccount);
|
|
|
+// bindSitesV2(okkiAccount);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -113,11 +187,72 @@ public class OkkiAccountServiceImpl extends ServiceImpl<OkkiAccountMapper, OkkiA
|
|
|
String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
log.info(res);
|
|
|
// {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
|
|
|
- JSONObject jsonObject= JSONObject.parseObject(res);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
if (jsonObject.get("code").equals(0)) {
|
|
|
okkiAccount.setUserRole(okkiAccountParam.getUserRole());
|
|
|
this.updateById(okkiAccount);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void resetRoleV2(OkkiAccount okkiAccountParam) {
|
|
|
+ // 请求okki平台接口
|
|
|
+ Map<String, String> query = new TreeMap<>();
|
|
|
+ query.put("sign_method", "hmac-md5");
|
|
|
+ query.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ query.put("site_id", "sp_weichi");
|
|
|
+ query.put("method", "resetUserInfo");
|
|
|
+ Map<String, Object> postData = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String queryStr = HttpClientUtils.buildQueryString(query);
|
|
|
+ final OkkiAccount okkiAccount = this.getById(okkiAccountParam.getId());
|
|
|
+ postData.put("user_id", okkiAccount.getUserId());
|
|
|
+ if (okkiAccountParam.getUserRole() != null) {
|
|
|
+ postData.put("user_role", okkiAccountParam.getUserRole());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(okkiAccountParam.getName())) {
|
|
|
+ postData.put("nickname", okkiAccountParam.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(okkiAccountParam.getAccount())) {
|
|
|
+ postData.put("email", okkiAccountParam.getAccount());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(okkiAccountParam.getPhone())) {
|
|
|
+ postData.put("phone", okkiAccountParam.getPhone());
|
|
|
+ }
|
|
|
+ log.info("postData:{}", FastJsonUtil.toJSONString(postData));
|
|
|
+
|
|
|
+ String body = HttpClientUtils.toJsonString(postData);
|
|
|
+ String signStr = queryStr + body;
|
|
|
+ query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
|
|
|
+ String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
|
|
|
+ log.info("url:" + okkiUrl + ",body:" + body);
|
|
|
+ String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
+ log.info(res);
|
|
|
+ // {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ if (jsonObject.get("code").equals(0)) {
|
|
|
+ okkiAccount.setUserRole(okkiAccountParam.getUserRole());
|
|
|
+ if (StringUtils.isNotEmpty(okkiAccountParam.getName())) {
|
|
|
+ okkiAccount.setName(okkiAccountParam.getName());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(okkiAccountParam.getAccount())) {
|
|
|
+ okkiAccount.setAccount(okkiAccountParam.getAccount());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (StringUtils.isNotEmpty(okkiAccountParam.getPhone())) {
|
|
|
+ okkiAccount.setPhone(okkiAccountParam.getPhone());
|
|
|
+ }
|
|
|
+ this.updateById(okkiAccount);
|
|
|
+ } else {
|
|
|
throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -151,11 +286,73 @@ public class OkkiAccountServiceImpl extends ServiceImpl<OkkiAccountMapper, OkkiA
|
|
|
log.info("url:" + okkiUrl + ",body:" + body);
|
|
|
String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
log.info(res);
|
|
|
- JSONObject jsonObject= JSONObject.parseObject(res);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ if (jsonObject.get("code").equals(0)) {
|
|
|
+ okkiAccount.setSiteIds(siteIds);
|
|
|
+ this.updateById(okkiAccount);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void bindSitesV2(OkkiAccount okkiAccountParam) {
|
|
|
+ // 请求okki平台接口
|
|
|
+ Map<String, String> query = new TreeMap<>();
|
|
|
+ query.put("sign_method", "hmac-md5");
|
|
|
+ query.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ query.put("site_id", "sp_weichi");
|
|
|
+ query.put("method", "bindSiteWithRole");
|
|
|
+ Map<String, Object> postData = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String queryStr = HttpClientUtils.buildQueryString(query);
|
|
|
+ final OkkiAccount okkiAccount = this.getById(okkiAccountParam.getId());
|
|
|
+// postData.put("user_id", okkiAccount.getUserId());
|
|
|
+
|
|
|
+ // 字符串转数组
|
|
|
+ String siteIds = okkiAccountParam.getSiteIds();
|
|
|
+ String[] split = siteIds.split(",");
|
|
|
+ postData.put("site_ids", split);
|
|
|
+
|
|
|
+// List<Integer> userIds = new ArrayList<>();
|
|
|
+// userIds.add(okkiAccount.getUserId());
|
|
|
+// Map<Integer,Object> map = new HashMap<>();
|
|
|
+// map.put(okkiAccount.getUserRole(),userIds);
|
|
|
+
|
|
|
+// List<Integer> userIds2 = new ArrayList<>();
|
|
|
+// userIds2.add(okkiAccount.getUserId());
|
|
|
+// map.put(2,userIds2);
|
|
|
+
|
|
|
+ List<DictModel> dictModels = sysDictService.getDictItems("user_role");
|
|
|
+// log.info("dictModels:{}",FastJsonUtil.toJSONString(dictModels));
|
|
|
+ Map<Integer, Object> userRoleMap = new HashMap<>();
|
|
|
+ dictModels.forEach(c -> {
|
|
|
+ List<Integer> userIds = new ArrayList<>();
|
|
|
+ if (okkiAccount.getUserRole().equals(Integer.valueOf(c.getValue()))) {
|
|
|
+ userIds.add(okkiAccount.getUserId());
|
|
|
+ }
|
|
|
+ userRoleMap.put(Integer.valueOf(c.getValue()), userIds);
|
|
|
+ });
|
|
|
+ log.info("userRoleMap:{}", FastJsonUtil.toJSONString(userRoleMap));
|
|
|
+
|
|
|
+ postData.put("user_sets", userRoleMap);
|
|
|
+ log.info("postData:{}", FastJsonUtil.toJSONString(postData));
|
|
|
+
|
|
|
+ String body = HttpClientUtils.toJsonString(postData);
|
|
|
+ String signStr = queryStr + body;
|
|
|
+ query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
|
|
|
+ String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
|
|
|
+ log.info("url:" + okkiUrl + ",body:" + body);
|
|
|
+ String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
+ log.info(res);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
if (jsonObject.get("code").equals(0)) {
|
|
|
okkiAccount.setSiteIds(siteIds);
|
|
|
this.updateById(okkiAccount);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
@@ -164,6 +361,129 @@ public class OkkiAccountServiceImpl extends ServiceImpl<OkkiAccountMapper, OkkiA
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ public void bindSitesV2(OkkiBindSiteDto okkiBindSiteDto) {
|
|
|
+ // 请求okki平台接口
|
|
|
+ Map<String, String> query = new TreeMap<>();
|
|
|
+ query.put("sign_method", "hmac-md5");
|
|
|
+ query.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ query.put("site_id", "sp_weichi");
|
|
|
+ query.put("method", "bindSiteWithRole");
|
|
|
+ Map<String, Object> postData = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String queryStr = HttpClientUtils.buildQueryString(query);
|
|
|
+
|
|
|
+ // 字符串转数组
|
|
|
+ String siteIds = okkiBindSiteDto.getSiteId();
|
|
|
+ String[] split = siteIds.split(",");
|
|
|
+ postData.put("site_ids", split);
|
|
|
+
|
|
|
+ Map<Integer, Object> userRoleMap = buildUserRoleMap(okkiBindSiteDto);
|
|
|
+ postData.put("user_sets", userRoleMap);
|
|
|
+ log.info("postData:{}", FastJsonUtil.toJSONString(postData));
|
|
|
+
|
|
|
+ String body = HttpClientUtils.toJsonString(postData);
|
|
|
+ String signStr = queryStr + body;
|
|
|
+ query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
|
|
|
+ String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
|
|
|
+ log.info("url:" + okkiUrl + ",body:" + body);
|
|
|
+ String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
+ log.info(res);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ if (jsonObject.get("code").equals(0)) {
|
|
|
+ // 保存站点数据
|
|
|
+ buildOkkiSiteUser(okkiBindSiteDto);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建用户角色映射
|
|
|
+ */
|
|
|
+ private Map<Integer, Object> buildUserRoleMap(OkkiBindSiteDto okkiBindSiteDto) {
|
|
|
+ Map<Integer, Object> userRoleMap = new HashMap<>();
|
|
|
+
|
|
|
+ addRoleToMap(userRoleMap, 1, okkiBindSiteDto.getServiceManageUser());
|
|
|
+ addRoleToMap(userRoleMap, 5, okkiBindSiteDto.getDataUser());
|
|
|
+ addRoleToMap(userRoleMap, 2, okkiBindSiteDto.getKefuUser());
|
|
|
+ addRoleToMap(userRoleMap, 7, okkiBindSiteDto.getSeoUser());
|
|
|
+ addRoleToMap(userRoleMap, 9, okkiBindSiteDto.getSemManageUser());
|
|
|
+ addRoleToMap(userRoleMap, 10, okkiBindSiteDto.getSemUser());
|
|
|
+ addRoleToMap(userRoleMap, 4, okkiBindSiteDto.getUiUser());
|
|
|
+ addRoleToMap(userRoleMap, 11, okkiBindSiteDto.getWebsiteUser());
|
|
|
+ addRoleToMap(userRoleMap, 8, okkiBindSiteDto.getSocialUser());
|
|
|
+ addRoleToMap(userRoleMap, 12, okkiBindSiteDto.getRdUser());
|
|
|
+
|
|
|
+ return userRoleMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 向用户角色映射中添加角色
|
|
|
+ */
|
|
|
+ private void addRoleToMap(Map<Integer, Object> userRoleMap, int roleType, String userId) {
|
|
|
+ if (StringUtils.isNotEmpty(userId)) {
|
|
|
+ String[] userIds = userId.split(",");
|
|
|
+ userRoleMap.put(roleType, userIds);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建OkkiSite对象
|
|
|
+ */
|
|
|
+ private void buildOkkiSiteUser(OkkiBindSiteDto okkiBindSiteDto) {
|
|
|
+ List<OkkiSiteUser> okkiSiteUsers = new ArrayList<>();
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 删除已有的站点用户
|
|
|
+ QueryWrapper<OkkiSiteUser> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.eq("site_id", Integer.valueOf(okkiBindSiteDto.getSiteId()));
|
|
|
+ boolean isRemoved = okkiSiteUserService.remove(queryWrapper);
|
|
|
+ log.info("Removed existing site users for siteId {}: {}", okkiBindSiteDto.getSiteId(), isRemoved);
|
|
|
+
|
|
|
+ // 用户类型映射
|
|
|
+ Map<String, String> userTypeMapping = new HashMap<>();
|
|
|
+ userTypeMapping.put("serviceManageUser", okkiBindSiteDto.getServiceManageUser());
|
|
|
+ userTypeMapping.put("dataUser", okkiBindSiteDto.getDataUser());
|
|
|
+ userTypeMapping.put("kefuUser", okkiBindSiteDto.getKefuUser());
|
|
|
+ userTypeMapping.put("seoUser", okkiBindSiteDto.getSeoUser());
|
|
|
+ userTypeMapping.put("semManageUser", okkiBindSiteDto.getSemManageUser());
|
|
|
+ userTypeMapping.put("semUser", okkiBindSiteDto.getSemUser());
|
|
|
+ userTypeMapping.put("uiUser", okkiBindSiteDto.getUiUser());
|
|
|
+ userTypeMapping.put("websiteUser", okkiBindSiteDto.getWebsiteUser());
|
|
|
+ userTypeMapping.put("socialUser", okkiBindSiteDto.getSocialUser());
|
|
|
+ userTypeMapping.put("rdUser", okkiBindSiteDto.getRdUser());
|
|
|
+
|
|
|
+ // 遍历映射关系,构建 OkkiSiteUser 对象
|
|
|
+ for (Map.Entry<String, String> entry : userTypeMapping.entrySet()) {
|
|
|
+ String userType = entry.getKey();
|
|
|
+ String userIds = entry.getValue();
|
|
|
+
|
|
|
+ if (userIds != null && !userIds.isEmpty()) {
|
|
|
+ String[] userArr = userIds.split(",");
|
|
|
+ for (String s : userArr) {
|
|
|
+ OkkiSiteUser okkiSiteUser = new OkkiSiteUser();
|
|
|
+ okkiSiteUser.setSiteId(Integer.valueOf(okkiBindSiteDto.getSiteId()));
|
|
|
+ okkiSiteUser.setUserId(Integer.valueOf(s));
|
|
|
+ okkiSiteUser.setType(userType);
|
|
|
+ okkiSiteUsers.add(okkiSiteUser);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 批量保存站点用户数据
|
|
|
+ boolean isSaved = okkiSiteUserService.saveBatch(okkiSiteUsers);
|
|
|
+ log.info("Saved site users for siteId {}: {}", okkiBindSiteDto.getSiteId(), isSaved);
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("Error building OkkiSiteUser for siteId {}", okkiBindSiteDto.getSiteId(), e);
|
|
|
+ throw new RuntimeException("Error building OkkiSiteUser", e);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
public void resetPwd(OkkiAccountResetPwdParam okkiAccountResetPwdParam) {
|
|
|
// 请求okki平台接口
|
|
|
Map<String, String> query = new TreeMap<>();
|
|
@@ -186,15 +506,59 @@ public class OkkiAccountServiceImpl extends ServiceImpl<OkkiAccountMapper, OkkiA
|
|
|
log.info("url:" + okkiUrl + ",body:" + body);
|
|
|
String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
log.info(res);
|
|
|
- JSONObject jsonObject= JSONObject.parseObject(res);
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
if (jsonObject.get("code").equals(0)) {
|
|
|
okkiAccount.setPassword(okkiAccountResetPwdParam.getNewPassword());
|
|
|
this.updateById(okkiAccount);
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取站点绑定信息
|
|
|
+ *
|
|
|
+ * @param siteId
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> getSiteBindInfo(Integer siteId) {
|
|
|
+ Map<String, Object> mergedList = new HashMap<>();
|
|
|
+ // 请求okki平台接口
|
|
|
+ Map<String, String> query = new TreeMap<>();
|
|
|
+ query.put("sign_method", "hmac-md5");
|
|
|
+ query.put("timestamp", String.valueOf(System.currentTimeMillis()));
|
|
|
+ query.put("site_id", "sp_weichi");
|
|
|
+ query.put("method", "siteBindInfo");
|
|
|
+ Map<String, Object> postData = new HashMap<>();
|
|
|
+ try {
|
|
|
+ String queryStr = HttpClientUtils.buildQueryString(query);
|
|
|
+ postData.put("site_id", siteId);
|
|
|
+
|
|
|
+ String body = HttpClientUtils.toJsonString(postData);
|
|
|
+ String signStr = queryStr + body;
|
|
|
+ query.put("signature", HttpClientUtils.generateHmacMD5(signStr, CLIENT_SECRET));
|
|
|
+ String okkiUrl = URL + "?" + HttpClientUtils.buildQueryString(query);
|
|
|
+ log.info("url:" + okkiUrl + ",body:" + body);
|
|
|
+ String res = HttpClientUtils.doPost(okkiUrl, body);
|
|
|
+ log.info(res);
|
|
|
+ // {"code":0,"msg":"success","now":"2024-05-06 15:34:54","data":[]}
|
|
|
+ JSONObject jsonObject = JSONObject.parseObject(res);
|
|
|
+ if (jsonObject.get("code").equals(0)) {
|
|
|
+ JSONObject dataObject = jsonObject.getJSONObject("data");
|
|
|
+ Map<String, Object> check = FastJsonUtil.parseObject(dataObject.get("check").toString(), Map.class);
|
|
|
+ Map<String, Object> other = FastJsonUtil.parseObject(dataObject.get("other").toString(), Map.class);
|
|
|
+ mergedList.putAll(check);
|
|
|
+ mergedList.putAll(other);
|
|
|
+ }
|
|
|
+// else {
|
|
|
+// throw new RuntimeException(jsonObject.get("msg").toString());
|
|
|
+// }
|
|
|
+ } catch (Exception e) {
|
|
|
+// throw new RuntimeException(e);
|
|
|
+ }
|
|
|
+ return mergedList;
|
|
|
+ }
|
|
|
}
|