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 c2bde34ce..c96ee2e82 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 @@ -150,7 +150,9 @@ public interface RetailAppService { JSONObject sendVerifyEmail(JSONObject device); - void openimCheck(JSONObject device); + JSONObject openimCheck(JSONObject device); + + void addUnreadMsg(JSONObject device,JSONObject param); JSONObject getRefunds(JSONObject device, AppQueryBean appQueryBean); 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 3b5b25be9..e11eb9228 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 @@ -417,9 +417,14 @@ public class RetailAppServiceImp implements RetailAppService { } @Override - public void openimCheck(JSONObject device) { + public JSONObject openimCheck(JSONObject device) { JSONObject account = clientAccountMapper.findById(device.getString("account_id")); - customerServiceService.checkAndSave(account); + return customerServiceService.checkAndSave(account); + } + + @Override + public void addUnreadMsg(JSONObject device, JSONObject param) { + customerServiceService.addUnreadMsg(param); } @Override 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 6d3ec3dd2..ff78abf7d 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 @@ -545,7 +545,12 @@ public class RetailAppController { } @RequestMapping(value = "/openim/check",method = RequestMethod.POST) - public void openimCheck(@ModelAttribute(RETAIL_DEVICE) JSONObject device) { + public JSONObject openimCheck(@ModelAttribute(RETAIL_DEVICE) JSONObject device) { + return retailAppService.openimCheck(device); + } + + @RequestMapping(value = "/openim/chat",method = RequestMethod.POST) + public void openimChat(@ModelAttribute(RETAIL_DEVICE) JSONObject device,@RequestBody JSONObject param) { retailAppService.openimCheck(device); } 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 index 72207a9bb..d00549626 100644 --- 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 @@ -20,4 +20,8 @@ public interface CustomerServiceService { void onoff(JSONObject manager,boolean status); + void addUnreadMsg(JSONObject params); + + void sendUnreadWxMsg(); + } 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 8c48b6414..24a6de1bc 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 @@ -21,7 +21,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; -import java.util.ArrayList; import java.util.List; /** @@ -30,8 +29,6 @@ import java.util.List; */ @Service public class OpenimClient { - - Logger logger = LoggerFactory.getLogger(getClass()); @Value("${im.openim.appkey}") private String appkey; @@ -113,28 +110,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 list2 = new ArrayList(); - Userinfos obj3 = new Userinfos(); - list2.add(obj3); - obj3.setNick("king"); - obj3.setIconUrl("https://ss0.baidu.com/73t1bjeh1BF3odCf/it/u=1948403834,955109320&fm=85&s=0D06E5134AD145F30C8D6D680300303A"); - obj3.setUserid("huangjin"); - obj3.setPassword("xxxxxx"); - req.setUserinfos(list2); - OpenimUsersAddResponse 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 index 6a4b52c6c..ae5ce2b5d 100644 --- 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 @@ -7,6 +7,8 @@ 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.connections.mpsupport.MpWechatApiProvider; +import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage; import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.ForbiddenException; @@ -20,7 +22,9 @@ import org.springframework.stereotype.Service; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.Resource; @@ -41,6 +45,9 @@ public class CustomerServiceServiceImpl implements CustomerServiceService { private ManagerMapper managerMapper; @Resource private SysCustomerServiceMapper sysCustomerServiceMapper; + @Resource + private MpWechatApiProvider mpWechatApiProvider; + private final Map unReadMap = new HashMap<>(); @Value("${im.openim.appkey}") private String appkey; @@ -130,6 +137,44 @@ public class CustomerServiceServiceImpl implements CustomerServiceService { udpateOrSave(record); } + @Override + public void addUnreadMsg(JSONObject params) { + String key = params.getString("uid"); + if(unReadMap.containsKey(key)) { + unReadMap.put(key, unReadMap.get(key) + 1); + }else { + unReadMap.put(key,1L); + } + } + + @Override + public void sendUnreadWxMsg() { + unReadMap.entrySet().parallelStream().forEach(p->{ + JSONObject account = clientAccountMapper.findByUsername(p.getKey()); + if(StringUtils.isNotEmpty(account.getString("wx_openid"))){ +// TemplateMessage msg = initAccountMsg(tradeInfo, client.getString("short_name"), time, String.valueOf(counts), openId, paymentApi.getTemplateId("transaction-daily")); +// MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi(); +// paymentApi.sendTemplateMessage(msg); + } + p.getKey(); + }); + + } + + private TemplateMessage initAccountMsg(JSONObject tradeInfo, String short_name, String time, String clientCounts, String openId, String templateId) { + + TemplateMessage msg = new TemplateMessage(openId, templateId, null); + String detail = "收款总额:" + tradeInfo.getBigDecimal("total") + "$, 收款笔数:" + tradeInfo.getString("orders") + ", 付款人数:" + tradeInfo.getString("customers"); + msg.put("first", "每日交易汇总数据(" + tradeInfo.getString("trade_date") + ")", "#000000"); + msg.put("keyword1", short_name, "#000000"); + msg.put("keyword2", time, "#000000"); + msg.put("keyword3", clientCounts + "家", "#000000"); + msg.put("keyword4", detail, "#0000ff"); + msg.put("remark", "详情请查看商户后台、APP或皇家支付小程序", "#000000"); + msg.setMiniprogram("wx54445a7c56432d57", "/pages/welcome/welcome"); + return msg; + } + private void udpateOrSave(JSONObject servant){ JSONObject record = sysCustomerServiceMapper.findByManagerId(servant.getString("manager_id")); if(record==null){