Просмотр исходного кода

[系统][修改]:获取pvuv时从数据库拿token

release_toaliyun_real
hupeng 7 лет назад
Родитель
Сommit
03fad68962
1 измененных файлов: 11 добавлений и 23 удалений
  1. +11
    -23
      mallinkSchedule/src/main/java/com/iformall/schedule/WxAppVisitSchedule.java

+ 11
- 23
mallinkSchedule/src/main/java/com/iformall/schedule/WxAppVisitSchedule.java Просмотреть файл

@@ -45,8 +45,8 @@ public class WxAppVisitSchedule {




//@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次
@Scheduled(cron = "0 0 2,3,4 * * ? ") //2,3,4点做一次
public void start() {
@Scheduled(cron = "0 0 2,3,4 * * ? ") //2,3,4点做一次
public void daliyVisitRetrive() {
try { try {


WxAppinfo appInfo = new WxAppinfo(); WxAppinfo appInfo = new WxAppinfo();
@@ -61,8 +61,8 @@ public class WxAppVisitSchedule {
for(int i = 0; i < 7; i++) { //查找最近7天有没有漏掉的数据 for(int i = 0; i < 7; i++) { //查找最近7天有没有漏掉的数据
c.add(Calendar.DAY_OF_YEAR, -1); c.add(Calendar.DAY_OF_YEAR, -1);
date = new SimpleDateFormat("yyyyMMdd").format(c.getTime()); date = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
if (!checkData(date ,w.getAppId(), w.getTenantId()))
getData(date,w.getAppId(),w.getSecret(),w.getTenantId());
if (!checkData(date,w))
getData(date,w);
} }
} }
}catch(Exception e) { }catch(Exception e) {
@@ -70,10 +70,10 @@ public class WxAppVisitSchedule {
} }
} }


private boolean checkData(String date,String appId, String tenantId) {
private boolean checkData(String date,WxAppinfo appInfo) {
WxUserVisit wxUserVisit = new WxUserVisit(); WxUserVisit wxUserVisit = new WxUserVisit();
wxUserVisit.setAppId(appId);
wxUserVisit.setTenantId(tenantId);
wxUserVisit.setAppId(appInfo.getAppId());
wxUserVisit.setTenantId(appInfo.getTenantId());
wxUserVisit.setRefDate(date); wxUserVisit.setRefDate(date);
PageInfo<WxUserVisit> page = wxUserVisitService.listAsPage(wxUserVisit, 1, 10000); PageInfo<WxUserVisit> page = wxUserVisitService.listAsPage(wxUserVisit, 1, 10000);
if (page.getList().size() > 0) if (page.getList().size() > 0)
@@ -81,8 +81,8 @@ public class WxAppVisitSchedule {
return false; return false;
} }
private void getData(String date,String appId,String key,String talentId) throws Exception {
String accessToken = getAccessToken(appId, key);
private void getData(String date,WxAppinfo appInfo) throws Exception {
String accessToken = appInfo.getAccessToken();
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
Map<String, String> map = new HashMap<String, String>(); Map<String, String> map = new HashMap<String, String>();
@@ -106,7 +106,7 @@ public class WxAppVisitSchedule {
logger.info(JSON.toJSONString(itemMap)); logger.info(JSON.toJSONString(itemMap));
WxUserVisit v = new WxUserVisit(); WxUserVisit v = new WxUserVisit();
// TODO hardcode appId // TODO hardcode appId
v.setAppId(appId);
v.setAppId(appInfo.getAppId());
String time = itemMap.get("ref_date")+""; String time = itemMap.get("ref_date")+"";
Date dayDate = new SimpleDateFormat("yyyyMMdd").parse(time); Date dayDate = new SimpleDateFormat("yyyyMMdd").parse(time);
v.setDayDate(dayDate); v.setDayDate(dayDate);
@@ -118,20 +118,8 @@ public class WxAppVisitSchedule {
v.setStayTimeSession(itemMap.get("stay_time_session")+""); v.setStayTimeSession(itemMap.get("stay_time_session")+"");
v.setVisitDepth(itemMap.get("visit_depth")+""); v.setVisitDepth(itemMap.get("visit_depth")+"");
v.setStayTimeUv(itemMap.get("stay_time_uv")+""); v.setStayTimeUv(itemMap.get("stay_time_uv")+"");
v.setTenantId(talentId);
v.setTenantId(appInfo.getTenantId());
wxUserVisitService.saveOrUpdate(v); wxUserVisitService.saveOrUpdate(v);
} }
} }
private String getAccessToken(String appId,String appSecret) {
String token="https://api.weixin.qq.com/cgi-bin/token?"+
"grant_type=client_credential&appid=APPID&secret=APPSECRET";
String url = token.replace("APPID", appId).
replace("APPSECRET", appSecret);
Map<String,Object> map = restTemplate.getForObject(url,Map.class);
logger.info("获取access_token返回:"+JSON.toJSONString(map));
return (String)map.get("access_token");
}
} }

Загрузка…
Отмена
Сохранить