Commit 4ff1ce043d7cebddedb07fec043dfe86a698162d
1 parent
cb8c5b2f
Exists in
master
1
Showing
3 changed files
with
41 additions
and
114 deletions
Show diff stats
src/main/java/com/sincere/wechatbusiness/controller/ChannelController.java
@@ -61,6 +61,9 @@ public class ChannelController { | @@ -61,6 +61,9 @@ public class ChannelController { | ||
61 | //private String domain="https://mytest.myjxt.com:51314"; | 61 | //private String domain="https://mytest.myjxt.com:51314"; |
62 | private String domain="https://proxy.shunzhi.net:51314"; | 62 | private String domain="https://proxy.shunzhi.net:51314"; |
63 | 63 | ||
64 | + private static String appId = ""; | ||
65 | + private static String secret = "" ; | ||
66 | + | ||
64 | @RequestMapping(value = "getByTemplate",method = RequestMethod.GET) | 67 | @RequestMapping(value = "getByTemplate",method = RequestMethod.GET) |
65 | @ApiOperation(value = "获取统一模板下 渠道商") | 68 | @ApiOperation(value = "获取统一模板下 渠道商") |
66 | public BaseDto<List<Channel>> getByTemplate(int templateId){ | 69 | public BaseDto<List<Channel>> getByTemplate(int templateId){ |
@@ -496,6 +499,15 @@ public class ChannelController { | @@ -496,6 +499,15 @@ public class ChannelController { | ||
496 | String js=Get("https://api.weixin.qq.com/cgi-bin/ticket/getticket","type=jsapi&access_token="+token.getAccess_token()); | 499 | String js=Get("https://api.weixin.qq.com/cgi-bin/ticket/getticket","type=jsapi&access_token="+token.getAccess_token()); |
497 | JSONObject jsonObject= JSONObject.parseObject(js); | 500 | JSONObject jsonObject= JSONObject.parseObject(js); |
498 | log_channel.info("获取ticket返回数据----"+jsonObject.toJSONString()); | 501 | log_channel.info("获取ticket返回数据----"+jsonObject.toJSONString()); |
502 | + if(jsonObject.getString("errorcode").equals("40001")){ | ||
503 | + //token 过期 重新获取 | ||
504 | + token=getAccessToken("wx6078ff3f67524996","8a0465b8ad0f000f568f48853e2818c8"); | ||
505 | + accessToken=new AccessToken(); | ||
506 | + accessToken.setAccessToken(token.getAccess_token()); | ||
507 | + channelService.insertAccessToken(accessToken); | ||
508 | + js=Get("https://api.weixin.qq.com/cgi-bin/ticket/getticket","type=jsapi&access_token="+token.getAccess_token()); | ||
509 | + jsonObject= JSONObject.parseObject(js); | ||
510 | + } | ||
499 | wxSign1.setJsapi_ticket(jsonObject.getString("ticket")); | 511 | wxSign1.setJsapi_ticket(jsonObject.getString("ticket")); |
500 | String rawstring = "jsapi_ticket=" + wxSign1.getJsapi_ticket() + "&noncestr=" + wxSign1.getNoncestr() + "×tamp=" + wxSign1.getTimestamp() + "&url=" + url + ""; | 512 | String rawstring = "jsapi_ticket=" + wxSign1.getJsapi_ticket() + "&noncestr=" + wxSign1.getNoncestr() + "×tamp=" + wxSign1.getTimestamp() + "&url=" + url + ""; |
501 | wxSign1.setSignature(SHA1(rawstring)); | 513 | wxSign1.setSignature(SHA1(rawstring)); |
src/main/java/com/sincere/wechatbusiness/controller/TestController.java
@@ -1,107 +0,0 @@ | @@ -1,107 +0,0 @@ | ||
1 | -//package com.sincere.wechatbusiness.controller; | ||
2 | -// | ||
3 | -//import com.sincere.wechatbusiness.dto.BaseDto; | ||
4 | -//import com.sincere.wechatbusiness.mapper.ChannelMapper; | ||
5 | -//import com.sincere.wechatbusiness.model.Banner; | ||
6 | -//import com.sincere.wechatbusiness.model.BannerNext; | ||
7 | -//import com.sincere.wechatbusiness.model.ChannelProduct; | ||
8 | -//import com.sincere.wechatbusiness.service.BannerService; | ||
9 | -//import com.sincere.wechatbusiness.service.ChannelProductService; | ||
10 | -//import com.sincere.wechatbusiness.service.ChannelService; | ||
11 | -//import org.apache.commons.lang3.StringUtils; | ||
12 | -//import org.springframework.beans.factory.annotation.Autowired; | ||
13 | -//import org.springframework.web.bind.annotation.RequestMapping; | ||
14 | -//import org.springframework.web.bind.annotation.RequestMethod; | ||
15 | -//import org.springframework.web.bind.annotation.RestController; | ||
16 | -// | ||
17 | -//import java.io.BufferedReader; | ||
18 | -//import java.io.FileReader; | ||
19 | -//import java.io.IOException; | ||
20 | -//import java.util.List; | ||
21 | -// | ||
22 | -//@RestController | ||
23 | -//public class TestController { | ||
24 | -// | ||
25 | -// @Autowired | ||
26 | -// ChannelService channelService ; | ||
27 | -// | ||
28 | -// @Autowired | ||
29 | -// ChannelProductService channelProductService ; | ||
30 | -// | ||
31 | -// @Autowired | ||
32 | -// BannerService bannerService ; | ||
33 | -// | ||
34 | -// @Autowired | ||
35 | -// ChannelMapper channelMapper ; | ||
36 | -// | ||
37 | -// | ||
38 | -// public static void main(String[] args){ | ||
39 | -// try { | ||
40 | -// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); | ||
41 | -// BufferedReader bf = new BufferedReader(fr); | ||
42 | -// String str; | ||
43 | -// // 按行读取字符串 | ||
44 | -// while ((str = bf.readLine()) != null) { | ||
45 | -// String[] message = str.split("="); | ||
46 | -// System.out.println(message[0]+"="+ message[1] +"="+ java.net.URLEncoder.encode(message[2], "UTF-8")); | ||
47 | -// } | ||
48 | -// bf.close(); | ||
49 | -// fr.close(); | ||
50 | -// } catch (IOException e) { | ||
51 | -// e.printStackTrace(); | ||
52 | -// } | ||
53 | -// } | ||
54 | -// | ||
55 | -// @RequestMapping(value = "copy",method = RequestMethod.GET) | ||
56 | -// public BaseDto copyChannel(){ | ||
57 | -// int sourceId = 1025 ; | ||
58 | -// ChannelProduct channelProduct = channelProductService.getList(sourceId).get(0); | ||
59 | -// List<Banner> banners = bannerService.getList(sourceId); | ||
60 | -// List<BannerNext> bannerNexts = bannerService.getBannerNextList(sourceId); | ||
61 | -// | ||
62 | -// try { | ||
63 | -// FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); | ||
64 | -// BufferedReader bf = new BufferedReader(fr); | ||
65 | -// String str; | ||
66 | -// // 按行读取字符串 | ||
67 | -// while ((str = bf.readLine()) != null) { | ||
68 | -// int channelId = 0; | ||
69 | -// try{ | ||
70 | -// channelId = channelMapper.getByName(str.trim() + "团购").getId(); | ||
71 | -// }catch (Exception e){ | ||
72 | -// System.out.println(str); | ||
73 | -// e.printStackTrace(); | ||
74 | -// } | ||
75 | -// int channelProductId = 0 ; | ||
76 | -// List<ChannelProduct> products = channelProductService.getList(channelId); | ||
77 | -// for(ChannelProduct product : products){ | ||
78 | -// channelProductId = product.getId(); | ||
79 | -// product.setTitle(channelProduct.getTitle()); | ||
80 | -// product.setCaption(channelProduct.getCaption()); | ||
81 | -// product.setChannelPrice(channelProduct.getChannelPrice()); | ||
82 | -// channelProductService.update(product); | ||
83 | -// } | ||
84 | -// | ||
85 | -// bannerService.deleteChannelBanner(channelId); | ||
86 | -// bannerService.deleteChannelBannerNext(channelId); | ||
87 | -// for(Banner banner : banners){ | ||
88 | -// banner.setChannelId(channelId); | ||
89 | -// if(StringUtils.isNotBlank(banner.getLinkUrl())){ | ||
90 | -// banner.setLinkUrl("http://market.myjxt.com/wap/index.html#/CommodityDetail?id="+channelProductId+"&productId=1"); | ||
91 | -// } | ||
92 | -// bannerService.copy(banner); | ||
93 | -// } | ||
94 | -// for(BannerNext bannerNext : bannerNexts){ | ||
95 | -// bannerNext.setChannelId(channelId); | ||
96 | -// bannerService.copyBannerNext(bannerNext); | ||
97 | -// } | ||
98 | -// } | ||
99 | -// bf.close(); | ||
100 | -// fr.close(); | ||
101 | -// } catch (IOException e) { | ||
102 | -// e.printStackTrace(); | ||
103 | -// } | ||
104 | -// | ||
105 | -// return new BaseDto(); | ||
106 | -// } | ||
107 | -//} |
src/main/java/com/sincere/wechatbusiness/controller/TokenController.java
1 | package com.sincere.wechatbusiness.controller; | 1 | package com.sincere.wechatbusiness.controller; |
2 | 2 | ||
3 | import com.alibaba.fastjson.JSONObject; | 3 | import com.alibaba.fastjson.JSONObject; |
4 | +import com.sincere.wechatbusiness.mapper.ChannelMapper; | ||
4 | import com.sincere.wechatbusiness.model.AccessToken; | 5 | import com.sincere.wechatbusiness.model.AccessToken; |
6 | +import com.sincere.wechatbusiness.model.Channel; | ||
5 | import com.sincere.wechatbusiness.model.Token; | 7 | import com.sincere.wechatbusiness.model.Token; |
6 | import com.sincere.wechatbusiness.service.ChannelService; | 8 | import com.sincere.wechatbusiness.service.ChannelService; |
7 | import io.swagger.annotations.ApiOperation; | 9 | import io.swagger.annotations.ApiOperation; |
@@ -10,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping; | @@ -10,6 +12,8 @@ import org.springframework.web.bind.annotation.RequestMapping; | ||
10 | import org.springframework.web.bind.annotation.RequestMethod; | 12 | import org.springframework.web.bind.annotation.RequestMethod; |
11 | import org.springframework.web.bind.annotation.RestController; | 13 | import org.springframework.web.bind.annotation.RestController; |
12 | 14 | ||
15 | +import java.io.BufferedReader; | ||
16 | +import java.io.FileReader; | ||
13 | import java.io.IOException; | 17 | import java.io.IOException; |
14 | import java.io.InputStream; | 18 | import java.io.InputStream; |
15 | import java.net.HttpURLConnection; | 19 | import java.net.HttpURLConnection; |
@@ -24,11 +28,9 @@ public class TokenController { | @@ -24,11 +28,9 @@ public class TokenController { | ||
24 | @Autowired | 28 | @Autowired |
25 | ChannelService channelService ; | 29 | ChannelService channelService ; |
26 | 30 | ||
27 | - @ApiOperation(value = "清空token") | ||
28 | - @RequestMapping(value = "deleteToken",method = RequestMethod.GET) | ||
29 | - public void deleteToken(){ | ||
30 | - channelService.deleteToken(); | ||
31 | - } | 31 | + @Autowired |
32 | + ChannelMapper channelMapper ; | ||
33 | + | ||
32 | 34 | ||
33 | @ApiOperation(value = "获取分享token") | 35 | @ApiOperation(value = "获取分享token") |
34 | @RequestMapping(value = "getToken",method = RequestMethod.GET) | 36 | @RequestMapping(value = "getToken",method = RequestMethod.GET) |
@@ -60,10 +62,10 @@ public class TokenController { | @@ -60,10 +62,10 @@ public class TokenController { | ||
60 | return accessToken.getAccessToken() ; | 62 | return accessToken.getAccessToken() ; |
61 | } | 63 | } |
62 | 64 | ||
63 | - public Token getAccessToken(String appID, String appScret) { | 65 | + public Token getAccessToken(String appID, String appSecret) { |
64 | Token token = new Token(); | 66 | Token token = new Token(); |
65 | String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret=" | 67 | String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appID + "&secret=" |
66 | - + appScret; | 68 | + + appSecret; |
67 | try { | 69 | try { |
68 | URL getUrl=new URL(url); | 70 | URL getUrl=new URL(url); |
69 | HttpURLConnection http=(HttpURLConnection)getUrl.openConnection(); | 71 | HttpURLConnection http=(HttpURLConnection)getUrl.openConnection(); |
@@ -94,4 +96,24 @@ public class TokenController { | @@ -94,4 +96,24 @@ public class TokenController { | ||
94 | return token; | 96 | return token; |
95 | } | 97 | } |
96 | 98 | ||
99 | + @RequestMapping(value = "test",method = RequestMethod.GET) | ||
100 | + public void test(){ | ||
101 | + try { | ||
102 | + FileReader fr = new FileReader("C:\\Users\\chen\\Desktop\\name.txt"); | ||
103 | + BufferedReader bf = new BufferedReader(fr); | ||
104 | + String str; | ||
105 | + // 按行读取字符串 | ||
106 | + while ((str = bf.readLine()) != null) { | ||
107 | + Channel channel = channelMapper.getByName(str+"团购"); | ||
108 | + int pageView = channelService.getPageViewCount(channel.getId(),0,3); | ||
109 | + int register = channelService.getRegisterCount(channel.getId(),0,3); | ||
110 | + int order = channelService.getOrderCount(channel.getId(),0,3); | ||
111 | + System.out.println(str+"---浏览量:" + pageView+";---注册量:"+register+";---订单量:"+order); | ||
112 | + } | ||
113 | + bf.close(); | ||
114 | + fr.close(); | ||
115 | + } catch (IOException e) { | ||
116 | + e.printStackTrace(); | ||
117 | + } | ||
118 | + } | ||
97 | } | 119 | } |