master
kira 6 years ago
parent 87bae39ecc
commit 8579b406d3

@ -1,26 +0,0 @@
package au.com.royalpay.payment.manage.mappers.openim;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
/**
* Created by yixian on 2016-10-27.
*/
@AutoMapper(tablename = "sys_openim", pkName = "id")
public interface OpenimMapper {
@AutoSql(type = SqlType.SELECT)
JSONObject findOne(@Param("user_id") String user_id);
@AutoSql(type = SqlType.SELECT)
JSONObject findByAccountId(@Param("account_id") String account_id,@Param("account_type") String account_type);
@AutoSql(type = SqlType.UPDATE)
void update(JSONObject member);
@AutoSql(type = SqlType.INSERT)
void save(JSONObject member);
}

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.openim;
import au.com.royalpay.payment.manage.openim.beans.OpenimUserVO;
import au.com.royalpay.payment.manage.openim.core.CustomerServiceService;
import au.com.royalpay.payment.manage.permission.manager.RequireManager;
import au.com.royalpay.payment.tools.CommonConsts;
@ -9,8 +10,11 @@ import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import javax.annotation.Resource;
/**
@ -24,11 +28,19 @@ public class OpenimController {
@Resource
private CustomerServiceService customerServiceService;
@RequestMapping(value = "/check",method = RequestMethod.POST)
@RequestMapping(value = "/check", method = RequestMethod.POST)
@RequireManager
public void sendMsg(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
customerServiceService.checkAndSave(manager);
}
@RequestMapping(value = "/findOne", method = RequestMethod.GET)
public OpenimUserVO findOne(@RequestParam int clientId, @RequestParam String userName) {
return customerServiceService.findOne(clientId, userName);
}
@RequestMapping(value = "/list",method = RequestMethod.GET)
public List<JSONObject> query(@RequestParam String clientMoniker){
return customerServiceService.query(clientMoniker);
}
}

@ -0,0 +1,26 @@
package au.com.royalpay.payment.manage.openim.beans;
/**
* @author kira
* @date 2018/7/17
*/
public class OpenimUserVO {
private String nick;
private String userid;
public String getNick() {
return nick;
}
public void setNick(String nick) {
this.nick = nick;
}
public String getUserid() {
return userid;
}
public void setUserid(String userid) {
this.userid = userid;
}
}

@ -1,7 +1,11 @@
package au.com.royalpay.payment.manage.openim.core;
import au.com.royalpay.payment.manage.openim.beans.OpenimUserVO;
import com.alibaba.fastjson.JSONObject;
import java.util.List;
/**
* @author kira
* @date 2018/7/11
@ -9,4 +13,8 @@ import com.alibaba.fastjson.JSONObject;
public interface CustomerServiceService {
void checkAndSave(JSONObject account);
OpenimUserVO findOne(int clientId,String userName);
List<JSONObject> query(String clientMoniker);
}

@ -20,7 +20,6 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
/**
@ -30,8 +29,8 @@ import java.util.List;
@Service
public class OpenimClient {
Logger logger = LoggerFactory.getLogger(getClass());
// private final String appkey = "24960261";
// private final String secret = "7639427973bd671be15c9d0c1e9c90b4";
// private final String appkey = "24960261";
// private final String secret = "7639427973bd671be15c9d0c1e9c90b4";
private final String appkey = "24962653";
private final String secret = "1c1a1320c4e6f24df24e3fe41c3fc00a";
private final String url = "https://eco.taobao.com/router/rest";
@ -47,7 +46,11 @@ public class OpenimClient {
} catch (ApiException e) {
logger.info("openim get user fail", e);
}
return JSONObject.parseObject(rsp.getBody());
JSONObject openInfo = JSONObject.parseObject(rsp.getBody());
if (openInfo.getJSONObject("openim_users_get_response").getJSONObject("userinfos").size() < 1) {
return null;
}
return openInfo;
}
public void addUser(List<Userinfos> users) {
@ -61,9 +64,12 @@ public class OpenimClient {
logger.info("openim add user fail", e);
}
JSONObject result = JSONObject.parseObject(rsp.getBody());
if (result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").size() > 0) {
logger.info("openim add user fail reason:"
+ result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString());
JSONObject failMsg = result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg");
if (failMsg.size() > 0) {
if ("data exist".equals(failMsg.getJSONArray("string").get(0))) {
return;
}
logger.info("openim add user fail reason:" + failMsg.getJSONArray("string").toJSONString());
throw new ServerErrorException("System error");
}
}
@ -103,27 +109,4 @@ public class OpenimClient {
throw new ServerErrorException("System error");
}
}
// public static void main(String[] args) {
// String appkey = "24960261";
// String secret = "7639427973bd671be15c9d0c1e9c90b4";
// String url = "https://eco.taobao.com/router/rest";
// TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret);
// OpenimUsersAddRequest req = new OpenimUsersAddRequest();
// List<Userinfos> list2 = new ArrayList<Userinfos>();
// Userinfos obj3 = new Userinfos();
// list2.add(obj3);
// obj3.setNick("im123");
// obj3.setUserid("im123");
// obj3.setPassword("xxxxxx");
// req.setUserinfos(list2);
// OpenimUsersAddResponse rsp = null;
// try {
// rsp = client.execute(req);
// } catch (ApiException e) {
// e.printStackTrace();
// }
// System.out.println(rsp.getBody());
// }
}

@ -1,14 +1,21 @@
package au.com.royalpay.payment.manage.openim.core.impl;
import au.com.royalpay.payment.manage.mappers.openim.OpenimMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
import au.com.royalpay.payment.manage.merchants.core.ClientManager;
import au.com.royalpay.payment.manage.openim.beans.OpenimUserVO;
import au.com.royalpay.payment.manage.openim.core.CustomerServiceService;
import au.com.royalpay.payment.manage.openim.core.OpenimApi;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.Resource;
/**
@ -18,14 +25,21 @@ import javax.annotation.Resource;
@Service
public class CustomerServiceServiceImpl implements CustomerServiceService {
@Resource
private OpenimMapper openimMapper;
@Resource
private OpenimApi openimApi;
@Resource
private ClientManager clientManager;
@Resource
private ClientAccountMapper clientAccountMapper;
private final String password = "XXXXXX";
@Override
public void checkAndSave(JSONObject account) {
JSONObject client = clientManager.getClientInfo(account.getIntValue("client_id"));
if (client == null) {
throw new BadRequestException("Merchant Not Found");
}
boolean isPartner = true;
if (StringUtils.isNotEmpty(account.getString("account_id"))) {
isPartner = true;
@ -33,21 +47,55 @@ public class CustomerServiceServiceImpl implements CustomerServiceService {
if (StringUtils.isNotEmpty(account.getString("manager_id"))) {
isPartner = false;
}
String uid = account.getString("username")+ (isPartner ? "_partner": "_manager");
JSONObject record = openimMapper.findOne(uid);
if(record==null){
JSONObject saveRecord = new JSONObject();
saveRecord.put("nick",account.getString("display_name"));
if(isPartner){
saveRecord.put("user_id",account.getString("username")+"_partner");
saveRecord.put("account_type","partner");
saveRecord.put("account_id",account.getString("account_id"));
}else {
saveRecord.put("user_id",account.getString("username")+"_manager");
saveRecord.put("account_type","manager");
saveRecord.put("account_id",account.getString("manager_id"));
}
openimApi.addUser(saveRecord);
String uid = account.getString("username") + (isPartner ? "(" + client.getString("client_moniker") + ")" : "");
JSONObject saveRecord = new JSONObject();
saveRecord.put("nick", account.getString("display_name"));
if (isPartner) {
saveRecord.put("user_id", uid);
saveRecord.put("account_type", "partner");
saveRecord.put("account_id", account.getString("account_id"));
} else {
saveRecord.put("user_id", uid);
saveRecord.put("account_type", "manager");
saveRecord.put("account_id", account.getString("manager_id"));
}
saveRecord.put("password", password);
openimApi.addUser(saveRecord);
}
@Override
public OpenimUserVO findOne(int clientId, String userName) {
JSONObject client = clientManager.getClientInfo(clientId);
if (client == null) {
throw new BadRequestException("Merchant Not Found");
}
JSONObject account = clientAccountMapper.findByUsername(userName);
if (account == null) {
throw new BadRequestException("Account Not Found");
}
if (account.getIntValue("client_id") != clientId) {
throw new ForbiddenException("No Rights");
}
OpenimUserVO result = new OpenimUserVO();
result.setNick(account.getString("display_name"));
result.setUserid(account.getString("username") + "(" + client.getString("client_moniker") + ")");
return result;
}
@Override
public List<JSONObject> query(String clientMoniker) {
JSONObject client = clientManager.getClientInfoByMoniker(clientMoniker);
if (client == null) {
throw new BadRequestException("Merchant Not Found");
}
List<JSONObject> accounts = clientAccountMapper.listPartnerAccounts(client.getIntValue("client_id"));
List<JSONObject> result = new ArrayList<>(accounts.size());
accounts.forEach(p -> {
JSONObject openimUser = new JSONObject();
openimUser.put("nick", p.getString("display_name"));
openimUser.put("userid", p.getString("username") + "(" + client.getString("client_moniker") + ")");
result.add(openimUser);
});
return result;
}
}

@ -1,9 +1,7 @@
package au.com.royalpay.payment.manage.openim.core.impl;
import au.com.royalpay.payment.manage.mappers.openim.OpenimMapper;
import au.com.royalpay.payment.manage.openim.core.OpenimApi;
import au.com.royalpay.payment.manage.openim.core.OpenimClient;
import au.com.royalpay.payment.tools.utils.id.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.taobao.api.domain.Userinfos;
@ -24,27 +22,20 @@ public class OpenimApiImpl implements OpenimApi {
@Resource
private OpenimClient openimClient;
@Resource
private OpenimMapper openimMapper;
@Override
public void addUser(JSONObject user) {
JSONObject opemInfo = openimClient.getUser(user.getString("user_id"));
if(opemInfo!=null){
return;
}
List<Userinfos> saveList = new ArrayList<>();
Userinfos record = new Userinfos();
record.setUserid(user.getString("user_id"));
record.setNick(user.getString("nick"));
record.setPassword("XXXXXX");
record.setPassword(user.getString("password"));
saveList.add(record);
openimClient.addUser(saveList);
JSONObject openim = new JSONObject();
openim.put("id", IdUtil.getId());
openim.put("user_id", record.getUserid());
openim.put("password_aes", record.getPassword());
openim.put("account_id", user.getString("account_id"));
openim.put("account_type", user.getString("account_type"));
openimMapper.save(openim);
}
@Override

@ -19,10 +19,6 @@
appkey: 24960261,
credential: 'xxxxxx',
touid: window.touid,
logo:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531805672266&di=2b24a1579255192f7456d64872c65b39&imgtype=0&src=http%3A%2F%2Fimage.coolapk.com%2Ffeed%2F2016%2F1113%2F661664_1479013815_7771.jpg.m.jpg',
toAvatar:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531805672266&di=2b24a1579255192f7456d64872c65b39&imgtype=0&src=http%3A%2F%2Fimage.coolapk.com%2Ffeed%2F2016%2F1113%2F661664_1479013815_7771.jpg.m.jpg',
Avatar:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531805672266&di=2b24a1579255192f7456d64872c65b39&imgtype=0&src=http%3A%2F%2Fimage.coolapk.com%2Ffeed%2F2016%2F1113%2F661664_1479013815_7771.jpg.m.jpg',
pluginUrl: 'http://192.168.0.43:9001/service_contact_list.html?uid='
+ window.uid,
onLoginSuccess: function (data) {

Loading…
Cancel
Save