|
|
|
@ -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.config.CommonSysConst; |
|
|
|
|
import com.hai.model.HighMerchantStoreModel; |
|
|
|
|
import com.hai.model.ResponseData; |
|
|
|
|
import com.hai.service.CommonService; |
|
|
|
|
import com.hai.service.HighMerchantStoreService; |
|
|
|
|
import com.v1.config.SysConst; |
|
|
|
|
import com.v1.config.WeChatQrcodeUtils; |
|
|
|
|
import io.swagger.annotations.Api; |
|
|
|
@ -29,9 +31,11 @@ import org.springframework.web.bind.annotation.ResponseBody; |
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
import javax.servlet.http.HttpServletResponse; |
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
|
|
import java.util.Map; |
|
|
|
|
import java.util.Objects; |
|
|
|
|
import java.util.SortedMap; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -48,12 +52,39 @@ public class WxMsgController { |
|
|
|
|
@Autowired |
|
|
|
|
private WeChatQrcodeUtils weChatQrcodeUtils; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Resource |
|
|
|
|
private HighMerchantStoreService merchantStoreService; |
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.GET) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "验证servlet") |
|
|
|
|
public String verifyWxToken(HttpServletRequest request) { |
|
|
|
|
public String verifyWxToken( |
|
|
|
|
@RequestParam(name = "signature", required = false) String signature, |
|
|
|
|
@RequestParam(name = "timestamp", required = false) String timestamp, |
|
|
|
|
@RequestParam(name = "nonce", required = false) String nonce, |
|
|
|
|
@RequestParam(name = "echostr", required = false) String echostr |
|
|
|
|
) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
|
|
String signatureStr = WxUtils.getSHA1("RgAWdnR5oEOLBdyEjfr4" , timestamp , nonce); |
|
|
|
|
log.info("signatureStr!!!!!" + signatureStr); |
|
|
|
|
log.info("signature!!!!!" + signature); |
|
|
|
|
if (signature.equals(signatureStr)) { |
|
|
|
|
log.info("验证通过!!!!!"); |
|
|
|
|
return echostr; |
|
|
|
|
} |
|
|
|
|
log.info("验证失败!!!!!"); |
|
|
|
|
return null; |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
@RequestMapping(value = "/verifyWxToken", method = RequestMethod.POST) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "验证servlet") |
|
|
|
|
public void verifyWxToken(HttpServletRequest request , HttpServletResponse response) { |
|
|
|
|
|
|
|
|
|
try { |
|
|
|
|
log.info("进入公众号!!!!!!!"); |
|
|
|
@ -63,19 +94,96 @@ 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; |
|
|
|
|
// 二维码参数
|
|
|
|
|
String eventKey = map.get("EventKey"); |
|
|
|
|
String linkContent; |
|
|
|
|
String content = null; |
|
|
|
|
if (eventKey != null && eventKey.length() != 0) { |
|
|
|
|
JSONObject object = weChatQrcodeUtils.paramPars(eventKey); |
|
|
|
|
// type = 1 推广扫码 type = 2
|
|
|
|
|
if (Objects.equals(object.getString("qrscene_type"), "1") || Objects.equals(object.getString("type"), "1")) { |
|
|
|
|
linkContent = "<a href='" + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5?accountId=0000010&key=&code=" + object.getString("code") + "'>点击查看更多优惠</a>\n\n"; |
|
|
|
|
} else { |
|
|
|
|
// 商户门店
|
|
|
|
|
HighMerchantStoreModel store = merchantStoreService.getMerchantStoreByKey(object.getString("code")); |
|
|
|
|
linkContent = "<a href='"+CommonSysConst.getSysConfig().getHsgDomainName()+"/hsgH5?accountId=000000&gasKey=" + object.getString("code") + "&staffCode='>欢迎来到" + store.getStoreName()+"</a>" + "[哇][哇][哇]\n\n<a href='"+CommonSysConst.getSysConfig().getHsgDomainName()+"/hsgH5?accountId=000000&gasKey=" + object.getString("code") + "&staffCode='>点击这里一键加油</a>\n\n"; |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
linkContent = "<a href='" + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5'>点击查看更多优惠</a>\n\n"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
log.info("二维码参数:" + eventKey); |
|
|
|
|
// 普通消息
|
|
|
|
|
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); |
|
|
|
|
// todo 业务处理
|
|
|
|
|
content = |
|
|
|
|
"终于等到你,还好我没放弃[玫瑰][玫瑰][玫瑰]\n\n" + |
|
|
|
|
"您好,感谢关注嗨森逛商城!\n\n" + |
|
|
|
|
linkContent + |
|
|
|
|
"在线等你来撩~[哇][哇][哇]\n\n" + |
|
|
|
|
"特意为您奉上" + |
|
|
|
|
"<a href='" + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5'>5张优惠券</a>" + |
|
|
|
|
",放在您的"+ |
|
|
|
|
"<a href='" + CommonSysConst.getSysConfig().getHsgDomainName() + "/hsgH5'>优惠券</a>"+ |
|
|
|
|
"里面,记得及时使用哦[爱心][爱心][爱心]\n\n" + |
|
|
|
|
"【如遇任何问题请致电客服:400-678-0738】" |
|
|
|
|
; |
|
|
|
|
// todo 业务处理
|
|
|
|
|
} |
|
|
|
|
// 用户扫码进入公众号
|
|
|
|
|
else if ("SCAN".equals(event)) { |
|
|
|
|
// todo 业务处理
|
|
|
|
|
content = |
|
|
|
|
"油价很贵,诗和远方也很贵[可怜]\n\n" + |
|
|
|
|
"“一键加油”有”油“惠[红包][红包][红包]\n\n" + |
|
|
|
|
linkContent + |
|
|
|
|
"多重好礼为您助力\n\n" + |
|
|
|
|
"加油的时候少点心疼,踩油门的时候多点豪横![得意][得意][得意]\n\n" + |
|
|
|
|
"【如遇任何问题请致电客服:400-678-0738】" |
|
|
|
|
; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else if ("unsubscribe".equals(event)) { |
|
|
|
|
// todo 取消关注 业务处理
|
|
|
|
|
} |
|
|
|
|
map.put("content" , content); |
|
|
|
|
String mapToXml = weChatQrcodeUtils.handleEventSubscribe(map); |
|
|
|
|
response.setCharacterEncoding("UTF-8"); |
|
|
|
|
response.getWriter().print(mapToXml); |
|
|
|
|
} |
|
|
|
|
} catch (Exception e) { |
|
|
|
|
return null; |
|
|
|
|
// return null;
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@RequestMapping(value = "/getWxToken", method = RequestMethod.POST) |
|
|
|
|
@ResponseBody |
|
|
|
|
@ApiOperation(value = "获取微信token") |
|
|
|
@ -110,9 +218,15 @@ 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 = "type", required = false) String type, |
|
|
|
|
@RequestParam(name = "code", required = false) String code) { |
|
|
|
|
try { |
|
|
|
|
return ResponseMsgUtil.success(weChatQrcodeUtils.qrCodeCreateLastTicket(sceneId)); |
|
|
|
|
|
|
|
|
|
String sceneId = "type=" + type + "&code=" + code; |
|
|
|
|
|
|
|
|
|
String ticket = weChatQrcodeUtils.qrCodeCreateLastTicket(sceneId).getTicket(); |
|
|
|
|
|
|
|
|
|
return ResponseMsgUtil.success(weChatQrcodeUtils.qrCodePictureUrl(ticket)); |
|
|
|
|
} catch (WxErrorException e) { |
|
|
|
|
return ResponseMsgUtil.exception(e); |
|
|
|
|
} |
|
|
|
|