From bbcd213feba6035890116edefcb4e8ac2945dbcb Mon Sep 17 00:00:00 2001 From: 陈杰 <504987307@qq.com> Date: Wed, 22 Jul 2020 09:58:22 +0800 Subject: [PATCH] 渠道商 动态码 --- src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java | 12 ++++++++++-- src/main/java/com/sincere/wechatbusiness/controller/CodeController.java | 58 ---------------------------------------------------------- src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/sincere/wechatbusiness/controller/TokenController.java | 157 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------ src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java | 2 ++ src/main/java/com/sincere/wechatbusiness/model/Channel.java | 11 +++++++++++ src/main/java/com/sincere/wechatbusiness/service/ChannelService.java | 4 ++-- src/main/java/com/sincere/wechatbusiness/service/impl/ChannelProductServiceImpl.java | 1 + src/main/java/com/sincere/wechatbusiness/service/impl/ChannelServiceImpl.java | 5 +++++ src/main/resources/mapper/ChannelMapper.xml | 5 +++++ src/main/resources/mapper/ChannelProductMapper.xml | 9 +++++++-- 11 files changed, 276 insertions(+), 88 deletions(-) delete mode 100644 src/main/java/com/sincere/wechatbusiness/controller/CodeController.java diff --git a/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java b/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java index ebbf347..4f7c21f 100644 --- a/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java +++ b/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java @@ -10,7 +10,6 @@ import com.sincere.wechatbusiness.logs.LogName; import com.sincere.wechatbusiness.logs.LoggerUtils; import com.sincere.wechatbusiness.model.*; import com.sincere.wechatbusiness.service.*; -import com.sincere.wechatbusiness.utils.HttpClientUtils; import com.sincere.wechatbusiness.utils.Page; import com.sincere.wechatbusiness.utils.TokenUtils; import io.swagger.annotations.ApiOperation; @@ -104,7 +103,7 @@ public class ChannelController { } } } - }else if(channel.getTemplateId() == 2){ + }else if(channel.getTemplateId() == 2 || channel.getTemplateId() == 3){ List banners = bannerService.getList(copyDto.getSourceId()); List bannerNexts = bannerService.getBannerNextList(copyDto.getSourceId()); for(Integer channelId : copyDto.getTargetIdList()){ @@ -119,6 +118,15 @@ public class ChannelController { bannerService.copyBannerNext(bannerNext); } } + }else if(channel.getTemplateId() == 4){ + List banners = bannerService.getList(copyDto.getSourceId()); + for(Integer channelId : copyDto.getTargetIdList()){ + bannerService.deleteChannelBanner(channelId); + for(Banner banner : banners){ + banner.setChannelId(channelId); + bannerService.copy(banner); + } + } } return new BaseDto(); } diff --git a/src/main/java/com/sincere/wechatbusiness/controller/CodeController.java b/src/main/java/com/sincere/wechatbusiness/controller/CodeController.java deleted file mode 100644 index 7c6f003..0000000 --- a/src/main/java/com/sincere/wechatbusiness/controller/CodeController.java +++ /dev/null @@ -1,58 +0,0 @@ -//package com.sincere.wechatbusiness.controller; -// -//import com.alibaba.fastjson.JSONObject; -//import com.sincere.wechatbusiness.utils.HttpClientUtils; -//import org.springframework.web.bind.annotation.RestController; -// -//import java.io.*; -//import java.net.HttpURLConnection; -//import java.net.URL; -// -//@RestController -//public class CodeController { -// -// private static String appId = "wxd055a716238e1bd7"; -// private static String secret = "c6912d34732b65116b8b4e9d5f8a81a5"; -// -// public static void main(String[] args){ -// String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret; -// JSONObject object = HttpClientUtils.httpGet(url) ; -// String token = object.get("access_token").toString(); -// try { -// URL imgUrl = new URL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token); -// HttpURLConnection httpURLConnection = (HttpURLConnection) imgUrl.openConnection(); -// httpURLConnection.setRequestMethod("POST");// 提交模式 -// // conn.setConnectTimeout(10000);//连接超时 单位毫秒 -// // conn.setReadTimeout(2000);//读取超时 单位毫秒 -// // 发送POST请求必须设置如下两行 -// httpURLConnection.setDoOutput(true); -// httpURLConnection.setDoInput(true); -// // 获取URLConnection对象对应的输出流 -// PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream()); -// // 发送请求参数 -// JSONObject paramJson = new JSONObject(); -// paramJson.put("scene", "channel=2"); -// paramJson.put("page", "pages/index/index"); -// paramJson.put("width", 430); -// paramJson.put("auto_color", true); -// printWriter.write(paramJson.toString()); -// // flush输出流的缓冲 -// printWriter.flush(); -// //开始获取数据 -// BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream()); -// OutputStream os = new FileOutputStream(new File("C:\\Users\\chen\\Desktop\\abc.png")); -// int len; -// byte[] arr = new byte[1024]; -// while ((len = bis.read(arr)) != -1) -// { -// os.write(arr, 0, len); -// os.flush(); -// } -// os.close(); -// } -// catch (Exception e) -// { -// e.printStackTrace(); -// } -// } -//} diff --git a/src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java b/src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java index f872c22..13351eb 100644 --- a/src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java +++ b/src/main/java/com/sincere/wechatbusiness/controller/ReportVoluntaryController.java @@ -1,17 +1,26 @@ package com.sincere.wechatbusiness.controller; import com.alibaba.fastjson.JSONObject; +import com.sincere.wechatbusiness.dto.BaseDto; +import com.sincere.wechatbusiness.model.Channel; import com.sincere.wechatbusiness.model.Order; import com.sincere.wechatbusiness.model.Users; import com.sincere.wechatbusiness.model.WxPay; +import com.sincere.wechatbusiness.service.ChannelService; import com.sincere.wechatbusiness.utils.HttpClientUtils; import io.swagger.annotations.ApiOperation; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; 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.RestController; +import java.io.*; +import java.net.HttpURLConnection; +import java.net.URL; + @RestController @RequestMapping("reportVoluntary") public class ReportVoluntaryController { @@ -19,6 +28,11 @@ public class ReportVoluntaryController { @Value("${reportVoluntary}") private String domain ; + @Autowired + ChannelService channelService; + + private static String appId = "wxd055a716238e1bd7"; + private static String secret = "c6912d34732b65116b8b4e9d5f8a81a5"; @ApiOperation("获取支付成功之后分享列表 coupon_type AI 1 || 专家 2 ") @RequestMapping(value = "/getShareCouponList" , method = RequestMethod.GET) @@ -110,4 +124,90 @@ public class ReportVoluntaryController { object.put("openid",pay.getOpenid()); return HttpClientUtils.httpPostJson(domain+"/Payment/WxPay",object.toJSONString()); } + + + @RequestMapping(value = "getData",method = RequestMethod.GET) + @ApiOperation(value = "type 1 ai 2 expert") + public JSONObject getData(int type){ + String url = domain+"/data/getData?type="+type ; + return HttpClientUtils.httpGet(url); + } + + @ApiOperation("获取商品列表 全部列表point传0 好评point传5") + @RequestMapping(value = "/getEvaluationList" , method = RequestMethod.GET) + public JSONObject getEvaluationList(int packageId , int point , int page , int pageSize){ + String url = domain+"/h5/order/getEvaluationList?packageId="+packageId+"&point="+point+"&page="+page+"&pageSize="+pageSize ; + return HttpClientUtils.httpGet(url); + } + + @ApiOperation("获取小程序动态码") + @RequestMapping(value = "/downloadSmallRoutine" , method = RequestMethod.GET) + public BaseDto downloadSmallRoutine(int channelId){ + BaseDto result = new BaseDto(); + Channel channel = channelService.getDetail(channelId); + if(StringUtils.isBlank(channel.getReportRoutineUrl())){ + createRoutine(channelId); + String prefix = domain.replaceAll("51314","51315"); + String url = prefix+"smallRoutine\\"+channelId+".png" ; + channel.setReportRoutineUrl(url); + channelService.updateRoutine(channelId,url); + } + result.setData(channel.getReportRoutineUrl()); + return result ; + + } + + public void createRoutine(int channelId){ + String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appId+"&secret="+secret; + JSONObject object = HttpClientUtils.httpGet(url) ; + String token = object.get("access_token").toString(); + try { + URL imgUrl = new URL("https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token="+token); + HttpURLConnection httpURLConnection = (HttpURLConnection) imgUrl.openConnection(); + httpURLConnection.setRequestMethod("POST");// 提交模式 + // conn.setConnectTimeout(10000);//连接超时 单位毫秒 + // conn.setReadTimeout(2000);//读取超时 单位毫秒 + // 发送POST请求必须设置如下两行 + httpURLConnection.setDoOutput(true); + httpURLConnection.setDoInput(true); + // 获取URLConnection对象对应的输出流 + PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream()); + // 发送请求参数 + JSONObject paramJson = new JSONObject(); + paramJson.put("scene", "channel="+channelId); + paramJson.put("page", "pages/index/index"); + paramJson.put("width", 430); + paramJson.put("auto_color", true); + printWriter.write(paramJson.toString()); + // flush输出流的缓冲 + printWriter.flush(); + //开始获取数据 + BufferedInputStream bis = new BufferedInputStream(httpURLConnection.getInputStream()); + OutputStream os = new FileOutputStream(new File("D:\\report\\img\\smallRoutine\\"+channelId+".png")); + int len; + byte[] arr = new byte[1024]; + while ((len = bis.read(arr)) != -1) + { + os.write(arr, 0, len); + os.flush(); + } + os.close(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + @ApiOperation("获取渠道商推广的用户") + @RequestMapping(value = "/getUserList" , method = RequestMethod.GET) + public JSONObject getUserList(int channelId , int page , int pageSize){ + JSONObject search = new JSONObject(); + search.put("userType",1); + search.put("page",page); + search.put("pageSize",pageSize); + search.put("channelId",channelId); + String url = domain+"/admin/Voluntary/GetUserList"; + return HttpClientUtils.httpPostJson(url,search.toJSONString()); + } } diff --git a/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java b/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java index 532639d..0f20a8c 100644 --- a/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java +++ b/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java @@ -3,18 +3,16 @@ package com.sincere.wechatbusiness.controller; import com.alibaba.fastjson.JSONObject; import com.sincere.wechatbusiness.mapper.ChannelMapper; import com.sincere.wechatbusiness.model.AccessToken; -import com.sincere.wechatbusiness.model.Channel; import com.sincere.wechatbusiness.model.Token; +import com.sincere.wechatbusiness.service.BannerService; +import com.sincere.wechatbusiness.service.ChannelProductService; import com.sincere.wechatbusiness.service.ChannelService; -import com.sincere.wechatbusiness.utils.HttpClientUtils; import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; -import java.io.BufferedReader; -import java.io.FileReader; import java.io.IOException; import java.io.InputStream; import java.net.HttpURLConnection; @@ -32,6 +30,12 @@ public class TokenController { @Autowired ChannelMapper channelMapper; + @Autowired + ChannelProductService channelProductService ; + + @Autowired + BannerService bannerService ; + private static String appId = "wx6078ff3f67524996" ; private static String secret = "8a0465b8ad0f000f568f48853e2818c8" ; @@ -99,24 +103,129 @@ public class TokenController { return token; } - @RequestMapping(value = "test",method = RequestMethod.GET) - public void test(){ - try { - FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); - BufferedReader bf = new BufferedReader(fr); - String str; - // 按行读取字符串 - while ((str = bf.readLine()) != null) { - Channel channel = channelMapper.getByName(str+"团购"); - int pageView = channelService.getPageViewCount(channel.getId(),0,3); - int register = channelService.getRegisterCount(channel.getId(),0,3); - int order = channelService.getOrderCount(channel.getId(),0,3); - System.out.println(str+"---浏览量:" + pageView+";---注册量:"+register+";---订单量:"+order); - } - bf.close(); - fr.close(); - } catch (IOException e) { - e.printStackTrace(); - } - } +// @RequestMapping(value = "test",method = RequestMethod.GET) +// public void test(){ +// try { +// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); +// BufferedReader bf = new BufferedReader(fr); +// String str; +// // 按行读取字符串 +// while ((str = bf.readLine()) != null) { +// Channel channel = channelMapper.getByName(str+"团购"); +// int pageView = channelService.getPageViewCount(channel.getId(),0,3); +// int register = channelService.getRegisterCount(channel.getId(),0,3); +// int order = channelService.getOrderCount(channel.getId(),0,3); +// System.out.println(str+"---浏览量:" + pageView+";---注册量:"+register+";---订单量:"+order); +// } +// bf.close(); +// fr.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } + +// @RequestMapping(value = "test2",method = RequestMethod.GET) +// public void test2(){ +// try { +// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\company.txt"); +// BufferedReader bf = new BufferedReader(fr); +// String str; +// // 按行读取字符串 +// while ((str = bf.readLine()) != null) { +// String[] msg = str.split(","); +// Channel channel = new Channel(); +// channel.setName("顺治"+msg[0]); +// channel.setMobile(msg[1]); +// channel.setProvince("浙江省"); +// channel.setCity("绍兴市"); +// channel.setTemplateId(4); +// channel.setState(1); +// channelService.insert(channel); +// for(int i = 1 ; i <= 2; i++){ +// ChannelProduct channelProduct = new ChannelProduct(); +// channelProduct.setChannelId(channel.getId()); +// JSONObject jsonObject = HttpClientUtils.httpGet("https://proxy.shunzhi.net:51314/University/getPackageById?id="+i); +// String data = jsonObject.getString("data"); +// DiscountPackage model= JSON.parseObject(data,new TypeReference(){}); +// channelProduct.setChannelTitle(model.getPackage_name()); +// channelProduct.setChannelImg(model.getPhoto()); +// channelProduct.setChannelRequire(model.getDescribe()); +// channelProduct.setChannelExplain(model.getRequire()); +// channelProduct.setProductId(i); +// channelProduct.setProductName(model.getPackage_name()); +// channelProduct.setPrice(model.getPrice()); +// channelProduct.setImgUrl(model.getPhoto()); +// if(i == 1){ +// channelProduct.setChannelPrice("199"); +// }else { +// channelProduct.setChannelPrice("999"); +// } +// channelProductService.insert(channelProduct); +// } +// } +// bf.close(); +// fr.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } + + +// @RequestMapping(value = "test3",method = RequestMethod.GET) +// public void test3(){ +// try { +// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\company.txt"); +// BufferedReader bf = new BufferedReader(fr); +// String str; +// // 按行读取字符串 +// List list = channelProductService.getList(1472); +// ChannelProduct aiProduct = new ChannelProduct(); +// ChannelProduct expertProduct = new ChannelProduct(); +// //List banners = bannerService.getList(1472); +// for(ChannelProduct channelProduct : list){ +// if(channelProduct.getProductId() == 1){ +// aiProduct = channelProduct; +// } +// if(channelProduct.getProductId() == 2){ +// expertProduct = channelProduct; +// } +// } +// while ((str = bf.readLine()) != null) { +// String name = str.split(",")[0]; +// Channel channel = channelMapper.getByName("顺治"+name); +// List products = channelProductService.getList(channel.getId()); +// int ai = 0, expert = 0 ; +// for(ChannelProduct channelProduct : products){ +// if(channelProduct.getProductId() == 1){ +// ai = channelProduct.getId(); +// channelProduct.setChannelRequire(null); +// channelProduct.setChannelExplain(aiProduct.getChannelExplain()); +// channelProductService.updateChannelProductMsg(channelProduct); +// }else { +// expert = channelProduct.getId(); +// channelProduct.setChannelRequire(null); +// channelProduct.setChannelExplain(expertProduct.getChannelExplain()); +// channelProductService.updateChannelProductMsg(channelProduct); +// } +// } +// +//// bannerService.deleteChannelBanner(channel.getId()); +//// for(Banner banner : banners){ +//// if(banner.getLinkUrl().equals("http://market.myjxt.com/wap/index.html#/CommodityDetail?id=1518&productId=1")){ +//// banner.setLinkUrl("http://market.myjxt.com/wap/index.html#/CommodityDetail?id="+ai+"&productId=1"); +//// }else if(banner.getLinkUrl().equals("http://market.myjxt.com/wap/index.html#/CommodityDetail?id=1517&productId=2")){ +//// banner.setLinkUrl("http://market.myjxt.com/wap/index.html#/CommodityDetail?id="+expert+"&productId=2"); +//// } +//// banner.setChannelId(channel.getId()); +//// bannerService.copy(banner); +//// } +// } +// bf.close(); +// fr.close(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } + + } diff --git a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java index 7813a28..ac217dc 100644 --- a/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java +++ b/src/main/java/com/sincere/wechatbusiness/mapper/ChannelMapper.java @@ -24,6 +24,8 @@ public interface ChannelMapper { int deleteChannel(int id); + int updateRoutine(@Param("id")int id , @Param("reportRoutineUrl")String reportRoutineUrl); + List getProvince(); List getCity(String areaCode); diff --git a/src/main/java/com/sincere/wechatbusiness/model/Channel.java b/src/main/java/com/sincere/wechatbusiness/model/Channel.java index d2a3aa1..8c936a4 100644 --- a/src/main/java/com/sincere/wechatbusiness/model/Channel.java +++ b/src/main/java/com/sincere/wechatbusiness/model/Channel.java @@ -28,8 +28,19 @@ public class Channel { private String cityCode; + //小程序 动态码 + private String reportRoutineUrl ; + private List channelProductList; + public String getReportRoutineUrl() { + return reportRoutineUrl; + } + + public void setReportRoutineUrl(String reportRoutineUrl) { + this.reportRoutineUrl = reportRoutineUrl; + } + public Integer getId() { return id; } diff --git a/src/main/java/com/sincere/wechatbusiness/service/ChannelService.java b/src/main/java/com/sincere/wechatbusiness/service/ChannelService.java index e834005..8b62045 100644 --- a/src/main/java/com/sincere/wechatbusiness/service/ChannelService.java +++ b/src/main/java/com/sincere/wechatbusiness/service/ChannelService.java @@ -2,8 +2,6 @@ package com.sincere.wechatbusiness.service; import com.sincere.wechatbusiness.model.*; import com.sincere.wechatbusiness.utils.Page; -import org.apache.ibatis.annotations.Param; -import org.springframework.web.bind.annotation.RequestParam; import java.util.List; @@ -21,6 +19,8 @@ public interface ChannelService { int deleteChannel(int id); + int updateRoutine(int id ,String reportRoutineUrl); + List getAreaList(); List