|
|
|
@ -9,8 +9,10 @@ import com.hai.common.pay.util.XmlUtil; |
|
|
|
|
import com.hai.common.utils.HttpsUtils; |
|
|
|
|
import com.hai.common.utils.ResponseMsgUtil; |
|
|
|
|
import com.hai.common.utils.WxUtils; |
|
|
|
|
import com.hai.model.HighMerchantStoreModel; |
|
|
|
|
import com.hai.model.ResponseData; |
|
|
|
|
import com.hai.service.CommonService; |
|
|
|
|
import com.hai.model.TextMessage; |
|
|
|
|
import com.hai.service.HighMerchantStoreService; |
|
|
|
|
import com.v1.config.SysConst; |
|
|
|
|
import com.v1.config.WeChatQrcodeUtils; |
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
@ -26,10 +28,18 @@ import org.springframework.web.bind.annotation.RequestMapping; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
|
|
import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
|
import org.w3c.dom.Document; |
|
|
|
|
import org.w3c.dom.Element; |
|
|
|
|
import org.xml.sax.InputSource; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
import javax.xml.parsers.DocumentBuilder; |
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory; |
|
|
|
|
|
|
|
|
|
import java.io.BufferedOutputStream; |
|
|
|
|
import java.io.StringReader; |
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.SortedMap; |
|
|
|
@ -48,12 +58,14 @@ public class WxMsgController { |
|
|
|
|
@Autowired |
|
|
|
|
private WeChatQrcodeUtils weChatQrcodeUtils; |
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighMerchantStoreService merchantStoreService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.GET) |
|
|
|
|
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.POST) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "验证servlet") |
|
|
|
|
public String verifyWxToken(HttpServletRequest request) { |
|
|
|
|
public void verifyWxToken(HttpServletRequest request , HttpServletResponse response) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
log.info("进入公众号!!!!!!!"); |
|
|
|
@ -63,19 +75,69 @@ public class WxMsgController { |
|
|
|
|
String notifyXml; |
|
|
|
|
notifyXml = IOUtil.inputStreamToString(request.getInputStream(), "UTF-8"); |
|
|
|
|
|
|
|
|
|
log.info("微信支付系统发送的数据:" + notifyXml); |
|
|
|
|
log.info("微信系统发送的数据:" + notifyXml); |
|
|
|
|
SortedMap<String, String> map = XmlUtil.parseXmlToTreeMap(notifyXml, "UTF-8"); |
|
|
|
|
|
|
|
|
|
// openId
|
|
|
|
|
String userOpenId = map.get("FromUserName"); |
|
|
|
|
// 微信账号
|
|
|
|
|
String userName = map.get("ToUserName"); |
|
|
|
|
// 事件
|
|
|
|
|
String event = map.get("Event"); |
|
|
|
|
// 区分消息类型
|
|
|
|
|
String msgType = map.get("MsgType"); |
|
|
|
|
log.info("微信支付系统发送的数据:" + msgType); |
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
|
// 普通消息
|
|
|
|
|
if ("text".equals(msgType)) { |
|
|
|
|
// todo 处理文本消息
|
|
|
|
|
} else if ("image".equals(msgType)) { |
|
|
|
|
// todo 处理图片消息
|
|
|
|
|
} else if ("voice".equals(msgType)) { |
|
|
|
|
// todo 处理语音消息
|
|
|
|
|
} else if ("video".equals(msgType)) { |
|
|
|
|
// todo 处理视频消息
|
|
|
|
|
} |
|
|
|
|
// 事件推送消息
|
|
|
|
|
else if ("event".equals(msgType)) { |
|
|
|
|
// 用户关注公众号
|
|
|
|
|
if ("subscribe".equals(event)) { |
|
|
|
|
log.info("进入扫码关注流程:" + event); |
|
|
|
|
// 商户门店
|
|
|
|
|
HighMerchantStoreModel store = merchantStoreService.getMerchantStoreByKey(map.get("EventKey")); |
|
|
|
|
// todo 业务处理
|
|
|
|
|
String content = "欢迎来到" + store.getStoreName() + "<a href='https://hsgcs.dctpay.com/hsgH5?accountId=000000&gasKey=" + map.get("EventKey") + "&staffCode='>点击这里一键加油</a>"; |
|
|
|
|
|
|
|
|
|
map.put("content" , content); |
|
|
|
|
String mapToXml = weChatQrcodeUtils.handleEventSubscribe(map); |
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
response.getWriter().print(mapToXml); |
|
|
|
|
// todo 业务处理
|
|
|
|
|
} |
|
|
|
|
// 用户扫码进入公众号
|
|
|
|
|
else if ("SCAN".equals(event)) { |
|
|
|
|
// 商户门店
|
|
|
|
|
HighMerchantStoreModel store = merchantStoreService.getMerchantStoreByKey(map.get("EventKey")); |
|
|
|
|
// todo 业务处理
|
|
|
|
|
String content = "欢迎来到" + store.getStoreName() + "<a href='https://hsgcs.dctpay.com/hsgH5?accountId=000000&gasKey=" + map.get("EventKey") + "&staffCode='>点击这里一键加油</a>"; |
|
|
|
|
|
|
|
|
|
map.put("content" , content); |
|
|
|
|
String mapToXml = weChatQrcodeUtils.handleEventSubscribe(map); |
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
response.getWriter().print(mapToXml); |
|
|
|
|
|
|
|
|
|
}else if ("unsubscribe".equals(event)) { |
|
|
|
|
// todo 取消关注 业务处理
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return null; |
|
|
|
|
// return null;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getWxToken", method = RequestMethod.POST) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "获取微信token") |
|
|
|
@ -110,7 +172,7 @@ public class WxMsgController { |
|
|
|
|
@RequestMapping(value = "/createQrcode", method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "创建生成二维码") |
|
|
|
|
public ResponseData createQrcode(@RequestParam(name = "sceneId", required = false) Integer sceneId) { |
|
|
|
|
public ResponseData createQrcode(@RequestParam(name = "sceneId", required = false) String sceneId) { |
|
|
|
|
try { |
|
|
|
|
return ResponseMsgUtil.success(weChatQrcodeUtils.qrCodeCreateLastTicket(sceneId)); |
|
|
|
|
} catch (WxErrorException e) { |
|
|
|
|