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