Commit 5edb3a02 authored by shiyu's avatar shiyu

公众号

parent 76c5cb18
package com.wwdz.ch.wx.api; package com.wwdz.ch.wx.api;
import com.alibaba.fastjson.JSONObject;
import com.wwdz.ch.wx.util.StringUtil;
import com.xxdxxs.utils.JsonUtils;
import com.xxdxxs.utils.StringUtils;
import com.xxdxxs.utils.XmlUtils; import com.xxdxxs.utils.XmlUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
...@@ -17,6 +19,7 @@ import java.io.InputStream; ...@@ -17,6 +19,7 @@ import java.io.InputStream;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID;
@RestController @RestController
@RequestMapping("/officialAccountCallback") @RequestMapping("/officialAccountCallback")
...@@ -75,10 +78,34 @@ public class OfficialAccountController { ...@@ -75,10 +78,34 @@ public class OfficialAccountController {
} }
} }
} }
return ""; return "success";
} }
@RequestMapping(value ="/getSubscribeNotice")
public Object getNotice(@RequestParam(required = false, name = "signature") String signature,
@RequestParam(required = false, name = "timestamp") String timestamp,
@RequestParam(required = false, name = "nonce") String nonce,
@RequestParam(required = false, name = "echostr") String echostr,
@RequestBody(required = false) String xml) {
try {
List<Map<String, String>> list = XmlUtils.fromXml(xml, "xml");
Map<String, String> contentMap = list.get(0);
String event = contentMap.get("Event");
if (SUBSCRIBE_EVENT.equals(event) || UNSUBSCRIBE_EVENT.equals(event)) {
String userOpenId = contentMap.get("FromUserName");
String createTime = contentMap.get("CreateTime");
Date date = new Date(createTime);
logger.info("openId:{}, event :{}, time:{}", userOpenId, event, date);
}
} catch (Exception e) {
logger.error("视频号回调推送error : {}", e);
}
return "success";
}
@RequestMapping(value ="/getToken") @RequestMapping(value ="/getToken")
public String getToken(){ public String getToken(){
String token = null; String token = null;
...@@ -89,4 +116,8 @@ public class OfficialAccountController { ...@@ -89,4 +116,8 @@ public class OfficialAccountController {
} }
return token; return token;
} }
public static void main(String[] args) {
System.out.println(StringUtil.generateRandomString(32));
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment