From 30d8e227e8d823b6c38c3b9c90ac2df03b63befe Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 25 二月 2025 16:41:22 +0800 Subject: [PATCH] 淘宝转链接口更新 --- fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java | 554 +++++++++++++++++++++++++++---------------------------- 1 files changed, 272 insertions(+), 282 deletions(-) diff --git a/fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java b/fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java index 23ad364..555c853 100644 --- a/fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java +++ b/fanli/src/main/java/com/yeshi/fanli/controller/admin/PushController.java @@ -1,282 +1,272 @@ -package com.yeshi.fanli.controller.admin; - -import java.io.PrintWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import javax.annotation.Resource; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.yeshi.utils.HttpUtil; -import org.yeshi.utils.JsonUtil; - -import com.google.gson.Gson; -import com.google.gson.reflect.TypeToken; -import com.yeshi.fanli.entity.bus.msg.UserSystemMsg; -import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum; -import com.yeshi.fanli.exception.PushException; -import com.yeshi.fanli.service.inter.msg.UserSystemMsgService; -import com.yeshi.fanli.service.inter.push.PushService; -import com.yeshi.fanli.util.StringUtil; -import com.yeshi.fanli.util.factory.IOSPushFactory; - -import net.sf.json.JSONObject; - -@Controller(value = "adminPushController") -@RequestMapping("admin/new/api/v1/push") -public class PushController { - - public final static int GOODS = 1; // 鍟嗗搧鎺ㄩ�� - public final static int URL = 2; // 缃戦〉鎺ㄩ�� - public final static int DETAIL = 3; // 璇︽儏鎺ㄩ�� - public final static int ZNX = 4; // 绔欏唴鎺ㄩ�� - public final static int WEEX = 5; // 绔欏唴鎺ㄩ�� - public final static int BAICHUAN = 6; // 绔欏唴鎺ㄩ�� - public final static int WELFARE_CENTER = 7; // 绂忓埄涓績 - - - @Resource - private PushService pushService; - - @Resource - private UserSystemMsgService userSystemMsgService; - - - /** - * 鐭摼鎺ヨ浆鎹� - * - * @param url - * @param out - * @throws Exception - */ - @RequestMapping(value = "convertLink") - public void convertLink(String callback, String url, PrintWriter out) { - - if (StringUtil.isNullOrEmpty(url)) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("杞摼鏁版嵁涓嶈兘涓虹┖")); - return; - } - - try { - String shortLink = org.yeshi.utils.HttpUtil.getShortLink(url); - - JSONObject jsonData = new JSONObject(); - jsonData.put("url", url); - jsonData.put("shortLink", shortLink); - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(jsonData)); - - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("杞崲澶辫触")); - e.printStackTrace(); - } - } - - - /** - * 缃戦〉鎺ㄩ�� -(鏂板悗鍙�) - * - * @param url - * @param title - * @param content - * @param out - * @throws Exception - */ - @RequestMapping(value = "newPushUrlAll") - public void newPushUrlAll(String callback, String url, String title, String content, String uids, - String arrayIOS, String arrayAndroid, PrintWriter out) { - - if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欓摼鎺ワ紝鏍囬涓庡唴瀹�")); - return; - } - - JSONObject json = IOSPushFactory.createURLPush(HttpUtil.getShortLink(url), title, content); - if (json.toString().getBytes().length > 256) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏍囬鎴栧唴瀹硅繃闀匡紝璇峰垹鍑忓悗鍐嶈瘯")); - return; - } - - try { - - List<String> listuid = null; - if (uids != null && uids.trim().length() > 0) { - listuid = Arrays.asList(uids.split(",")); - if (listuid == null || listuid.size() == 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛id鏍煎紡涓嶆纭�")); - return; - } - } - - if ((arrayIOS == null || arrayIOS.trim().length() == 0) - && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�")); - return; - } - - List<String> listIOS = convertList(arrayIOS); - List<String> listAndroid = convertList(arrayAndroid); - - if (listuid == null) { - // 鍏ㄦ帹 - pushService.pushUrl(null, title, content, url, listIOS, listAndroid); - } else { - // 閮ㄥ垎鎺ㄩ�� - for (String str_uid: listuid) { - if (str_uid != null && str_uid.trim().length() > 0) { - pushService.pushUrl(Long.parseLong(str_uid), url, title, content, listIOS, listAndroid); - } - } - } - - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎺ㄩ�佹垚鍔�")); - } catch (PushException e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佸け璐�")); - e.printStackTrace(); - } - } - - /** - * - * 鏂规硶璇存槑: 绔欏唴淇℃帹閫� -(鏂板悗鍙�) - * - * @param uId - * @param title - * @param content - * @throws Exception - */ - @RequestMapping(value = "newPushFanZNX") - public void newPushFanZNX(String callback, String uids, String title, String content, String arrayIOS, - String arrayAndroid, PrintWriter out) { - - if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欐爣棰樹笌鍐呭")); - return; - } - - try { - - List<String> listuid = null; - if (uids != null && uids.trim().length() > 0) { - listuid = Arrays.asList(uids.split(",")); - if (listuid == null || listuid.size() == 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛id鏍煎紡涓嶆纭�")); - return; - } - } - - - if ((arrayIOS == null || arrayIOS.trim().length() == 0) - && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�")); - return; - } - - List<String> listIOS = convertList(arrayIOS); - List<String> listAndroid = convertList(arrayAndroid); - - if (listuid == null) { - // 鍏ㄦ帹 - pushService.pushZNX(null, title, content, listIOS, listAndroid); - } else { - // 閮ㄥ垎鎺ㄩ�� - for (String str_uid: listuid) { - if (str_uid != null && str_uid.trim().length() > 0) { - pushService.pushZNX(Long.parseLong(str_uid), title, content, listIOS, listAndroid); - - userSystemMsgService.addUserSystemMsg(Long.parseLong(str_uid), UserSystemMsgTypeEnum.question, - title, content, UserSystemMsg.TIME_TAG_EMERGENT, null); - } - } - } - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎺ㄩ�佹垚鍔�")); - } catch (PushException e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佸け璐�")); - e.printStackTrace(); - } - } - - /** - * - * 鏂规硶璇存槑: 鐧惧窛鎺ㄩ�� -(鏂板悗鍙�) - * - * @param uId - * @param title - * @param content - * @throws Exception - */ - @RequestMapping(value = "pushBaiChuan") - public void pushBaiChuan(String callback, String uids, String title, String content, String url, String arrayIOS, - String arrayAndroid, PrintWriter out) { - - if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欐爣棰樹笌鍐呭")); - return; - } - - try { - - List<String> listuid = null; - if (uids != null && uids.trim().length() > 0) { - listuid = Arrays.asList(uids.split(",")); - if (listuid == null || listuid.size() == 0) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛id鏍煎紡涓嶆纭�")); - return; - } - } - - if ((arrayIOS == null || arrayIOS.trim().length() == 0) - && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�")); - return; - } - - List<String> listIOS = convertList(arrayIOS); - List<String> listAndroid = convertList(arrayAndroid); - - if (listuid == null) { - // 鍏ㄦ帹 - pushService.pushBaiChuanUrl(null, title, content, url, listIOS, listAndroid); - } else { - // 閮ㄥ垎鎺ㄩ�� - for (String str_uid: listuid) { - if (str_uid != null && str_uid.trim().length() > 0) { - pushService.pushBaiChuanUrl(Long.parseLong(str_uid), title, content, url, listIOS, listAndroid); - } - } - } - JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎺ㄩ�佹垚鍔�")); - - } catch (PushException e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); - } catch (Exception e) { - JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佸け璐�")); - e.printStackTrace(); - } - } - - - /** - * 鐗堟湰澶勭悊 - * @param array - * @return - */ - public List<String> convertList (String array) { - Gson gson = new Gson(); - List<String> list = null; - if (array == null || array.trim().length() == 0) { - list = new ArrayList<String>(); // 闀垮害涓�0 涓嶆帹閫� - } else { - list = gson.fromJson(array, new TypeToken<ArrayList<String>>() {}.getType()); - if (list != null && list.size() > 0 && list.contains("鍏ㄦ帹")) { - list = null; // 鍏ㄦ帹 - } - } - return list; - } -} +package com.yeshi.fanli.controller.admin; + +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import javax.annotation.Resource; + +import com.yeshi.fanli.entity.accept.AdminAcceptData; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.yeshi.utils.HttpUtil; +import org.yeshi.utils.JsonUtil; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.yeshi.fanli.entity.bus.msg.UserSystemMsg; +import com.yeshi.fanli.entity.bus.msg.UserSystemMsgTypeEnum; +import com.yeshi.fanli.exception.push.PushException; +import com.yeshi.fanli.service.inter.msg.UserSystemMsgService; +import com.yeshi.fanli.service.inter.push.PushService; +import com.yeshi.fanli.util.StringUtil; +import com.yeshi.fanli.util.factory.IOSPushFactory; + +import net.sf.json.JSONObject; + +@Controller(value = "adminPushController") +@RequestMapping("admin/new/api/v1/push") +public class PushController { + + @Resource + private PushService pushService; + + @Resource + private UserSystemMsgService userSystemMsgService; + + + /** + * 鐭摼鎺ヨ浆鎹� + * + * @param url + * @param out + * @throws Exception + */ + @RequestMapping(value = "convertLink") + public void convertLink(AdminAcceptData acceptData,String callback, String url, PrintWriter out) { + + if (StringUtil.isNullOrEmpty(url)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("杞摼鏁版嵁涓嶈兘涓虹┖")); + return; + } + + try { + String shortLink = org.yeshi.utils.HttpUtil.getShortLink(url); + + JSONObject jsonData = new JSONObject(); + jsonData.put("url", url); + jsonData.put("shortLink", shortLink); + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(jsonData)); + + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("杞崲澶辫触")); + e.printStackTrace(); + } + } + + + /** + * 缃戦〉鎺ㄩ�� -(鏂板悗鍙�) + * + * @param url + * @param title + * @param content + * @param out + * @throws Exception + */ + @RequestMapping(value = "newPushUrlAll") + public void newPushUrlAll(AdminAcceptData acceptData, String callback, String url, String title, String content, String uids, + String arrayIOS, String arrayAndroid, PrintWriter out) { + + if (StringUtil.isNullOrEmpty(url) || StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欓摼鎺ワ紝鏍囬涓庡唴瀹�")); + return; + } + + JSONObject json = IOSPushFactory.createURLPush(HttpUtil.getShortLink(url), title, content); + if (json.toString().getBytes().length > 256) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鏍囬鎴栧唴瀹硅繃闀匡紝璇峰垹鍑忓悗鍐嶈瘯")); + return; + } + + try { + + List<String> listuid = null; + if (uids != null && uids.trim().length() > 0) { + listuid = Arrays.asList(uids.split(",")); + if (listuid == null || listuid.size() == 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛id鏍煎紡涓嶆纭�")); + return; + } + } + + if ((arrayIOS == null || arrayIOS.trim().length() == 0) + && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�")); + return; + } + + List<String> listIOS = convertList(arrayIOS); + List<String> listAndroid = convertList(arrayAndroid); + + if (listuid == null) { + // 鍏ㄦ帹 + pushService.pushUrl(null, title, content, url, listIOS, listAndroid,acceptData.getSystem()); + } else { + // 閮ㄥ垎鎺ㄩ�� + for (String str_uid: listuid) { + if (str_uid != null && str_uid.trim().length() > 0) { + pushService.pushUrl(Long.parseLong(str_uid), title, content, url, listIOS, listAndroid,acceptData.getSystem()); + } + } + } + + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎺ㄩ�佹垚鍔�")); + } catch (PushException e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佸け璐�")); + e.printStackTrace(); + } + } + + /** + * + * 鏂规硶璇存槑: 绔欏唴淇℃帹閫� -(鏂板悗鍙�) + * + * @param title + * @param content + * @throws Exception + */ + @RequestMapping(value = "newPushFanZNX") + public void newPushFanZNX(AdminAcceptData acceptData,String callback, String uids, String title, String content, String arrayIOS, + String arrayAndroid, PrintWriter out) { + + if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欐爣棰樹笌鍐呭")); + return; + } + + try { + + List<String> listuid = null; + if (uids != null && uids.trim().length() > 0) { + listuid = Arrays.asList(uids.split(",")); + if (listuid == null || listuid.size() == 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛id鏍煎紡涓嶆纭�")); + return; + } + } + + + if ((arrayIOS == null || arrayIOS.trim().length() == 0) + && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�")); + return; + } + + List<String> listIOS = convertList(arrayIOS); + List<String> listAndroid = convertList(arrayAndroid); + + if (listuid == null) { + // 鍏ㄦ帹 + pushService.pushZNX(null, title, content, listIOS, listAndroid,acceptData.getSystem()); + } else { + // 閮ㄥ垎鎺ㄩ�� + for (String str_uid: listuid) { + if (str_uid != null && str_uid.trim().length() > 0) { + pushService.pushZNX(Long.parseLong(str_uid), title, content, listIOS, listAndroid,acceptData.getSystem()); + + userSystemMsgService.addUserSystemMsg(Long.parseLong(str_uid), UserSystemMsgTypeEnum.question, + title, content, UserSystemMsg.TIME_TAG_EMERGENT, null); + } + } + } + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎺ㄩ�佹垚鍔�")); + } catch (PushException e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佸け璐�")); + e.printStackTrace(); + } + } + + /** + * + * 鏂规硶璇存槑: 鐧惧窛鎺ㄩ�� -(鏂板悗鍙�) + * + * @param title + * @param content + * @throws Exception + */ + @RequestMapping(value = "pushBaiChuan") + public void pushBaiChuan(AdminAcceptData acceptData,String callback, String uids, String title, String content, String url, String arrayIOS, + String arrayAndroid, PrintWriter out) { + + if (StringUtil.isNullOrEmpty(title) || StringUtil.isNullOrEmpty(content)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("璇峰~鍐欐爣棰樹笌鍐呭")); + return; + } + + try { + + List<String> listuid = null; + if (uids != null && uids.trim().length() > 0) { + listuid = Arrays.asList(uids.split(",")); + if (listuid == null || listuid.size() == 0) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鐢ㄦ埛id鏍煎紡涓嶆纭�")); + return; + } + } + + if ((arrayIOS == null || arrayIOS.trim().length() == 0) + && (arrayAndroid == null || arrayAndroid.trim().length() == 0)) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佺増鏈笉鑳戒负绌�")); + return; + } + + List<String> listIOS = convertList(arrayIOS); + List<String> listAndroid = convertList(arrayAndroid); + + if (listuid == null) { + // 鍏ㄦ帹 + pushService.pushBaiChuanUrl(null, title, content, url, listIOS, listAndroid,acceptData.getSystem()); + } else { + // 閮ㄥ垎鎺ㄩ�� + for (String str_uid: listuid) { + if (str_uid != null && str_uid.trim().length() > 0) { + pushService.pushBaiChuanUrl(Long.parseLong(str_uid), title, content, url, listIOS, listAndroid,acceptData.getSystem()); + } + } + } + JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("鎺ㄩ�佹垚鍔�")); + + } catch (PushException e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg())); + } catch (Exception e) { + JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("鎺ㄩ�佸け璐�")); + e.printStackTrace(); + } + } + + + /** + * 鐗堟湰澶勭悊 + * @param array + * @return + */ + public List<String> convertList (String array) { + Gson gson = new Gson(); + List<String> list = null; + if (array == null || array.trim().length() == 0) { + list = new ArrayList<String>(); // 闀垮害涓�0 涓嶆帹閫� + } else { + list = gson.fromJson(array, new TypeToken<ArrayList<String>>() {}.getType()); + if (list != null && list.size() > 0 && list.contains("鍏ㄦ帹")) { + list = null; // 鍏ㄦ帹 + } + } + return list; + } +} -- Gitblit v1.8.0