|
|
|
@@ -65,35 +65,22 @@ public class WxMsgCallbackServiceImpl implements WxMsgCallbackService { |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void saveOrUpdate(String tenantId, String item, String sign) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
WxMsgConfig wxMsgConfig = new WxMsgConfig(); |
|
|
|
wxMsgConfig.setTenantId(tenantId); |
|
|
|
List<WxMsgConfig> list = wxMsgConfigMapper.findList(wxMsgConfig); |
|
|
|
List<WxMsgCallback> wxMsgCallbacks = JSONArray.parseArray(item, WxMsgCallback.class); |
|
|
|
wxMsgConfig = list.get(0); |
|
|
|
|
|
|
|
TreeMap<String, String> message = new TreeMap<>(); |
|
|
|
message.put("item","Array"); |
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
Set<Map.Entry<String, String>> entries = message.entrySet(); |
|
|
|
for (Map.Entry<String, String> entry : entries) { |
|
|
|
sb.append(entry.getKey()).append("=").append(entry.getValue()); |
|
|
|
} |
|
|
|
sb.append("&secret=").append(wxMsgConfig.getSecret()); |
|
|
|
String sign_check = HMACSHA256.sha256_HMAC(sb.toString(), wxMsgConfig.getSecret()); |
|
|
|
if(sign_check.equalsIgnoreCase(sign)){ |
|
|
|
logger.info("短信SIGN校验成功"); |
|
|
|
public void saveOrUpdate(String tenantId, Map<String, String> param) { |
|
|
|
|
|
|
|
if(checksign(tenantId,param)){ |
|
|
|
logger.info("短信发送回调SIGN校验成功"); |
|
|
|
WxMsgConfig wxMsgConfig = new WxMsgConfig(); |
|
|
|
wxMsgConfig.setTenantId(tenantId); |
|
|
|
List<WxMsgConfig> list = wxMsgConfigMapper.findList(wxMsgConfig); |
|
|
|
List<WxMsgCallback> wxMsgCallbacks = JSONArray.parseArray(param.get("item"), WxMsgCallback.class); |
|
|
|
wxMsgConfig = list.get(0); |
|
|
|
wxMsgConfig.setRemains(wxMsgConfig.getRemains() - wxMsgCallbacks.size()); |
|
|
|
wxMsgConfigMapper.updateByPrimaryKeySelective(wxMsgConfig); |
|
|
|
final IdWorker idWorker = IdWorker.get(); |
|
|
|
for (WxMsgCallback wxMsgCallback : wxMsgCallbacks) { |
|
|
|
WxMsgCallback callback=wxMsgCallbackMapper.queryCallbackByBatchNoAndPhone(wxMsgCallback); |
|
|
|
if(callback!=null){//有更新,无插入 |
|
|
|
callback.setSign(sign); |
|
|
|
callback.setSign(param.get("sign")); |
|
|
|
callback.setTenantId(tenantId); |
|
|
|
callback.setStatus(wxMsgCallback.getStatus()); |
|
|
|
callback.setStatusMsg(wxMsgCallback.getStatusMsg()); |
|
|
|
@@ -113,59 +100,69 @@ public class WxMsgCallbackServiceImpl implements WxMsgCallbackService { |
|
|
|
} |
|
|
|
} |
|
|
|
}else{ |
|
|
|
logger.info("短信SIGN校验失败"); |
|
|
|
logger.info("短信发送回调SIGN校验失败"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void receivemodel(String tenantId, Map<String, String> param) { |
|
|
|
|
|
|
|
WxMsgModel wxMsgModel = new WxMsgModel(); |
|
|
|
wxMsgModel.setModelId(Integer.valueOf(param.get("id"))); |
|
|
|
wxMsgModel.setTenantId(tenantId); |
|
|
|
wxMsgModel = wxMsgModelMapper.findList(wxMsgModel).get(0); |
|
|
|
wxMsgModel.setStatus(param.get("status").equals("1")?Integer.valueOf(param.get("status")):0); |
|
|
|
wxMsgModelMapper.updateByPrimaryKeySelective(wxMsgModel); |
|
|
|
|
|
|
|
if(checksign(tenantId,param)){ |
|
|
|
logger.info("短信营销模板回调SIGN校验成功"); |
|
|
|
WxMsgModel wxMsgModel = new WxMsgModel(); |
|
|
|
wxMsgModel.setModelId(Integer.valueOf(param.get("id"))); |
|
|
|
wxMsgModel.setTenantId(tenantId); |
|
|
|
wxMsgModel = wxMsgModelMapper.findList(wxMsgModel).get(0); |
|
|
|
wxMsgModel.setStatus(param.get("status").equals("1")?Integer.valueOf(param.get("status")):0); |
|
|
|
wxMsgModelMapper.updateByPrimaryKeySelective(wxMsgModel); |
|
|
|
}else{ |
|
|
|
logger.info("短信营销模板回调SIGN校验失败"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void receiveverifymodel(String tenantId, Map<String, String> param) { |
|
|
|
|
|
|
|
WxMsgValidationcodeModel wxMsgModel = new WxMsgValidationcodeModel(); |
|
|
|
wxMsgModel.setModelId(Integer.valueOf(param.get("id"))); |
|
|
|
wxMsgModel.setTenantId(tenantId); |
|
|
|
wxMsgModel = wxMsgValidationcodeModelMapper.findList(wxMsgModel).get(0); |
|
|
|
wxMsgModel.setStatus(param.get("status").equals("1")?Integer.valueOf(param.get("status")):0); |
|
|
|
wxMsgValidationcodeModelMapper.updateByPrimaryKeySelective(wxMsgModel); |
|
|
|
if(checksign(tenantId,param)) { |
|
|
|
logger.info("短信验证码回调SIGN校验成功"); |
|
|
|
WxMsgValidationcodeModel wxMsgModel = new WxMsgValidationcodeModel(); |
|
|
|
wxMsgModel.setModelId(Integer.valueOf(param.get("id"))); |
|
|
|
wxMsgModel.setTenantId(tenantId); |
|
|
|
wxMsgModel = wxMsgValidationcodeModelMapper.findList(wxMsgModel).get(0); |
|
|
|
wxMsgModel.setStatus(param.get("status").equals("1")?Integer.valueOf(param.get("status")):0); |
|
|
|
wxMsgValidationcodeModelMapper.updateByPrimaryKeySelective(wxMsgModel); |
|
|
|
}else{ |
|
|
|
logger.info("短信验证码回调SIGN校验失败"); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
public boolean checksign(String tenantId,Map<String, String> param){ |
|
|
|
|
|
|
|
WxMsgConfig wxMsgConfig = new WxMsgConfig(); |
|
|
|
wxMsgConfig.setTenantId(tenantId); |
|
|
|
List<WxMsgConfig> list = wxMsgConfigMapper.findList(wxMsgConfig); |
|
|
|
wxMsgConfig = list.get(0); |
|
|
|
|
|
|
|
TreeMap<String, String> message = new TreeMap<>(); |
|
|
|
message.putAll(param); |
|
|
|
message.remove("sign"); |
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
Set<Map.Entry<String, String>> entries = message.entrySet(); |
|
|
|
for (Map.Entry<String, String> entry : entries) { |
|
|
|
sb.append(entry.getKey()).append("=").append(entry.getValue()); |
|
|
|
} |
|
|
|
sb.append("&secret=").append(wxMsgConfig.getSecret()); |
|
|
|
String sign_check = HMACSHA256.sha256_HMAC(sb.toString(), wxMsgConfig.getSecret()); |
|
|
|
|
|
|
|
// public static void main(String ...args){ |
|
|
|
// TreeMap<String, String> message = new TreeMap<>(); |
|
|
|
// String data="{\"ret\":\"1\",\"msg\":\"success\",\"data\":{\"data\":[{\"id\":\"50\",\"sign\":\"\\u8fc8\\u5927\\u4e8b\",\"msg\":\"\\u540c\\u5fd7\\u4eec\\uff0c\\u4eca\\u5929\\u6d4b\\u8bd5\\u90e8\\u95e8\\u6210\\u7acb\\u4e86\",\"begintime\":\"1532014609\",\"status\":\"1\"}],\"total\":\"8\"},\"sign\":\"D2D5F4FC4640B5492754031F04264A982F9C9CD8EF54AED7EA3D699FD9E31170\"}"; |
|
|
|
// JSONObject jsonObject = JSONObject.parseObject(data); |
|
|
|
// |
|
|
|
// message.put("data","Array"); |
|
|
|
// message.put("msg","success"); |
|
|
|
// message.put("ret","1"); |
|
|
|
// |
|
|
|
// StringBuilder sb = new StringBuilder(); |
|
|
|
// Set<Map.Entry<String, String>> entries = message.entrySet(); |
|
|
|
// for (Map.Entry<String, String> entry : entries) { |
|
|
|
// sb.append(entry.getKey()).append("=").append(entry.getValue()); |
|
|
|
// } |
|
|
|
// sb.append("&secret=").append("7ea1d237eab458a8bec36aa8dd4892bb"); |
|
|
|
// String sign_check = HMACSHA256.sha256_HMAC(sb.toString(), "7ea1d237eab458a8bec36aa8dd4892bb"); |
|
|
|
// System.out.println(); |
|
|
|
// } |
|
|
|
return sign_check.equalsIgnoreCase(param.get("sign")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |