From 0c76b953a69116eea9fb7157be65d4346fffb77f Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Wed, 11 Jul 2018 11:01:14 +0800 Subject: [PATCH 1/6] init --- .../manage/openim/core/OpenimClient.java | 66 +++++++++++++++++++ .../payment/manage/openim/package-info.java | 5 ++ 2 files changed, 71 insertions(+) create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/package-info.java diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java new file mode 100644 index 000000000..663c96058 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java @@ -0,0 +1,66 @@ +package au.com.royalpay.payment.manage.openim.core; + +import com.taobao.api.ApiException; +import com.taobao.api.DefaultTaobaoClient; +import com.taobao.api.TaobaoClient; +import com.taobao.api.domain.Userinfos; +import com.taobao.api.request.OpenimUsersAddRequest; +import com.taobao.api.response.OpenimUsersAddResponse; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author kira + * @date 2018/7/11 + */ +@Service +public class OpenimClient { + Logger logger = LoggerFactory.getLogger(getClass()); +private final String appkey = "24960261"; +private final String secret = "7639427973bd671be15c9d0c1e9c90b4"; +private final String add_user="https://eco.taobao.com/router/rest"; + + public void addUser(){ + TaobaoClient client = new DefaultTaobaoClient(add_user, appkey, secret); + OpenimUsersAddRequest req = new OpenimUsersAddRequest(); + List list2 = new ArrayList<>(); + Userinfos obj3 = new Userinfos(); + list2.add(obj3); + obj3.setNick("king"); + obj3.setIconUrl("http://xxx.com/xxx"); + obj3.setEmail("uid@taobao.com"); + obj3.setMobile("18600000000"); + obj3.setTaobaoid("tbnick123"); + obj3.setUserid("imuser123"); + obj3.setPassword("xxxxxx"); + obj3.setRemark("demo"); + obj3.setExtra("{}"); + obj3.setCareer("demo"); + obj3.setVip("{}"); + obj3.setAddress("demo"); + obj3.setName("demo"); + obj3.setAge(123L); + obj3.setGender("M"); + obj3.setWechat("demo"); + obj3.setQq("demo"); + obj3.setWeibo("demo"); + req.setUserinfos(list2); + OpenimUsersAddResponse rsp = null; + try { + rsp = client.execute(req); + } catch (ApiException e) { + logger.info("openim add user fail",e); + } + System.out.println(rsp.getBody()); + } + + public static void main(String[] args) { + OpenimClient asd = new OpenimClient(); + asd.addUser(); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/package-info.java b/src/main/java/au/com/royalpay/payment/manage/openim/package-info.java new file mode 100644 index 000000000..1fd29e619 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/package-info.java @@ -0,0 +1,5 @@ +/** + * @author kira + * @date 2018/7/11 + */ +package au.com.royalpay.payment.manage.openim; \ No newline at end of file From 59bb6d7160198cb84cf9263b7fd5de5deec62d82 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Wed, 11 Jul 2018 11:35:20 +0800 Subject: [PATCH 2/6] tmp --- .../payment/manage/openim/core/OpenimApi.java | 8 ++ .../manage/openim/core/OpenimClient.java | 77 ++++++++++++++++--- .../openim/core/impl/OpenimApiImpl.java | 10 +++ .../payment/manage/openim/package-info.java | 5 -- 4 files changed, 86 insertions(+), 14 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java delete mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/package-info.java diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java new file mode 100644 index 000000000..3f01c1a35 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java @@ -0,0 +1,8 @@ +package au.com.royalpay.payment.manage.openim.core; + +/** + * @author kira + * @date 2018/7/11 + */ +public interface OpenimApi { +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java index 663c96058..a8906d545 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java @@ -4,14 +4,19 @@ import com.taobao.api.ApiException; import com.taobao.api.DefaultTaobaoClient; import com.taobao.api.TaobaoClient; import com.taobao.api.domain.Userinfos; +import com.taobao.api.request.OpenimCustmsgPushRequest; import com.taobao.api.request.OpenimUsersAddRequest; +import com.taobao.api.request.OpenimUsersUpdateRequest; +import com.taobao.api.response.OpenimCustmsgPushResponse; import com.taobao.api.response.OpenimUsersAddResponse; +import com.taobao.api.response.OpenimUsersUpdateResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /** @@ -21,12 +26,12 @@ 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 add_user="https://eco.taobao.com/router/rest"; + private final String appkey = "24960261"; + private final String secret = "7639427973bd671be15c9d0c1e9c90b4"; + private final String url = "https://eco.taobao.com/router/rest"; - public void addUser(){ - TaobaoClient client = new DefaultTaobaoClient(add_user, appkey, secret); + public void addUser() { + TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersAddRequest req = new OpenimUsersAddRequest(); List list2 = new ArrayList<>(); Userinfos obj3 = new Userinfos(); @@ -54,13 +59,67 @@ private final String add_user="https://eco.taobao.com/router/rest"; try { rsp = client.execute(req); } catch (ApiException e) { - logger.info("openim add user fail",e); + logger.info("openim add user fail", e); } System.out.println(rsp.getBody()); } - public static void main(String[] args) { - OpenimClient asd = new OpenimClient(); - asd.addUser(); + public void updateUser() { + TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); + OpenimUsersUpdateRequest req = new OpenimUsersUpdateRequest(); + List list2 = new ArrayList(); + Userinfos obj3 = new Userinfos(); + list2.add(obj3); + obj3.setNick("king"); + obj3.setIconUrl("http://xxx.com/xxx"); + obj3.setEmail("uid@taobao.com"); + obj3.setMobile("18600000000"); + obj3.setTaobaoid("tbnick123"); + obj3.setUserid("imuser123"); + obj3.setPassword("xxxxxx"); + obj3.setRemark("demo"); + obj3.setExtra("{}"); + obj3.setCareer("demo"); + obj3.setVip("{}"); + obj3.setAddress("demo"); + obj3.setName("demo"); + obj3.setAge(123L); + obj3.setGender("M"); + obj3.setWechat("demo"); + obj3.setQq("demo"); + obj3.setWeibo("demo"); + req.setUserinfos(list2); + OpenimUsersUpdateResponse rsp = null; + try { + rsp = client.execute(req); + } catch (ApiException e) { + logger.info("openim update user fail", e); + } + System.out.println(rsp.getBody()); } + + public void pushMsg(){ + TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); + OpenimCustmsgPushRequest req = new OpenimCustmsgPushRequest(); + OpenimCustmsgPushRequest.CustMsg obj1 = new OpenimCustmsgPushRequest.CustMsg(); + obj1.setFromUser("user_sender"); + obj1.setToAppkey("0"); + obj1.setToUsers(Collections.singletonList("user1")); + obj1.setSummary("客户端最近消息里面显示的消息摘要"); + obj1.setData("push payload"); + obj1.setAps("{\"alert\":\"ios apns push\"}"); + obj1.setApnsParam("apns推送的附带数据"); + obj1.setInvisible(0L); + obj1.setFromNick("sender_nick"); + obj1.setFromTaobao(0L); + req.setCustmsg(obj1); + OpenimCustmsgPushResponse rsp = null; + try { + rsp = client.execute(req); + } catch (ApiException e) { + logger.info("openim push msg fail", e); + } + System.out.println(rsp.getBody()); + } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java new file mode 100644 index 000000000..268d79331 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java @@ -0,0 +1,10 @@ +package au.com.royalpay.payment.manage.openim.core.impl; + +import au.com.royalpay.payment.manage.openim.core.OpenimApi; + +/** + * @author kira + * @date 2018/7/11 + */ +public class OpenimApiImpl implements OpenimApi{ +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/package-info.java b/src/main/java/au/com/royalpay/payment/manage/openim/package-info.java deleted file mode 100644 index 1fd29e619..000000000 --- a/src/main/java/au/com/royalpay/payment/manage/openim/package-info.java +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @author kira - * @date 2018/7/11 - */ -package au.com.royalpay.payment.manage.openim; \ No newline at end of file From 2416999408c41c6fbaa5f6db5e1f6711319d8957 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Wed, 11 Jul 2018 13:51:08 +0800 Subject: [PATCH 3/6] update --- .../payment/manage/openim/beans/AddUser.java | 170 ++++++++++++++++++ .../manage/openim/core/OpenimClient.java | 41 +++-- .../openim/core/impl/OpenimApiImpl.java | 2 +- 3 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/beans/AddUser.java diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/beans/AddUser.java b/src/main/java/au/com/royalpay/payment/manage/openim/beans/AddUser.java new file mode 100644 index 000000000..3c5204c9f --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/beans/AddUser.java @@ -0,0 +1,170 @@ +package au.com.royalpay.payment.manage.openim.beans; + +/** + * @author kira + * @date 2018/7/11 + */ +public class AddUser { + private String nick; + private String icon_url; + private String email; + private String mobile; + private String taobaoid; + private String userid; + private String passowrd; + private String remark; + private String extra; + private String career; + private String vip; + private String address; + private String name; + private int age; + private String gender; + private String wechat; + private String qq; + private String weibo; + + public String getNick() { + return nick; + } + + public void setNick(String nick) { + this.nick = nick; + } + + public String getIcon_url() { + return icon_url; + } + + public void setIcon_url(String icon_url) { + this.icon_url = icon_url; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getMobile() { + return mobile; + } + + public void setMobile(String mobile) { + this.mobile = mobile; + } + + public String getTaobaoid() { + return taobaoid; + } + + public void setTaobaoid(String taobaoid) { + this.taobaoid = taobaoid; + } + + public String getUserid() { + return userid; + } + + public void setUserid(String userid) { + this.userid = userid; + } + + public String getPassowrd() { + return passowrd; + } + + public void setPassowrd(String passowrd) { + this.passowrd = passowrd; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + + public String getExtra() { + return extra; + } + + public void setExtra(String extra) { + this.extra = extra; + } + + public String getCareer() { + return career; + } + + public void setCareer(String career) { + this.career = career; + } + + public String getVip() { + return vip; + } + + public void setVip(String vip) { + this.vip = vip; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public int getAge() { + return age; + } + + public void setAge(int age) { + this.age = age; + } + + public String getGender() { + return gender; + } + + public void setGender(String gender) { + this.gender = gender; + } + + public String getWechat() { + return wechat; + } + + public void setWechat(String wechat) { + this.wechat = wechat; + } + + public String getQq() { + return qq; + } + + public void setQq(String qq) { + this.qq = qq; + } + + public String getWeibo() { + return weibo; + } + + public void setWeibo(String weibo) { + this.weibo = weibo; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java index a8906d545..89d46636e 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java @@ -6,9 +6,11 @@ import com.taobao.api.TaobaoClient; import com.taobao.api.domain.Userinfos; import com.taobao.api.request.OpenimCustmsgPushRequest; import com.taobao.api.request.OpenimUsersAddRequest; +import com.taobao.api.request.OpenimUsersGetRequest; import com.taobao.api.request.OpenimUsersUpdateRequest; import com.taobao.api.response.OpenimCustmsgPushResponse; import com.taobao.api.response.OpenimUsersAddResponse; +import com.taobao.api.response.OpenimUsersGetResponse; import com.taobao.api.response.OpenimUsersUpdateResponse; import org.slf4j.Logger; @@ -30,30 +32,31 @@ public class OpenimClient { private final String secret = "7639427973bd671be15c9d0c1e9c90b4"; private final String url = "https://eco.taobao.com/router/rest"; + public void getUser(){ + TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); + OpenimUsersGetRequest req = new OpenimUsersGetRequest(); + req.setUserids("imuser123456"); + OpenimUsersGetResponse rsp = null; + try { + rsp = client.execute(req); + } catch (ApiException e) { + logger.info("openim get user fail", e); + } + System.out.println(rsp.getBody()); + } + + + public void addUser() { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersAddRequest req = new OpenimUsersAddRequest(); List list2 = new ArrayList<>(); Userinfos obj3 = new Userinfos(); list2.add(obj3); - obj3.setNick("king"); - obj3.setIconUrl("http://xxx.com/xxx"); - obj3.setEmail("uid@taobao.com"); obj3.setMobile("18600000000"); obj3.setTaobaoid("tbnick123"); - obj3.setUserid("imuser123"); + obj3.setUserid("imuser123456"); obj3.setPassword("xxxxxx"); - obj3.setRemark("demo"); - obj3.setExtra("{}"); - obj3.setCareer("demo"); - obj3.setVip("{}"); - obj3.setAddress("demo"); - obj3.setName("demo"); - obj3.setAge(123L); - obj3.setGender("M"); - obj3.setWechat("demo"); - obj3.setQq("demo"); - obj3.setWeibo("demo"); req.setUserinfos(list2); OpenimUsersAddResponse rsp = null; try { @@ -75,7 +78,7 @@ public class OpenimClient { obj3.setEmail("uid@taobao.com"); obj3.setMobile("18600000000"); obj3.setTaobaoid("tbnick123"); - obj3.setUserid("imuser123"); + obj3.setUserid("imuser12345"); obj3.setPassword("xxxxxx"); obj3.setRemark("demo"); obj3.setExtra("{}"); @@ -122,4 +125,10 @@ public class OpenimClient { System.out.println(rsp.getBody()); } + + public static void main(String[] args) { + OpenimClient asd = new OpenimClient(); + asd.addUser(); + asd.getUser(); + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java index 268d79331..fdfdf014b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java @@ -6,5 +6,5 @@ import au.com.royalpay.payment.manage.openim.core.OpenimApi; * @author kira * @date 2018/7/11 */ -public class OpenimApiImpl implements OpenimApi{ +public class OpenimApiImpl implements OpenimApi { } From 052fce1894202e1c10ca9753376d7ffebf371de3 Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Wed, 11 Jul 2018 15:05:21 +0800 Subject: [PATCH 4/6] tmp --- .../beans/{AddUser.java => OpenimUser.java} | 4 +- .../manage/openim/beans/PushMsgBean.java | 48 +++++++++++++++++++ .../manage/openim/core/OpenimClient.java | 15 +++--- 3 files changed, 58 insertions(+), 9 deletions(-) rename src/main/java/au/com/royalpay/payment/manage/openim/beans/{AddUser.java => OpenimUser.java} (98%) create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/beans/PushMsgBean.java diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/beans/AddUser.java b/src/main/java/au/com/royalpay/payment/manage/openim/beans/OpenimUser.java similarity index 98% rename from src/main/java/au/com/royalpay/payment/manage/openim/beans/AddUser.java rename to src/main/java/au/com/royalpay/payment/manage/openim/beans/OpenimUser.java index 3c5204c9f..52162d649 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/beans/AddUser.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/beans/OpenimUser.java @@ -4,7 +4,7 @@ package au.com.royalpay.payment.manage.openim.beans; * @author kira * @date 2018/7/11 */ -public class AddUser { +public class OpenimUser { private String nick; private String icon_url; private String email; @@ -18,7 +18,7 @@ public class AddUser { private String vip; private String address; private String name; - private int age; + private Integer age; private String gender; private String wechat; private String qq; diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/beans/PushMsgBean.java b/src/main/java/au/com/royalpay/payment/manage/openim/beans/PushMsgBean.java new file mode 100644 index 000000000..314dd3ebd --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/beans/PushMsgBean.java @@ -0,0 +1,48 @@ +package au.com.royalpay.payment.manage.openim.beans; + +import java.util.List; + +/** + * @author kira + * @date 2018/7/11 + */ +public class PushMsgBean { + + private String from_user; + private List to_users; + private String summary; + private String data; + + + public String getFrom_user() { + return from_user; + } + + public void setFrom_user(String from_user) { + this.from_user = from_user; + } + + public List getTo_users() { + return to_users; + } + + public void setTo_users(List to_users) { + this.to_users = to_users; + } + + public String getSummary() { + return summary; + } + + public void setSummary(String summary) { + this.summary = summary; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java index 89d46636e..92d3cfd6a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java @@ -1,5 +1,7 @@ package au.com.royalpay.payment.manage.openim.core; +import au.com.royalpay.payment.manage.openim.beans.OpenimUser; + import com.taobao.api.ApiException; import com.taobao.api.DefaultTaobaoClient; import com.taobao.api.TaobaoClient; @@ -32,10 +34,11 @@ public class OpenimClient { private final String secret = "7639427973bd671be15c9d0c1e9c90b4"; private final String url = "https://eco.taobao.com/router/rest"; - public void getUser(){ + public void getUser(String userId){ TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersGetRequest req = new OpenimUsersGetRequest(); - req.setUserids("imuser123456"); + // 批量为userid逗号分隔字符串 + req.setUserids(userId); OpenimUsersGetResponse rsp = null; try { rsp = client.execute(req); @@ -47,7 +50,7 @@ public class OpenimClient { - public void addUser() { + public void addUser(OpenimUser user) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersAddRequest req = new OpenimUsersAddRequest(); List list2 = new ArrayList<>(); @@ -67,7 +70,7 @@ public class OpenimClient { System.out.println(rsp.getBody()); } - public void updateUser() { + public void updateUser(List users) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersUpdateRequest req = new OpenimUsersUpdateRequest(); List list2 = new ArrayList(); @@ -125,10 +128,8 @@ public class OpenimClient { System.out.println(rsp.getBody()); } - public static void main(String[] args) { OpenimClient asd = new OpenimClient(); - asd.addUser(); - asd.getUser(); + asd.getUser("imuser123456"); } } From b3f1d26e7c515d94e562d704fc84c7c01e7bf73e Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Wed, 11 Jul 2018 15:39:59 +0800 Subject: [PATCH 5/6] tmp --- .../manage/openim/core/OpenimClient.java | 124 ++++++++++-------- 1 file changed, 68 insertions(+), 56 deletions(-) diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java index 92d3cfd6a..03677f43a 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java @@ -1,7 +1,8 @@ package au.com.royalpay.payment.manage.openim.core; -import au.com.royalpay.payment.manage.openim.beans.OpenimUser; +import au.com.royalpay.payment.tools.exceptions.ServerErrorException; +import com.alibaba.fastjson.JSONObject; import com.taobao.api.ApiException; import com.taobao.api.DefaultTaobaoClient; import com.taobao.api.TaobaoClient; @@ -19,8 +20,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; /** @@ -34,7 +33,7 @@ public class OpenimClient { private final String secret = "7639427973bd671be15c9d0c1e9c90b4"; private final String url = "https://eco.taobao.com/router/rest"; - public void getUser(String userId){ + public JSONObject getUser(String userId){ TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersGetRequest req = new OpenimUsersGetRequest(); // 批量为userid逗号分隔字符串 @@ -45,91 +44,104 @@ public class OpenimClient { } catch (ApiException e) { logger.info("openim get user fail", e); } - System.out.println(rsp.getBody()); + return JSONObject.parseObject(rsp.getBody()); } - public void addUser(OpenimUser user) { + public void addUser(List users) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersAddRequest req = new OpenimUsersAddRequest(); - List list2 = new ArrayList<>(); - Userinfos obj3 = new Userinfos(); - list2.add(obj3); - obj3.setMobile("18600000000"); - obj3.setTaobaoid("tbnick123"); - obj3.setUserid("imuser123456"); - obj3.setPassword("xxxxxx"); - req.setUserinfos(list2); + req.setUserinfos(users); OpenimUsersAddResponse rsp = null; try { rsp = client.execute(req); } catch (ApiException e) { logger.info("openim add user fail", e); } - System.out.println(rsp.getBody()); + JSONObject result =JSONObject.parseObject(rsp.getBody()); + if(result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").size()>1){ + logger.info("openim add user fail reason:"+result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); + throw new ServerErrorException("System error"); + } } public void updateUser(List users) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersUpdateRequest req = new OpenimUsersUpdateRequest(); - List list2 = new ArrayList(); - Userinfos obj3 = new Userinfos(); - list2.add(obj3); - obj3.setNick("king"); - obj3.setIconUrl("http://xxx.com/xxx"); - obj3.setEmail("uid@taobao.com"); - obj3.setMobile("18600000000"); - obj3.setTaobaoid("tbnick123"); - obj3.setUserid("imuser12345"); - obj3.setPassword("xxxxxx"); - obj3.setRemark("demo"); - obj3.setExtra("{}"); - obj3.setCareer("demo"); - obj3.setVip("{}"); - obj3.setAddress("demo"); - obj3.setName("demo"); - obj3.setAge(123L); - obj3.setGender("M"); - obj3.setWechat("demo"); - obj3.setQq("demo"); - obj3.setWeibo("demo"); - req.setUserinfos(list2); + req.setUserinfos(users); OpenimUsersUpdateResponse rsp = null; try { rsp = client.execute(req); } catch (ApiException e) { logger.info("openim update user fail", e); } - System.out.println(rsp.getBody()); + JSONObject result = JSONObject.parseObject(rsp.getBody()); + if(result.getJSONObject("openim_users_update_response").getJSONObject("fail_msg").size()>1){ + logger.info("openim add user fail reason:"+result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); + throw new ServerErrorException("System error"); + } } - public void pushMsg(){ + public JSONObject pushMsg(OpenimCustmsgPushRequest.CustMsg msg){ TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimCustmsgPushRequest req = new OpenimCustmsgPushRequest(); - OpenimCustmsgPushRequest.CustMsg obj1 = new OpenimCustmsgPushRequest.CustMsg(); - obj1.setFromUser("user_sender"); - obj1.setToAppkey("0"); - obj1.setToUsers(Collections.singletonList("user1")); - obj1.setSummary("客户端最近消息里面显示的消息摘要"); - obj1.setData("push payload"); - obj1.setAps("{\"alert\":\"ios apns push\"}"); - obj1.setApnsParam("apns推送的附带数据"); - obj1.setInvisible(0L); - obj1.setFromNick("sender_nick"); - obj1.setFromTaobao(0L); - req.setCustmsg(obj1); + req.setCustmsg(msg); OpenimCustmsgPushResponse rsp = null; try { rsp = client.execute(req); } catch (ApiException e) { logger.info("openim push msg fail", e); } - System.out.println(rsp.getBody()); + return JSONObject.parseObject(rsp.getBody()); } - public static void main(String[] args) { - OpenimClient asd = new OpenimClient(); - asd.getUser("imuser123456"); - } + +// public JSONObject test(){ +// TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); +// OpenimUsersUpdateRequest req = new OpenimUsersUpdateRequest(); +// List list2 = new ArrayList(); +// Userinfos obj3 = new Userinfos(); +// list2.add(obj3); +// obj3.setNick("king"); +// obj3.setIconUrl("http://xxx.com/xxx"); +// obj3.setEmail("uid@taobao.com"); +// obj3.setMobile("18600000000"); +// obj3.setTaobaoid("tbnick123"); +// obj3.setUserid("imuserkcbknefe123"); +// obj3.setPassword("xxxxxx"); +// obj3.setRemark("demo"); +// obj3.setExtra("{}"); +// obj3.setCareer("demo"); +// obj3.setVip("{}"); +// obj3.setAddress("demo"); +// obj3.setName("demo"); +// obj3.setAge(123L); +// obj3.setGender("M"); +// obj3.setWechat("demo"); +// obj3.setQq("demo"); +// obj3.setWeibo("demo"); +// req.setUserinfos(list2); +// OpenimUsersUpdateResponse rsp = null; +// try { +// rsp = client.execute(req); +// } catch (ApiException e) { +// e.printStackTrace(); +// } +// System.out.println(rsp.getBody()); +// return JSONObject.parseObject(rsp.getBody()); +// +// } +// public static void main(String[] args) { +// OpenimClient asd = new OpenimClient(); +// JSONObject zxc = asd.test(); +// System.out.println(zxc); +// System.out.println(zxc); +// System.out.println(zxc); +// JSONObject qwe = JSONObject.parseObject("{\"openim_users_add_response\":{\"uid_fail\":{\"string\":[\"imuser123asdasdasd\"]},\"uid_succ\":{},\"fail_msg\":{\"string\":[\"data exist\"]}}}"); +// +// System.out.println(qwe.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); +// System.out.println(qwe); +// System.out.println(qwe); +// } } From 954b9b6fd2ad17f99273147bf437813c114e9dca Mon Sep 17 00:00:00 2001 From: kira <164851225@qq.com> Date: Thu, 12 Jul 2018 10:22:42 +0800 Subject: [PATCH 6/6] tmp --- .../appclient/core/RetailAppService.java | 2 + .../core/impls/RetailAppServiceImp.java | 9 ++ .../appclient/web/RetailAppController.java | 63 ++++++----- .../manage/mappers/openim/OpenimMapper.java | 26 +++++ .../manage/openim/OpenimController.java | 34 ++++++ .../openim/core/CustomerServiceService.java | 12 ++ .../payment/manage/openim/core/OpenimApi.java | 12 ++ .../manage/openim/core/OpenimClient.java | 105 ++++++++---------- .../core/impl/CustomerServiceServiceImpl.java | 53 +++++++++ .../openim/core/impl/OpenimApiImpl.java | 54 +++++++++ .../resources/templates/customer_service.html | 25 +++++ src/main/ui/manage.html | 4 +- 12 files changed, 307 insertions(+), 92 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/mappers/openim/OpenimMapper.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/OpenimController.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/core/CustomerServiceService.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/openim/core/impl/CustomerServiceServiceImpl.java create mode 100644 src/main/resources/templates/customer_service.html diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java index c3cfc669f..0ff5470dc 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java @@ -149,4 +149,6 @@ public interface RetailAppService { void applyToCompliance(JSONObject device); JSONObject sendVerifyEmail(JSONObject device); + + void openimCheck(JSONObject device); } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java index 57dadf95b..c09e8246b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java @@ -30,6 +30,7 @@ import au.com.royalpay.payment.manage.merchants.entity.impls.SwitchPermissionMod import au.com.royalpay.payment.manage.notice.beans.NoticeInfo; import au.com.royalpay.payment.manage.notice.core.NoticeManage; import au.com.royalpay.payment.manage.notice.core.NoticePartner; +import au.com.royalpay.payment.manage.openim.core.CustomerServiceService; import au.com.royalpay.payment.manage.pushMessage.APNSMessageHelper; import au.com.royalpay.payment.manage.pushMessage.bean.AppManagerMessageBuilder; import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; @@ -166,6 +167,8 @@ public class RetailAppServiceImp implements RetailAppService { private ClientModifySupport clientModifySupport; @Resource private ClearingLogMapper clearingLogMapper; + @Resource + private CustomerServiceService customerServiceService; private Map senderMap = new HashMap<>(); private final String fileName[] = { "client_bank_file", "client_id_file", "client_company_file" }; @@ -410,6 +413,12 @@ public class RetailAppServiceImp implements RetailAppService { return result; } + @Override + public void openimCheck(JSONObject device) { + JSONObject account = clientAccountMapper.findById(device.getString("account_id")); + customerServiceService.checkAndSave(account); + } + @Override public void updateClient(JSONObject device, AppClientBean appClientBean) { String clientType = device.getString("client_type"); diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java index 9caa888d2..e22449561 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java @@ -1,34 +1,5 @@ package au.com.royalpay.payment.manage.appclient.web; -import static au.com.royalpay.payment.tools.CommonConsts.RETAIL_DEVICE; - -import java.math.BigDecimal; -import java.text.ParseException; -import java.util.Date; -import java.util.List; -import java.util.Map; - -import javax.annotation.Resource; -import javax.servlet.http.HttpServletResponse; -import javax.validation.Valid; - -import org.apache.commons.lang3.time.DateUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.validation.Errors; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestBody; -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.ResponseBody; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.servlet.ModelAndView; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; - import au.com.royalpay.payment.core.exceptions.ParamInvalidException; import au.com.royalpay.payment.manage.activities.app_index.core.AppActService; import au.com.royalpay.payment.manage.activities.monsettledelay.core.ActMonDelaySettleService; @@ -55,6 +26,35 @@ import au.com.royalpay.payment.tools.http.HttpUtils; import au.com.royalpay.payment.tools.merchants.beans.QRCodeConfig; import au.com.royalpay.payment.tools.merchants.beans.UpdateSurchargeDTO; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; + +import org.apache.commons.lang3.time.DateUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.validation.Errors; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestBody; +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.ResponseBody; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.servlet.ModelAndView; + +import java.math.BigDecimal; +import java.text.ParseException; +import java.util.Date; +import java.util.List; +import java.util.Map; + +import javax.annotation.Resource; +import javax.servlet.http.HttpServletResponse; +import javax.validation.Valid; + +import static au.com.royalpay.payment.tools.CommonConsts.RETAIL_DEVICE; + /** * Created by yishuqian on 28/03/2017. */ @@ -540,4 +540,9 @@ public class RetailAppController { return attachmentClient.uploadFile(file,false); } + @RequestMapping(value = "/openim/check",method = RequestMethod.POST) + public void openimCheck(@ModelAttribute(RETAIL_DEVICE) JSONObject device) { + retailAppService.openimCheck(device); + } + } diff --git a/src/main/java/au/com/royalpay/payment/manage/mappers/openim/OpenimMapper.java b/src/main/java/au/com/royalpay/payment/manage/mappers/openim/OpenimMapper.java new file mode 100644 index 000000000..16fc11adf --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/mappers/openim/OpenimMapper.java @@ -0,0 +1,26 @@ +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); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/OpenimController.java b/src/main/java/au/com/royalpay/payment/manage/openim/OpenimController.java new file mode 100644 index 000000000..ae3331c78 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/OpenimController.java @@ -0,0 +1,34 @@ +package au.com.royalpay.payment.manage.openim; + +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; + +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.RestController; + +import javax.annotation.Resource; + +/** + * @author kira + * @date 2018/7/11 + */ +@RestController +@RequestMapping("/sys/openim") +public class OpenimController { + + @Resource + private CustomerServiceService customerServiceService; + + + @RequestMapping(value = "/check",method = RequestMethod.POST) + @RequireManager + public void sendMsg(@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { + customerServiceService.checkAndSave(manager); + } + +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/CustomerServiceService.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/CustomerServiceService.java new file mode 100644 index 000000000..ef6dd0c88 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/CustomerServiceService.java @@ -0,0 +1,12 @@ +package au.com.royalpay.payment.manage.openim.core; + +import com.alibaba.fastjson.JSONObject; + +/** + * @author kira + * @date 2018/7/11 + */ +public interface CustomerServiceService { + + void checkAndSave(JSONObject account); +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java index 3f01c1a35..fb380b84f 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimApi.java @@ -1,8 +1,20 @@ package au.com.royalpay.payment.manage.openim.core; +import com.alibaba.fastjson.JSONObject; + /** * @author kira * @date 2018/7/11 */ public interface OpenimApi { + + void addUser(JSONObject record); + + void updateUser(); + + void pushMsh(); + + JSONObject getUserInfo(String userId); + + } diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java index 03677f43a..d1a126eef 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/OpenimClient.java @@ -6,12 +6,15 @@ import com.alibaba.fastjson.JSONObject; import com.taobao.api.ApiException; import com.taobao.api.DefaultTaobaoClient; import com.taobao.api.TaobaoClient; +import com.taobao.api.domain.OpenImUser; import com.taobao.api.domain.Userinfos; import com.taobao.api.request.OpenimCustmsgPushRequest; +import com.taobao.api.request.OpenimRelationsGetRequest; import com.taobao.api.request.OpenimUsersAddRequest; import com.taobao.api.request.OpenimUsersGetRequest; import com.taobao.api.request.OpenimUsersUpdateRequest; import com.taobao.api.response.OpenimCustmsgPushResponse; +import com.taobao.api.response.OpenimRelationsGetResponse; import com.taobao.api.response.OpenimUsersAddResponse; import com.taobao.api.response.OpenimUsersGetResponse; import com.taobao.api.response.OpenimUsersUpdateResponse; @@ -29,14 +32,16 @@ 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"; - public JSONObject getUser(String userId){ + public JSONObject getUser(String userId) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersGetRequest req = new OpenimUsersGetRequest(); - // 批量为userid逗号分隔字符串 + // 批量为userid逗号分隔字符串 req.setUserids(userId); OpenimUsersGetResponse rsp = null; try { @@ -47,8 +52,6 @@ public class OpenimClient { return JSONObject.parseObject(rsp.getBody()); } - - public void addUser(List users) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimUsersAddRequest req = new OpenimUsersAddRequest(); @@ -59,9 +62,10 @@ public class OpenimClient { } catch (ApiException e) { logger.info("openim add user fail", e); } - JSONObject result =JSONObject.parseObject(rsp.getBody()); - if(result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").size()>1){ - logger.info("openim add user fail reason:"+result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); + 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()); throw new ServerErrorException("System error"); } } @@ -76,14 +80,15 @@ public class OpenimClient { } catch (ApiException e) { logger.info("openim update user fail", e); } - JSONObject result = JSONObject.parseObject(rsp.getBody()); - if(result.getJSONObject("openim_users_update_response").getJSONObject("fail_msg").size()>1){ - logger.info("openim add user fail reason:"+result.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); + JSONObject result = JSONObject.parseObject(rsp.getBody()); + if (result.getJSONObject("openim_users_update_response").getJSONObject("fail_msg").size() > 0) { + logger.info("openim update user fail reason:" + + result.getJSONObject("openim_users_update_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); throw new ServerErrorException("System error"); } } - public JSONObject pushMsg(OpenimCustmsgPushRequest.CustMsg msg){ + public void pushMsg(OpenimCustmsgPushRequest.CustMsg msg) { TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); OpenimCustmsgPushRequest req = new OpenimCustmsgPushRequest(); req.setCustmsg(msg); @@ -93,55 +98,33 @@ public class OpenimClient { } catch (ApiException e) { logger.info("openim push msg fail", e); } - return JSONObject.parseObject(rsp.getBody()); + JSONObject result = JSONObject.parseObject(rsp.getBody()); + if (result.getJSONObject("openim_custmsg_push_response").getJSONObject("fail_msg").size() > 0) { + logger.info("openim push message fail reason:" + + result.getJSONObject("openim_custmsg_push_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); + throw new ServerErrorException("System error"); + } } -// public JSONObject test(){ -// TaobaoClient client = new DefaultTaobaoClient(url, appkey, secret); -// OpenimUsersUpdateRequest req = new OpenimUsersUpdateRequest(); -// List list2 = new ArrayList(); -// Userinfos obj3 = new Userinfos(); -// list2.add(obj3); -// obj3.setNick("king"); -// obj3.setIconUrl("http://xxx.com/xxx"); -// obj3.setEmail("uid@taobao.com"); -// obj3.setMobile("18600000000"); -// obj3.setTaobaoid("tbnick123"); -// obj3.setUserid("imuserkcbknefe123"); -// obj3.setPassword("xxxxxx"); -// obj3.setRemark("demo"); -// obj3.setExtra("{}"); -// obj3.setCareer("demo"); -// obj3.setVip("{}"); -// obj3.setAddress("demo"); -// obj3.setName("demo"); -// obj3.setAge(123L); -// obj3.setGender("M"); -// obj3.setWechat("demo"); -// obj3.setQq("demo"); -// obj3.setWeibo("demo"); -// req.setUserinfos(list2); -// OpenimUsersUpdateResponse rsp = null; -// try { -// rsp = client.execute(req); -// } catch (ApiException e) { -// e.printStackTrace(); -// } -// System.out.println(rsp.getBody()); -// return JSONObject.parseObject(rsp.getBody()); -// -// } -// public static void main(String[] args) { -// OpenimClient asd = new OpenimClient(); -// JSONObject zxc = asd.test(); -// System.out.println(zxc); -// System.out.println(zxc); -// System.out.println(zxc); -// JSONObject qwe = JSONObject.parseObject("{\"openim_users_add_response\":{\"uid_fail\":{\"string\":[\"imuser123asdasdasd\"]},\"uid_succ\":{},\"fail_msg\":{\"string\":[\"data exist\"]}}}"); -// -// System.out.println(qwe.getJSONObject("openim_users_add_response").getJSONObject("fail_msg").getJSONArray("string").toJSONString()); -// System.out.println(qwe); -// System.out.println(qwe); -// } + 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); + OpenimRelationsGetRequest req = new OpenimRelationsGetRequest(); + req.setBegDate("20180701"); + req.setEndDate("20180711"); + OpenImUser obj1 = new OpenImUser(); + obj1.setUid("imuser123"); + obj1.setTaobaoAccount(false); + req.setUser(obj1); + OpenimRelationsGetResponse rsp = null; + try { + rsp = client.execute(req); + } catch (ApiException e) { + e.printStackTrace(); + } + System.out.println(rsp.getBody()); + } } diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/CustomerServiceServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/CustomerServiceServiceImpl.java new file mode 100644 index 000000000..2179dc562 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/CustomerServiceServiceImpl.java @@ -0,0 +1,53 @@ +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.CustomerServiceService; +import au.com.royalpay.payment.manage.openim.core.OpenimApi; + +import com.alibaba.fastjson.JSONObject; + +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; + +/** + * @author kira + * @date 2018/7/11 + */ +@Service +public class CustomerServiceServiceImpl implements CustomerServiceService { + + @Resource + private OpenimMapper openimMapper; + @Resource + private OpenimApi openimApi; + + + @Override + public void checkAndSave(JSONObject account) { + boolean isPartner = true; + if (StringUtils.isNotEmpty(account.getString("account_id"))) { + isPartner = true; + } + 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); + } + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java index fdfdf014b..8e97ed004 100644 --- a/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/openim/core/impl/OpenimApiImpl.java @@ -1,10 +1,64 @@ 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; + +import org.springframework.stereotype.Service; + +import java.util.ArrayList; +import java.util.List; + +import javax.annotation.Resource; /** * @author kira * @date 2018/7/11 */ +@Service public class OpenimApiImpl implements OpenimApi { + + @Resource + private OpenimClient openimClient; + @Resource + private OpenimMapper openimMapper; + + @Override + public void addUser(JSONObject user) { + List saveList = new ArrayList<>(); + Userinfos record = new Userinfos(); + record.setUserid(user.getString("user_id")); + record.setNick(user.getString("nick")); + record.setPassword("XXXXXX"); + 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 + public void updateUser() { + + } + + @Override + public void pushMsh() { + + } + + @Override + public JSONObject getUserInfo(String userId) { + return openimClient.getUser(userId); + } } diff --git a/src/main/resources/templates/customer_service.html b/src/main/resources/templates/customer_service.html new file mode 100644 index 000000000..6a28a917e --- /dev/null +++ b/src/main/resources/templates/customer_service.html @@ -0,0 +1,25 @@ + + + + + + + + + diff --git a/src/main/ui/manage.html b/src/main/ui/manage.html index a5e3f5bdb..b7e61091f 100644 --- a/src/main/ui/manage.html +++ b/src/main/ui/manage.html @@ -307,13 +307,13 @@ margin-bottom: 10%;"/> -