diff --git a/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java b/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java index d7e162e..c7d6c99 100644 --- a/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java +++ b/src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java @@ -61,6 +61,9 @@ public class ChannelController { //private String domain="https://mytest.myjxt.com:51314"; private String domain="https://proxy.shunzhi.net:51314"; + private static String appId = ""; + private static String secret = "" ; + @RequestMapping(value = "getByTemplate",method = RequestMethod.GET) @ApiOperation(value = "获取统一模板下 渠道商") public BaseDto> getByTemplate(int templateId){ @@ -496,6 +499,15 @@ public class ChannelController { String js=Get("https://api.weixin.qq.com/cgi-bin/ticket/getticket","type=jsapi&access_token="+token.getAccess_token()); JSONObject jsonObject= JSONObject.parseObject(js); log_channel.info("获取ticket返回数据----"+jsonObject.toJSONString()); + if(jsonObject.getString("errorcode").equals("40001")){ + //token 过期 重新获取 + token=getAccessToken("wx6078ff3f67524996","8a0465b8ad0f000f568f48853e2818c8"); + accessToken=new AccessToken(); + accessToken.setAccessToken(token.getAccess_token()); + channelService.insertAccessToken(accessToken); + js=Get("https://api.weixin.qq.com/cgi-bin/ticket/getticket","type=jsapi&access_token="+token.getAccess_token()); + jsonObject= JSONObject.parseObject(js); + } wxSign1.setJsapi_ticket(jsonObject.getString("ticket")); String rawstring = "jsapi_ticket=" + wxSign1.getJsapi_ticket() + "&noncestr=" + wxSign1.getNoncestr() + "×tamp=" + wxSign1.getTimestamp() + "&url=" + url + ""; wxSign1.setSignature(SHA1(rawstring)); diff --git a/src/main/java/com/sincere/wechatbusiness/controller/TestController.java b/src/main/java/com/sincere/wechatbusiness/controller/TestController.java deleted file mode 100644 index 640e18b..0000000 --- a/src/main/java/com/sincere/wechatbusiness/controller/TestController.java +++ /dev/null @@ -1,107 +0,0 @@ -//package com.sincere.wechatbusiness.controller; -// -//import com.sincere.wechatbusiness.dto.BaseDto; -//import com.sincere.wechatbusiness.mapper.ChannelMapper; -//import com.sincere.wechatbusiness.model.Banner; -//import com.sincere.wechatbusiness.model.BannerNext; -//import com.sincere.wechatbusiness.model.ChannelProduct; -//import com.sincere.wechatbusiness.service.BannerService; -//import com.sincere.wechatbusiness.service.ChannelProductService; -//import com.sincere.wechatbusiness.service.ChannelService; -//import org.apache.commons.lang3.StringUtils; -//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.util.List; -// -//@RestController -//public class TestController { -// -// @Autowired -// ChannelService channelService ; -// -// @Autowired -// ChannelProductService channelProductService ; -// -// @Autowired -// BannerService bannerService ; -// -// @Autowired -// ChannelMapper channelMapper ; -// -// -// public static void main(String[] args){ -// try { -// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); -// BufferedReader bf = new BufferedReader(fr); -// String str; -// // 按行读取字符串 -// while ((str = bf.readLine()) != null) { -// String[] message = str.split("="); -// System.out.println(message[0]+"="+ message[1] +"="+ java.net.URLEncoder.encode(message[2], "UTF-8")); -// } -// bf.close(); -// fr.close(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } -// -// @RequestMapping(value = "copy",method = RequestMethod.GET) -// public BaseDto copyChannel(){ -// int sourceId = 1025 ; -// ChannelProduct channelProduct = channelProductService.getList(sourceId).get(0); -// List banners = bannerService.getList(sourceId); -// List bannerNexts = bannerService.getBannerNextList(sourceId); -// -// try { -// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); -// BufferedReader bf = new BufferedReader(fr); -// String str; -// // 按行读取字符串 -// while ((str = bf.readLine()) != null) { -// int channelId = 0; -// try{ -// channelId = channelMapper.getByName(str.trim() + "团购").getId(); -// }catch (Exception e){ -// System.out.println(str); -// e.printStackTrace(); -// } -// int channelProductId = 0 ; -// List products = channelProductService.getList(channelId); -// for(ChannelProduct product : products){ -// channelProductId = product.getId(); -// product.setTitle(channelProduct.getTitle()); -// product.setCaption(channelProduct.getCaption()); -// product.setChannelPrice(channelProduct.getChannelPrice()); -// channelProductService.update(product); -// } -// -// bannerService.deleteChannelBanner(channelId); -// bannerService.deleteChannelBannerNext(channelId); -// for(Banner banner : banners){ -// banner.setChannelId(channelId); -// if(StringUtils.isNotBlank(banner.getLinkUrl())){ -// banner.setLinkUrl("http://market.myjxt.com/wap/index.html#/CommodityDetail?id="+channelProductId+"&productId=1"); -// } -// bannerService.copy(banner); -// } -// for(BannerNext bannerNext : bannerNexts){ -// bannerNext.setChannelId(channelId); -// bannerService.copyBannerNext(bannerNext); -// } -// } -// bf.close(); -// fr.close(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// -// return new BaseDto(); -// } -//} diff --git a/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java b/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java index 328dc7f..768b243 100644 --- a/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java +++ b/src/main/java/com/sincere/wechatbusiness/controller/TokenController.java @@ -1,7 +1,9 @@ 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.ChannelService; import io.swagger.annotations.ApiOperation; @@ -10,6 +12,8 @@ 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; @@ -24,11 +28,9 @@ public class TokenController { @Autowired ChannelService channelService ; - @ApiOperation(value = "清空token") - @RequestMapping(value = "deleteToken",method = RequestMethod.GET) - public void deleteToken(){ - channelService.deleteToken(); - } + @Autowired + ChannelMapper channelMapper ; + @ApiOperation(value = "获取分享token") @RequestMapping(value = "getToken",method = RequestMethod.GET) @@ -60,10 +62,10 @@ public class TokenController { return accessToken.getAccessToken() ; } - public Token getAccessToken(String appID, String appScret) { + public Token getAccessToken(String appID, String appSecret) { Token token = new Token(); String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret=" - + appScret; + + appSecret; try { URL getUrl=new URL(url); HttpURLConnection http=(HttpURLConnection)getUrl.openConnection(); @@ -94,4 +96,24 @@ 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(); + } + } } -- libgit2 0.21.0